def __init__(self, queries, config = None, config_section="mysql"): threading.Thread.__init__(self) self.queries = queries self.config = config self.config_section = config_section if self.config is None: self.config = db.load_config() self.db = _mysql.connect(self.config.get(config_section, "host"), \ self.config.get(config_section, 'user'), \ self.config.get(config_section, 'pass'), \ self.config.get(config_section, 'database'))
def __init__(self, queries, config=None, config_section="mysql"): threading.Thread.__init__(self) self.queries = queries self.config = config self.config_section = config_section if self.config is None: self.config = db.load_config() self.db = _mysql.connect(self.config.get(config_section, "host"), \ self.config.get(config_section, 'user'), \ self.config.get(config_section, 'pass'), \ self.config.get(config_section, 'database'))
def load_data(input_filename, output_filename): if not pexists(output_filename): parent = dirname(abspath(output_filename)) if not isdir(parent): os.makedirs(parent) print('Partial results not found - starting from scratch') shutil.copyfile(input_filename, output_filename) print('Loading input') config = load_config() data = load_input(output_filename, config['address_column_name'], config['county_column_name'], config['country']) print('Loading complete') return data
APP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(os.path.join(APP_PATH, "src")) def general_insert_queries(table, fields, count = 1000): queries = [] for i in range(0, count): values = [] columns = [] for field_name, field_type in fields: values.append("'"+ str(db_schema.field_value(field_type)) + "'") columns.append(field_name) queries.append(("", "INSERT INTO %s ( %s ) VALUES (%s)" %(table, ",".join(columns), ",".join(values)))) return queries if __name__ == "__main__": config = db.load_config() table = config.get("io_test_mysql", "table") database = config.get("io_test_mysql", "database"); consume_count = config.get('io_test_mysql', 'consume') try: db = MySQLdb.connect(host="localhost", user="******", passwd="admin", db=database) except MySQLdb.Error as e: print "Error: %d: %s" %(e.args[0], e.args[1]) sys.exit(1) cursor = db.cursor() cursor.execute("""desc %s""" %(table)) fields = []
AP.add_argument('options', nargs='*', help='Module options, or --help to get help on that module') help = False raw_args = list() for arg in sys.argv[1:]: if arg.lower() in ('--help', '-h'): help = True else: raw_args.append(arg) args = AP.parse_args(raw_args) if not args.module: AP.print_help() exit() import modules import db db.load_config(args.config) if modules.has_module(args.module): module = modules.get_module(args.module) if help: module.START(db, '--help', *args.options) else: module.START(db, *args.options) else: print 'Module named "%s" not found.' % (args.module)