Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output: Optional[IO[str]] = None
buf: List[str] = []
def flush() -> None:
cast(IO[str], output).writelines(buf)
buf[:] = []
def new_output(filename: str) -> IO[str]:
if output:
output.close()
return open(os.path.join(directory, filename), 'w')
copy_lines: Optional[List[str]] = None
counter = 0
output = new_output('0000_prologue.sql')
matcher = Matcher()
for line in open(sql_filepath):
if copy_lines is None:
if line in ('\n', '--\n'):
buf.append(line)
elif line.startswith('SET search_path = '):
flush()
buf.append(line)
else:
if matcher.match(DATA_COMMENT_RE, line):
counter += 1
output = new_output(
'{counter:04}_{schema}.{table}.sql'.format(
counter=counter,
schema=matcher.group('schema'),
table=matcher.group('table')))
def main() -> None:
opts = parse_arguments()
output_file = os.path.join(opts.output_dir,
'{}.sql'.format(opts.database))
for path in glob(os.path.join(opts.output_dir, '*.sql')):
os.remove(path)
dump_database(opts.database, output_file)
split_sql_file(output_file)
os.remove(output_file)
commit_database(opts.output_dir, opts.remote)