23
23
24
24
import os
25
25
import random
26
- import socket
26
+ # import socket
27
27
import subprocess
28
28
import pwd
29
29
import tempfile
30
30
import shutil
31
31
import time
32
32
import six
33
33
34
- # Try to use psycopg2 by default. If psycopg2 isn"t available then use
34
+ # Try to use psycopg2 by default. If psycopg2 isn"t available then use
35
35
# pg8000 which is slower but much more portable because uses only
36
36
# pure-Python code
37
37
try :
44
44
45
45
46
46
registered_nodes = []
47
- last_assigned_port = int (random .random () * 16384 ) + 49152 ;
47
+ last_assigned_port = int (random .random () * 16384 ) + 49152
48
48
pg_config_data = {}
49
49
50
50
51
- """
52
- Predefined exceptions
53
- """
54
- class ClusterException (Exception ): pass
55
- class QueryException (Exception ): pass
51
+ class ClusterException (Exception ):
52
+ """
53
+ Predefined exceptions
54
+ """
55
+ pass
56
+
57
+
58
+ class QueryException (Exception ):
59
+ """
60
+ Predefined exceptions
61
+ """
62
+ pass
56
63
57
64
58
- """
59
- Transaction wrapper returned by Node
60
- """
61
65
class NodeConnection (object ):
66
+ """
67
+ Transaction wrapper returned by Node
68
+ """
62
69
def __init__ (self , parent_node , dbname ):
63
70
self .parent_node = parent_node
64
71
@@ -78,21 +85,22 @@ def __exit__(self, type, value, tb):
78
85
self .connection .close ()
79
86
80
87
def begin (self , isolation_level = 0 ):
81
- levels = [ 'read uncommitted' ,
82
- 'read committed' ,
83
- 'repeatable read' ,
84
- 'serializable' ]
88
+ levels = ['read uncommitted' ,
89
+ 'read committed' ,
90
+ 'repeatable read' ,
91
+ 'serializable' ]
85
92
93
+ print (type (isolation_level ))
86
94
# Check if level is int [0..3]
87
- if isinstance (isolation_level , int ) and \
88
- isolation_level in range (0 , 4 ):
95
+ if ( isinstance (isolation_level , int ) and
96
+ isolation_level in range (0 , 4 )) :
89
97
90
98
# Replace index with isolation level type
91
99
isolation_level = levels [isolation_level ]
92
100
93
101
# Or it might be a string
94
- elif isinstance (isolation_level , str ) and \
95
- str .lower (isolation_level ) in levels :
102
+ elif ( isinstance (isolation_level , six . text_type ) and
103
+ isolation_level .lower () in levels ) :
96
104
97
105
# Nothing to do here
98
106
pass
@@ -148,13 +156,13 @@ def error_filename(self):
148
156
149
157
@property
150
158
def connstr (self ):
151
- return "port=%s" % self .port
159
+ return "port=%s" % self .port
152
160
# return "port=%s host=%s" % (self.port, self.host)
153
161
154
162
def get_bin_path (self , filename ):
155
163
""" Returns full path to an executable """
156
164
pg_config = get_config ()
157
- if not "BINDIR" in pg_config :
165
+ if "BINDIR" not in pg_config :
158
166
return filename
159
167
else :
160
168
return "%s/%s" % (pg_config .get ("BINDIR" ), filename )
@@ -403,6 +411,7 @@ def get_username():
403
411
""" Returns current user name """
404
412
return pwd .getpwuid (os .getuid ())[0 ]
405
413
414
+
406
415
def get_config ():
407
416
global pg_config_data
408
417
@@ -422,19 +431,22 @@ def get_config():
422
431
423
432
return pg_config_data
424
433
434
+
425
435
def version_to_num (version ):
426
436
"""Converts PostgreSQL version to number for easier comparison"""
427
437
import re
428
438
429
439
if not version :
430
440
return 0
431
441
parts = version .split ("." )
432
- while len (parts ) < 3 : parts .append ("0" )
442
+ while len (parts ) < 3 :
443
+ parts .append ("0" )
433
444
num = 0
434
445
for part in parts :
435
446
num = num * 100 + int (re .sub ("[^\d]" , "" , part ))
436
447
return num
437
448
449
+
438
450
def get_new_node (name ):
439
451
global registered_nodes
440
452
global last_assigned_port
@@ -462,12 +474,14 @@ def get_new_node(name):
462
474
463
475
return node
464
476
477
+
465
478
def clean_all ():
466
479
global registered_nodes
467
480
for node in registered_nodes :
468
481
node .cleanup ()
469
482
registered_nodes = []
470
483
484
+
471
485
def stop_all ():
472
486
global registered_nodes
473
487
for node in registered_nodes :
0 commit comments