13
13
# * Creates CWL files from application metadata and Docker registry URL
14
14
# * Register application and pushes CWL files into Dockstore
15
15
16
- STATE_DIRECTORY = ".unity_app_gen"
17
-
18
- import os
19
16
import logging
20
17
from argparse import ArgumentParser
21
18
22
- from unity_app_generator .generator import UnityApplicationGenerator , ApplicationGenerationError
23
-
24
- logger = logging .getLogger ()
25
-
26
- class SubCommandError (Exception ):
27
- pass
28
-
29
- def state_directory_path (args ):
30
-
31
- if args .state_directory is not None :
32
- return os .path .realpath (args .state_directory )
33
-
34
- if hasattr (args , "destination_directory" ) and args .destination_directory is not None :
35
- return os .path .realpath (os .path .join (args .destination_directory , STATE_DIRECTORY ))
36
-
37
- if hasattr (args , "source_repository" ) and os .path .isdir (args .source_repository ):
38
- return os .path .realpath (os .path .join (args .source_repository , STATE_DIRECTORY ))
39
-
40
- return os .path .realpath (os .path .join (os .curdir , STATE_DIRECTORY ))
41
-
42
- def check_state_directory (state_dir ):
43
-
44
- if not os .path .exists (state_dir ):
45
- raise SubCommandError (f"Application state directory { state_dir } does not exist, please run init sub-command first" )
46
-
47
- return state_dir
48
-
49
- def init (args ):
50
- state_dir = state_directory_path (args )
51
-
52
- app_gen = UnityApplicationGenerator (state_dir , args .source_repository , args .destination_directory , args .checkout )
53
-
54
- def build_docker (args ):
55
- state_dir = check_state_directory (state_directory_path (args ))
56
-
57
- app_gen = UnityApplicationGenerator (state_dir ,
58
- repo2docker_config = args .config_file ,
59
- use_namespace = args .image_namespace ,
60
- use_repository = args .image_repository ,
61
- use_tag = args .image_tag )
62
-
63
- app_gen .create_docker_image ()
19
+ from unity_app_generator .generator import ApplicationGenerationError
64
20
65
- def push_docker (args ):
66
- state_dir = check_state_directory (state_directory_path (args ))
21
+ from . import interface
67
22
68
- app_gen = UnityApplicationGenerator (state_dir )
69
-
70
- app_gen .push_to_docker_registry (args .container_registry )
71
-
72
- def push_ecr (args ):
73
- state_dir = check_state_directory (state_directory_path (args ))
74
-
75
- app_gen = UnityApplicationGenerator (state_dir )
76
-
77
- app_gen .push_to_aws_ecr ()
78
-
79
- def notebook_parameters (args ):
80
-
81
- state_dir = check_state_directory (state_directory_path (args ))
82
-
83
- app_gen = UnityApplicationGenerator (state_dir )
84
-
85
- print ()
86
- print (app_gen .notebook_parameters ())
87
-
88
- def build_cwl (args ):
89
- state_dir = check_state_directory (state_directory_path (args ))
90
-
91
- app_gen = UnityApplicationGenerator (state_dir )
92
-
93
- app_gen .create_cwl (cwl_output_path = args .cwl_output_path , docker_url = args .image_url , monolithic = args .monolithic )
94
-
95
- def push_app_registry (args ):
96
- state_dir = check_state_directory (state_directory_path (args ))
97
-
98
- app_gen = UnityApplicationGenerator (state_dir )
99
-
100
- app_gen .push_to_application_registry (args .dockstore_api_url , args .dockstore_token )
23
+ logger = logging .getLogger ()
101
24
102
25
def main ():
103
26
parser = ArgumentParser (description = "Unity Application Package Generator" )
104
27
105
28
parser .add_argument ("--state_directory" ,
106
- help = f"An alternative location to store the application state other than { STATE_DIRECTORY } " )
29
+ help = f"An alternative location to store the application state other than { interface . DEFAULT_STATE_DIRECTORY } " )
107
30
108
31
parser .add_argument ("--verbose" , "-v" , action = "store_true" , default = False ,
109
32
help = f"Enable verbose logging" )
@@ -112,9 +35,9 @@ def main():
112
35
subparsers = parser .add_subparsers (required = True )
113
36
114
37
parser_init = subparsers .add_parser ('init' ,
115
- help = f"Initialize a Git repository for use by this application. Creates a { STATE_DIRECTORY } directory in the destination directory" )
38
+ help = f"Initialize a Git repository for use by this application. Creates a { interface . DEFAULT_STATE_DIRECTORY } directory in the destination directory" )
116
39
117
- parser_init .add_argument ("source_repository" ,
40
+ parser_init .add_argument ("source_repository" ,
118
41
help = "Directory or Git URL of application source files, default is current directory" )
119
42
120
43
parser_init .add_argument ("destination_directory" , nargs = "?" ,
@@ -123,7 +46,7 @@ def main():
123
46
parser_init .add_argument ("-c" , "--checkout" , required = False ,
124
47
help = "Git hash, tag or branch to checkout from the source repository" )
125
48
126
- parser_init .set_defaults (func = init )
49
+ parser_init .set_defaults (func = interface . init )
127
50
128
51
# build_docker
129
52
@@ -142,7 +65,7 @@ def main():
142
65
parser_build_docker .add_argument ("-c" , "--config_file" ,
143
66
help = "JSON or Python Traitlets style config file for repo2docker. Use 'repo2docker --help-all' to see configurable options." )
144
67
145
- parser_build_docker .set_defaults (func = build_docker )
68
+ parser_build_docker .set_defaults (func = interface . build_docker )
146
69
147
70
# push_docker
148
71
@@ -152,21 +75,21 @@ def main():
152
75
parser_push_docker .add_argument ("container_registry" ,
153
76
help = "URL or Dockerhub username of a Docker registry for pushing of the built image" )
154
77
155
- parser_push_docker .set_defaults (func = push_docker )
78
+ parser_push_docker .set_defaults (func = interface . push_docker )
156
79
157
80
# push_ecr
158
81
159
82
parser_push_ecr = subparsers .add_parser ('push_ecr' ,
160
83
help = f"Push a Docker image from the initialized application directory to an AWS Elastic Container Registry (ECR)" )
161
84
162
- parser_push_ecr .set_defaults (func = push_ecr )
85
+ parser_push_ecr .set_defaults (func = interface . push_ecr )
163
86
164
87
# notebook_parameters
165
88
166
89
parser_parameters = subparsers .add_parser ('parameters' ,
167
90
help = f"Display parsed notebook parameters" )
168
91
169
- parser_parameters .set_defaults (func = notebook_parameters )
92
+ parser_parameters .set_defaults (func = interface . notebook_parameters )
170
93
171
94
# build_cwl
172
95
@@ -182,7 +105,7 @@ def main():
182
105
parser_build_cwl .add_argument ("--monolithic" , action = "store_true" ,
183
106
help = "Use the deprecated 'monolithic' approach to generating CWL where stage in and out are bundled inside the application" )
184
107
185
- parser_build_cwl .set_defaults (func = build_cwl )
108
+ parser_build_cwl .set_defaults (func = interface . build_cwl )
186
109
187
110
# push_app_registry
188
111
@@ -195,7 +118,7 @@ def main():
195
118
parser_app_registry .add_argument ("--token" , dest = "dockstore_token" , required = True ,
196
119
help = "Dockstore API token obtained from the My Services / Account page" )
197
120
198
- parser_app_registry .set_defaults (func = push_app_registry )
121
+ parser_app_registry .set_defaults (func = interface . push_app_registry )
199
122
200
123
# Process arguments
201
124
@@ -207,12 +130,9 @@ def main():
207
130
logging .basicConfig (level = logging .INFO )
208
131
209
132
try :
210
- args .func (args )
211
- except ( SubCommandError , ApplicationGenerationError ) as err :
133
+ args .func (** vars ( args ) )
134
+ except ApplicationGenerationError as err :
212
135
parser .error (err )
213
136
214
-
215
- #app_gen.push_to_application_registry(None)
216
-
217
137
if __name__ == '__main__' :
218
138
main ()
0 commit comments