def sanity(self): okflag = True migfiles = [f.split("/")[-1] for f in \ glob.glob(self.mig_dir +"/" + "".join(["[0-9]" for i in \ range(0,self.mig_number_len)])+"_*.py")] if not os.path.exists(self.mig_dir + "/Config.yml"): print "Config.yml missing from script directory; exiting" exit(2) history = self.__mig_files_history() if self.mig_dir != self.conf_dir: testconf = configyml.get_config(self.mig_dir, False) if testconf != self.conf: print "cached " + self.mig_dir + \ "/Config.yml does not match " + \ self.conf_dir + "/Config.yml" okflag = False else: print "cached Config.yml matches " +\ self.conf_dir + "/Config.yml" for m in migfiles: if m not in history: print "< file " + m + " not reflected in migration history" okflag = False for h in history: if h not in migfiles: print "> file " + h + " of migration history missing from script directory" okflag = False if not okflag: print "scripts: " + str(migfiles) print "history: " + str(history) exit(2) else: print "scriptdir matches migration history"
def __init__(self, mig_dir, conf_dir): ## @var conf the configuration self.conf = configyml.get_config(conf_dir, False) api = self.conf['dbapi2'] connect_args = self.conf['connect_args'] try: dbapi2 = __import__(api, globals(), locals(), ['']) except: if api.rfind('.') > 0: dbapi2 = __import__(api[api.rfind('.') + 1:], globals(), locals(), ['']) ## @var mig_dir the directory with the migration files self.mig_dir = mig_dir ## @var mig_dir the directory with the Config.yml file self.conf_dir = conf_dir ## @var mig_number_len migration files have names of the form # <mig_number>_<version_name>.py # where mig_number is mig_number_len digits long self.mig_number_len = 3 # @var mig_prolog the junk that goes at the top of each migration file self.mig_prolog = """#!/usr/bin/python import sys from madpy.madpack.migrations import MadPackMigration class Migration(MadPackMigration): """ ## @var mig_forwards_prolog the junk that goes before each method's forwards script self.mig_forwards_prolog = """\tdef forwards(self):\n\t\tcur = self.dbconn.cursor()\n""" ## @var mig_backwards_prolog the junk that goes before each method's backwards script self.mig_backwards_prolog = """\tdef backwards(self):\n\t\tcur = self.dbconn.cursor()\n""" ## @var dbconn live database connection con_args = {} for arg in connect_args: if arg.find("=") == -1: print sys.exc_info()[0] print "Missing '=' character in the connect_args parameter: " + arg raise # cleanup the string arg = ((arg.replace("'", "")).replace('"', '')).replace(' ', '') equal_sign = arg.find('=') # create a proper dictionary of connection parameters con_args[arg[:equal_sign]] = arg[equal_sign + 1:] self.dbconn = dbapi2.connect(**con_args)
def __init__(self, mig_dir, conf_dir): ## @var conf the configuration self.conf = configyml.get_config(conf_dir, False) api = self.conf['dbapi2'] connect_args = self.conf['connect_args'] try: dbapi2 = __import__( api, globals(), locals(), ['']) except: if api.rfind('.') > 0: dbapi2 = __import__( api[api.rfind('.')+1:], globals(), locals(), ['']) ## @var mig_dir the directory with the migration files self.mig_dir = mig_dir ## @var mig_dir the directory with the Config.yml file self.conf_dir = conf_dir ## @var mig_number_len migration files have names of the form # <mig_number>_<version_name>.py # where mig_number is mig_number_len digits long self.mig_number_len = 3 # @var mig_prolog the junk that goes at the top of each migration file self.mig_prolog = """#!/usr/bin/python import sys from madpy.madpack.migrations import MadPackMigration class Migration(MadPackMigration): """ ## @var mig_forwards_prolog the junk that goes before each method's forwards script self.mig_forwards_prolog = """\tdef forwards(self):\n\t\tcur = self.dbconn.cursor()\n""" ## @var mig_backwards_prolog the junk that goes before each method's backwards script self.mig_backwards_prolog = """\tdef backwards(self):\n\t\tcur = self.dbconn.cursor()\n""" ## @var dbconn live database connection con_args={}; for arg in connect_args: if arg.find("=") == -1: print sys.exc_info()[0] print "Missing '=' character in the connect_args parameter: " + arg raise # cleanup the string arg = ((arg.replace( "'", "")).replace( '"', '')).replace( ' ', '') equal_sign = arg.find('=') # create a proper dictionary of connection parameters con_args[ arg[:equal_sign]] = arg[equal_sign+1:] self.dbconn = dbapi2.connect( **con_args)