This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfw-sync.py
43 lines (32 loc) · 1.87 KB
/
gfw-sync.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
import argparse
import layer_decision_tree
from utilities import google_sheet as gs
from utilities import logger
from utilities import settings
def main():
# Parse commandline arguments
parser = argparse.ArgumentParser(description='Get layer name, environment and verbosity for gfw-sync.')
parser.add_argument('--environment', '-e', default='staging', choices=('staging', 'prod'),
help='the environment/config files to use for this run')
parser.add_argument('--layer', '-l', required=True,
help='the data layer to process; must match a value for tech_title in the config')
parser.add_argument('--verbose', '-v', default='debug', choices=('debug', 'info', 'warning', 'error'),
help='set verbosity level to print and write to file')
args = parser.parse_args()
# Instantiate logger; write to {dir}\logs
logging = logger.build_logger(args.verbose)
logging.info("\n{0}\n{1} v{2}\n{0}\n".format('*' * 50, settings.get_settings(args.environment)['tool_info']['name'],
settings.get_settings(args.environment)['tool_info']['version']))
logging.critical('Starting | {0}'.format(args.layer))
# Open the correct sheet of the config table (PROD | DEV) and get the layerdef
# Config table: https://docs.google.com/spreadsheets/d/1pkJCLNe9HWAHqxQh__s-tYQr9wJzGCb6rmRBPj8yRWI/edit#gid=0
layerdef = gs.get_layerdef(args.layer, args.environment)
# Pass the layerdef to the build_layer function
layer = layer_decision_tree.build_layer(layerdef, args.environment)
# Update the layer in the output data sources
layer.update()
# Update the last-updated timestamp in the config table
gs.update_gs_timestamp(args.layer, args.environment)
logging.critical('Finished | {0}'.format(args.layer))
if __name__ == "__main__":
main()