-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcfg_help.py
More file actions
135 lines (106 loc) · 3.85 KB
/
Copy pathcfg_help.py
File metadata and controls
135 lines (106 loc) · 3.85 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""
Configuration Helper Script for Local Development
Quickstart:
python cfg_help.py create
edit $(python cfg_help.py get)
python run.py
1. Create configuration file by copying example in this repo
2. Edit the new configuration file
3. Run Gen3Workflow as you normally would
Support for Multiple Configs:
python cfg_help.py create -n google-config.yaml
python cfg_help.py get -n google-config.yaml
edit $(python cfg_help.py get -n google-config.yaml
python run.py -c google-config.yaml
1. Create another configuration file and specify new name
2. Easily obtain the path of your new configuration
3. Open config file in your editor with a command like
4. Run Gen3Workflow and point it to the right configuration file
Gen3Workflow searches specific folders for configuration files. Check Gen3Workflow's
settings for those paths. The LOCAL_CONFIG_FOLDER var here should be included
in the search paths.
NOTE: If using in production with wsgi.py, Gen3Workflow will still look for
configuration files in the defined search paths, but will not be able
to take in a custom configuration name by default.
It will search for a file matching regex: *config.yaml
You can modify the wsgi.py file to pass a file name / file path
into the call to get_app().
"""
import argparse
import os
from os.path import expanduser
from shutil import copyfile
import sys
from gen3config import config
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
LOCAL_CONFIG_FOLDER = "{}/.gen3/gen3-workflow".format(expanduser("~"))
def main():
"""
Config file management CLI
"""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title="action", dest="action")
create = subparsers.add_parser("create")
create.add_argument(
"-n",
"--name",
default="gen3workflow-config.yaml",
help=(
"configuration file name if you want something "
'other than "gen3workflow-config.yaml"'
),
)
create.add_argument(
"--config_path",
help=(
"Full path to a yaml config file to create. "
"Will override/ignore name if provided."
),
)
edit = subparsers.add_parser("get")
edit.add_argument(
"-n",
"--name",
default="gen3workflow-config.yaml",
help=(
"configuration file name if you used something "
'other than "gen3workflow-config.yaml"'
),
)
args = parser.parse_args()
if args.action == "create":
sys.stdout.write(create_config_file(args.name, args.config_path))
elif args.action == "get":
sys.stdout.write(get_config_file(args.name))
else:
raise ValueError("{} is not a recognized action.".format(args.actions))
def create_config_file(file_name, full_path=None):
"""
Initialize a new config file
"""
config_path = full_path or os.path.join(LOCAL_CONFIG_FOLDER, file_name)
dir_name = os.path.dirname(config_path)
if dir_name and not os.path.exists(dir_name):
os.makedirs(os.path.dirname(config_path))
copyfile(os.path.join(ROOT_DIR, "gen3workflow/config-default.yaml"), config_path)
return config_path
def get_config_file(file_name):
"""
Find the config file in the directories configured to be searched
"""
search_folders = [LOCAL_CONFIG_FOLDER]
try:
config_path = config.get_config_path(
search_folders=search_folders, file_name=file_name
)
except IOError:
raise IOError(
"Config file {file_name} could not be found in the search "
"locations: {search_folders}. Run "
'"cfg_help.py create -n {file_name}" first.'.format(
file_name=file_name, search_folders=search_folders
)
)
return config_path
if __name__ == "__main__":
main()