Skip to content

Commit

Permalink
Merge pull request #320 from SeverinDenisenko/main
Browse files Browse the repository at this point in the history
Add simple options to run client from script
  • Loading branch information
dstndstn authored Nov 25, 2024
2 parents 987eca9 + f03c12c commit e868ccd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
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)

0 comments on commit e868ccd

Please sign in to comment.