75 lines
1.4 KiB
Python
Executable file
75 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import typing as _typing
|
|
import sys as _sys
|
|
import os as _os
|
|
import argparse as _argparse
|
|
|
|
|
|
def main():
|
|
## consts
|
|
dir_source = "source"
|
|
|
|
## args
|
|
argument_parser = _argparse.ArgumentParser()
|
|
argument_parser.add_argument(
|
|
"-r",
|
|
"--revision",
|
|
type = str,
|
|
dest = "revision",
|
|
default = None,
|
|
help = "use '.' for latest",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-f",
|
|
"--format",
|
|
type = str,
|
|
dest = "format",
|
|
default = "sqlite",
|
|
)
|
|
args = argument_parser.parse_args()
|
|
|
|
## vars
|
|
revisions = sorted(
|
|
list(
|
|
map(
|
|
lambda name: name.split(".sindri.json")[0],
|
|
_os.listdir(_os.path.join(dir_source, "structure"))
|
|
)
|
|
)
|
|
)
|
|
revision = (
|
|
args.revision
|
|
if
|
|
(
|
|
(not (args.revision is None))
|
|
and
|
|
(not (args.revision == ""))
|
|
and
|
|
(not (args.revision == "."))
|
|
)
|
|
else
|
|
revisions[-1]
|
|
)
|
|
|
|
## exec
|
|
if (not (revision in set(revisions))):
|
|
_sys.stderr.write("-- invalid revision: %s\n" % revision)
|
|
_sys.exit(1)
|
|
else:
|
|
_sys.stderr.write("-- data\n")
|
|
_os.system(
|
|
"cat %s/structure/%s.sindri.json | tools/sindri/sindri --format='database:%s'"
|
|
% (
|
|
dir_source,
|
|
revision,
|
|
args.format,
|
|
)
|
|
)
|
|
_sys.stderr.write("-- meta\n")
|
|
_sys.stdout.write("DROP TABLE IF EXISTS _meta;\n")
|
|
_sys.stdout.write("CREATE TABLE _meta(revision VARCHAR(15) NOT NULL);\n")
|
|
_sys.stdout.write("INSERT INTO _meta(revision) VALUES ('%s');\n" % revision)
|
|
|
|
|
|
main()
|