-
Notifications
You must be signed in to change notification settings - Fork 16
/
run_graph_animator.py
74 lines (62 loc) · 2.24 KB
/
run_graph_animator.py
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
71
72
73
74
'''generate an animated GIF of the state of a LookML repo over time
It uses the Grapher tool to ceate one image per commit
Authors:
Carl Anderson ([email protected])
'''
import os
import json
import argparse
import logging
from lkmltools.grapher.graph_animator import GraphAnimator
def parse_arguments():
"""Parse command line arguments
Returns:
argument objects with flags as attributes
"""
parser = argparse.ArgumentParser()
parser.add_argument('--config',
help='Location of the configuration file',
required=True)
parser.add_argument('--path_to_repo',
help='Path to repo',
required=True)
parser.add_argument('--branch',
help='Git repo branch',
required=False)
parser.add_argument('--image_directory',
help='Directory to save images to. Will be created if does not exist',
required=True)
parser.add_argument('--gif_filename',
help='filepath of output GIF',
required=True)
known_args, pipeline_args = parser.parse_known_args()
return known_args, pipeline_args
def main():
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s %(funcName)s: %(message)s', level=logging.INFO)
args, _ = parse_arguments()
# Example input config file
# {
# "infile_globs": [
# "../somerepo/*.lkml"
# ],
#
# "options": {
# "node_size": 400,
# "label_font_size": 10,
# "text_angle": 30,
# "image_width": 12,
# "image_height" : 8
# }
# }
if os.path.exists(args.config):
with open(args.config, 'r') as f:
config = json.load(f)
else:
raise Exception('config file at: {} not found'.format(args.config))
branch = args.branch if args.branch else 'master'
if not os.path.exists(args.image_directory):
os.makedirs(args.image_directory)
animator = GraphAnimator(config)
animator.create_gif(args.path_to_repo, branch, args.image_directory, args.gif_filename)
if __name__ == '__main__':
main()