1
1
import click
2
- from arcsecond import ArcsecondAPI , Config
2
+ from arcsecond import ArcsecondAPI , ArcsecondConfig , cli as ArcsecondCLI
3
3
from arcsecond .options import State
4
4
5
5
from oort import __version__
6
+ from oort .common .context import Context
6
7
from oort .common .utils import build_endpoint_kwargs
8
+ from oort .uploader .walker import walk
7
9
from .errors import OortCloudError , InvalidUploadOptionsOortCloudError
8
10
from .helpers import display_command_summary
9
11
from .options import basic_options
10
- from .validators import validate_upload_parameters
11
12
12
13
pass_state = click .make_pass_decorator (State , ensure = True )
13
14
@@ -64,35 +65,21 @@ def login(state, username, password):
64
65
This Upload key is not your full API key. When logging in with oort, no fetch
65
66
nor storage of the API key occur (only the Upload one).
66
67
"""
67
- _ , error = ArcsecondAPI (Config (state )).login (username , password , upload_key = True )
68
+ config = ArcsecondConfig (state )
69
+ _ , error = ArcsecondAPI (config ).login (username , password , upload_key = True )
68
70
if error :
69
71
click .echo (error )
70
72
else :
71
- username = ArcsecondAPI .username ( api = state . api_name )
73
+ username = config .username
72
74
click .echo (f' • Successfully logged in as @{ username } (API: { state .api_name } ).' )
73
75
74
76
75
- @main .command ()
76
- @click .argument ('name' , required = True , nargs = 1 )
77
- @click .argument ('address ' , required = False , nargs = 1 )
77
+ @main .command (help = 'Get or set the API server address (fully qualified domain name).' )
78
+ @click .argument ('name' , required = False , nargs = 1 )
79
+ @click .argument ('fqdn ' , required = False , nargs = 1 )
78
80
@pass_state
79
- def api (state , name = None , address = None ):
80
- """
81
- Configure the API server address.
82
-
83
- For instance:
84
-
85
- • "oort api main" to get the main API server address (default).\n
86
- • "oort api dev http://localhost:8000" to configure a dev server.
87
-
88
- You can then use --api <api name> in every command to choose which API
89
- server you want to interact with. Hence, "--api dev" will choose the above
90
- dev server.
91
- """
92
- if address is None :
93
- print (ArcsecondAPI .get_api_name (api_name = name ))
94
- else :
95
- ArcsecondAPI .set_api_name (address , api_name = name )
81
+ def api (state , name = None , fqdn = None ):
82
+ ArcsecondCLI .api (state , name , fqdn )
96
83
97
84
98
85
@main .command (help = "Display the list of (organisation) datasets." )
@@ -109,7 +96,7 @@ def datasets(state, organisation=None):
109
96
click .echo (" • Fetching datasets..." )
110
97
111
98
kwargs = build_endpoint_kwargs (state .api_name , subdomain = organisation )
112
- dataset_list , error = ArcsecondAPI . datasets ( ** kwargs ) .list ()
99
+ dataset_list , error = ArcsecondAPI ( ArcsecondConfig ( state )). datasets .list ()
113
100
if error is not None :
114
101
raise OortCloudError (str (error ))
115
102
@@ -134,7 +121,7 @@ def datasets(state, organisation=None):
134
121
help = "The subdomain, if uploading for an Observatory Portal." )
135
122
@basic_options
136
123
@pass_state
137
- def upload (state , folder , organisation = None , dataset = None ):
124
+ def upload (state , folder , dataset = None , organisation = None ):
138
125
"""
139
126
Upload the content of a folder.
140
127
@@ -152,16 +139,17 @@ def upload(state, folder, organisation=None, dataset=None):
152
139
Oort will then start walking through the folder tree and uploads regular files
153
140
(hidden and empty files will be skipped).
154
141
"""
142
+ config = ArcsecondConfig (state )
143
+ context = Context (config , dataset_uuid_or_name = dataset , subdomain = organisation )
144
+
155
145
try :
156
- values = validate_upload_parameters ( organisation , dataset , state )
146
+ context . validate ( )
157
147
except InvalidUploadOptionsOortCloudError as e :
158
148
click .echo (f"\n • ERROR { str (e )} \n " )
159
149
return
160
150
161
- display_command_summary ([folder , ], Config ( state ), values )
151
+ display_command_summary (context , [folder , ])
162
152
ok = input ('\n ----> OK? (Press Enter) ' )
163
153
164
154
if ok .strip () == '' :
165
- from oort .uploader .walker import walk
166
-
167
- walk (folder , context )
155
+ walk (context , folder )
0 commit comments