1313# * Creates CWL files from application metadata and Docker registry URL
1414# * Register application and pushes CWL files into Dockstore
1515
16- STATE_DIRECTORY = ".unity_app_gen"
17-
18- import os
1916import logging
2017from argparse import ArgumentParser
2118
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
6420
65- def push_docker (args ):
66- state_dir = check_state_directory (state_directory_path (args ))
21+ from . import interface
6722
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 ()
10124
10225def main ():
10326 parser = ArgumentParser (description = "Unity Application Package Generator" )
10427
10528 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 } " )
10730
10831 parser .add_argument ("--verbose" , "-v" , action = "store_true" , default = False ,
10932 help = f"Enable verbose logging" )
@@ -112,9 +35,9 @@ def main():
11235 subparsers = parser .add_subparsers (required = True )
11336
11437 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" )
11639
117- parser_init .add_argument ("source_repository" ,
40+ parser_init .add_argument ("source_repository" ,
11841 help = "Directory or Git URL of application source files, default is current directory" )
11942
12043 parser_init .add_argument ("destination_directory" , nargs = "?" ,
@@ -123,7 +46,7 @@ def main():
12346 parser_init .add_argument ("-c" , "--checkout" , required = False ,
12447 help = "Git hash, tag or branch to checkout from the source repository" )
12548
126- parser_init .set_defaults (func = init )
49+ parser_init .set_defaults (func = interface . init )
12750
12851 # build_docker
12952
@@ -142,7 +65,7 @@ def main():
14265 parser_build_docker .add_argument ("-c" , "--config_file" ,
14366 help = "JSON or Python Traitlets style config file for repo2docker. Use 'repo2docker --help-all' to see configurable options." )
14467
145- parser_build_docker .set_defaults (func = build_docker )
68+ parser_build_docker .set_defaults (func = interface . build_docker )
14669
14770 # push_docker
14871
@@ -152,21 +75,21 @@ def main():
15275 parser_push_docker .add_argument ("container_registry" ,
15376 help = "URL or Dockerhub username of a Docker registry for pushing of the built image" )
15477
155- parser_push_docker .set_defaults (func = push_docker )
78+ parser_push_docker .set_defaults (func = interface . push_docker )
15679
15780 # push_ecr
15881
15982 parser_push_ecr = subparsers .add_parser ('push_ecr' ,
16083 help = f"Push a Docker image from the initialized application directory to an AWS Elastic Container Registry (ECR)" )
16184
162- parser_push_ecr .set_defaults (func = push_ecr )
85+ parser_push_ecr .set_defaults (func = interface . push_ecr )
16386
16487 # notebook_parameters
16588
16689 parser_parameters = subparsers .add_parser ('parameters' ,
16790 help = f"Display parsed notebook parameters" )
16891
169- parser_parameters .set_defaults (func = notebook_parameters )
92+ parser_parameters .set_defaults (func = interface . notebook_parameters )
17093
17194 # build_cwl
17295
@@ -182,7 +105,7 @@ def main():
182105 parser_build_cwl .add_argument ("--monolithic" , action = "store_true" ,
183106 help = "Use the deprecated 'monolithic' approach to generating CWL where stage in and out are bundled inside the application" )
184107
185- parser_build_cwl .set_defaults (func = build_cwl )
108+ parser_build_cwl .set_defaults (func = interface . build_cwl )
186109
187110 # push_app_registry
188111
@@ -195,7 +118,7 @@ def main():
195118 parser_app_registry .add_argument ("--token" , dest = "dockstore_token" , required = True ,
196119 help = "Dockstore API token obtained from the My Services / Account page" )
197120
198- parser_app_registry .set_defaults (func = push_app_registry )
121+ parser_app_registry .set_defaults (func = interface . push_app_registry )
199122
200123 # Process arguments
201124
@@ -207,12 +130,9 @@ def main():
207130 logging .basicConfig (level = logging .INFO )
208131
209132 try :
210- args .func (args )
211- except ( SubCommandError , ApplicationGenerationError ) as err :
133+ args .func (** vars ( args ) )
134+ except ApplicationGenerationError as err :
212135 parser .error (err )
213136
214-
215- #app_gen.push_to_application_registry(None)
216-
217137if __name__ == '__main__' :
218138 main ()
0 commit comments