-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
70 lines (51 loc) · 1.82 KB
/
Copy pathcli.py
File metadata and controls
70 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import argparse
import os
from sqlupdater.utils import create_dir, get_config
from sqlupdater.project import Project
from sqlupdater.executers import DummyExecutor, HiveExecutor, HiveClient, \
CacheData
def build_arg_parser():
parser = argparse.ArgumentParser(
description='Import SQL files')
parser.add_argument('-s', '--show',
required=False,
action='store_const',
const=True,
help='Only show data without executing')
parser.add_argument('-e', '--execute',
required=False,
action='store_const',
const=True,
help='Execute all the queries stored')
parser.add_argument('-p', '--project',
required=True,
action='store',
help='Project name')
return parser
def get_args():
parser = build_arg_parser()
return parser.parse_args()
def setup_project(config, project_name):
"""
Updates or setup a new project and return the Repo.
"""
create_dir(config['metadata_path'])
if project_name not in config['projects']:
raise Exception('Project not found %s' % project_name)
project_config = config['projects'][project_name]
project_dir = os.path.join(config['metadata_path'], project_name)
project = Project(project_dir, project_config)
project.init_project()
return project
def main():
args = get_args()
# load config
config = get_config()
project_name = args.project
project = setup_project(config, project_name)
if args.show:
executor = DummyExecutor()
elif args.execute:
executor = HiveExecutor(HiveClient(CacheData(project)))
executor.execute(project)
main()