Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple options to run client from script #320

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions net/client/README
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ Example use:
'''
python3 client.py -u ../../demo/apod1.jpg -k XXXXXXXX --scale-lower 0.2 --scale-units degwidth --wcs apod1.wcs
'''

Example use as a library:

```
opts = ClientRunnerOptions(
upload="../../demo/apod2.jpg",
apikey="XXXXXXXX",
scale_lower=0.2,
scale_units="degwidth",
newfits="apod2wcs.jpg",
)

run_client(opts)
```
27 changes: 25 additions & 2 deletions net/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ def jobs_by_tag(self, tag, exact):
)
return result

class ClientRunnerOptions(object):
def __init__(self, **entries):
self.server = Client.default_url
self.public = 'y'
self.allow_mod = 'd'
self.allow_commercial = 'd'

self.__dict__.update(entries)

def __getattr__(self, name):
try:
return object.__getattr__(self, name)
except:
return None

def run_client(opt):
args = {}
args['apiurl'] = opt.server
Expand Down Expand Up @@ -398,9 +413,9 @@ def run_client(opt):
jobs = c.myjobs()
print(jobs)

if __name__ == '__main__':
print("Running with args %s"%sys.argv)
def get_args():
import optparse

parser = optparse.OptionParser()
parser.add_option('--server', dest='server', default=Client.default_url,
help='Set server base URL (eg, %default)')
Expand Down Expand Up @@ -467,6 +482,7 @@ def run_client(opt):
const='n',
default='d',
help='Select license to disallow commercial use of submission')

opt,args = parser.parse_args()

if opt.apikey is None:
Expand All @@ -478,4 +494,11 @@ def run_client(opt):
print('You must either specify --apikey or set AN_API_KEY')
sys.exit(-1)

return opt

if __name__ == '__main__':
print("Running with args %s"%sys.argv)

opt = get_args()

run_client(opt)
Loading