2323
2424import os
2525import random
26- import socket
26+ # import socket
2727import subprocess
2828import pwd
2929import tempfile
3030import shutil
3131import time
3232import six
3333
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
3535# pg8000 which is slower but much more portable because uses only
3636# pure-Python code
3737try :
4444
4545
4646registered_nodes = []
47- last_assigned_port = int (random .random () * 16384 ) + 49152 ;
47+ last_assigned_port = int (random .random () * 16384 ) + 49152
4848pg_config_data = {}
4949
5050
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
5663
5764
58- """
59- Transaction wrapper returned by Node
60- """
6165class NodeConnection (object ):
66+ """
67+ Transaction wrapper returned by Node
68+ """
6269 def __init__ (self , parent_node , dbname ):
6370 self .parent_node = parent_node
6471
@@ -78,21 +85,22 @@ def __exit__(self, type, value, tb):
7885 self .connection .close ()
7986
8087 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' ]
8592
93+ print (type (isolation_level ))
8694 # 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 )) :
8997
9098 # Replace index with isolation level type
9199 isolation_level = levels [isolation_level ]
92100
93101 # 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 ) :
96104
97105 # Nothing to do here
98106 pass
@@ -148,13 +156,13 @@ def error_filename(self):
148156
149157 @property
150158 def connstr (self ):
151- return "port=%s" % self .port
159+ return "port=%s" % self .port
152160 # return "port=%s host=%s" % (self.port, self.host)
153161
154162 def get_bin_path (self , filename ):
155163 """ Returns full path to an executable """
156164 pg_config = get_config ()
157- if not "BINDIR" in pg_config :
165+ if "BINDIR" not in pg_config :
158166 return filename
159167 else :
160168 return "%s/%s" % (pg_config .get ("BINDIR" ), filename )
@@ -403,6 +411,7 @@ def get_username():
403411 """ Returns current user name """
404412 return pwd .getpwuid (os .getuid ())[0 ]
405413
414+
406415def get_config ():
407416 global pg_config_data
408417
@@ -422,19 +431,22 @@ def get_config():
422431
423432 return pg_config_data
424433
434+
425435def version_to_num (version ):
426436 """Converts PostgreSQL version to number for easier comparison"""
427437 import re
428438
429439 if not version :
430440 return 0
431441 parts = version .split ("." )
432- while len (parts ) < 3 : parts .append ("0" )
442+ while len (parts ) < 3 :
443+ parts .append ("0" )
433444 num = 0
434445 for part in parts :
435446 num = num * 100 + int (re .sub ("[^\d]" , "" , part ))
436447 return num
437448
449+
438450def get_new_node (name ):
439451 global registered_nodes
440452 global last_assigned_port
@@ -462,12 +474,14 @@ def get_new_node(name):
462474
463475 return node
464476
477+
465478def clean_all ():
466479 global registered_nodes
467480 for node in registered_nodes :
468481 node .cleanup ()
469482 registered_nodes = []
470483
484+
471485def stop_all ():
472486 global registered_nodes
473487 for node in registered_nodes :
0 commit comments