def _insert_build(self, cursor, *args, **kwargs): if self.config.dry_run: print "INSERT BUILD" print args print kwargs else: buildutil.insert_build(cursor, *args, **kwargs)
def main(argv=None): parser = argparse.ArgumentParser( formatter_class=WrappedTextHelpFormatter, description='Replay an ftpscraper log', epilog=EPILOG.strip(), ) parser.add_argument('ftpscraperlog', help='the ftpscraper log to replay') if argv is None: args = parser.parse_args() else: args = parser.parse_args(argv) ftpscraperlog = args.ftpscraperlog if not os.path.exists(ftpscraperlog): print('ftpscraper log "%s" does not exist. Exiting.' % ftpscraperlog) return 1 database_url = get_envvar('DATABASE_URL') connection = psycopg2.connect(database_url) cursor = connection.cursor() with open(ftpscraperlog, 'r') as fp: for line in fp: if ' adding (' not in line or ')' not in line: continue line = line.strip() params = line[line.find('('):line.find(')') + 1] params = eval(params) print('(replay) adding %s' % (params, )) insert_build(cursor, *params, ignore_duplicates=True)
def _insert_build(self, cursor, *args, **kwargs): self.config.logger.debug('adding %s', args) if self.config.dry_run: print('INSERT BUILD') print(args) print(kwargs) else: buildutil.insert_build(cursor, *args, **kwargs)