Loading cccli/commands/attachment.py 0 → 100644 +40 −0 Original line number Diff line number Diff line #!/usr/bin/env python #coding=utf8 ''' CloudControl script releated commands ''' import os import subprocess from cccli.exception import * from cccli.command import TqlCommand class Command_attachment(TqlCommand): '''Retrieve an attachment''' def __init__(self, cli, argv0): TqlCommand.__init__(self, cli, argv0) self.tql_filter += "&r=job" self.set_usage("%prog <tql> <attachment>") def __call__(self, argv): # Parse argline self.parse_args(argv) # append current login if nothing asked if len(self.args) != 2: raise cmdBadArgument() # ask server pager = os.environ.get('PAGER', '/bin/more') objs = self.rpc.call("attachment", self.args[0], self.args[1]) for out in objs['objects']: if out['status'] == 'success': page = '# %s:\n\n%s\n' % (out['id'], out['output']) p = subprocess.Popen([pager], stdin=subprocess.PIPE) p.communicate(page) else: self.printer.warn('%s: %s' % (out['id'], out['message'])) def remote_functions(self): return set(("attachment",)) Loading
cccli/commands/attachment.py 0 → 100644 +40 −0 Original line number Diff line number Diff line #!/usr/bin/env python #coding=utf8 ''' CloudControl script releated commands ''' import os import subprocess from cccli.exception import * from cccli.command import TqlCommand class Command_attachment(TqlCommand): '''Retrieve an attachment''' def __init__(self, cli, argv0): TqlCommand.__init__(self, cli, argv0) self.tql_filter += "&r=job" self.set_usage("%prog <tql> <attachment>") def __call__(self, argv): # Parse argline self.parse_args(argv) # append current login if nothing asked if len(self.args) != 2: raise cmdBadArgument() # ask server pager = os.environ.get('PAGER', '/bin/more') objs = self.rpc.call("attachment", self.args[0], self.args[1]) for out in objs['objects']: if out['status'] == 'success': page = '# %s:\n\n%s\n' % (out['id'], out['output']) p = subprocess.Popen([pager], stdin=subprocess.PIPE) p.communicate(page) else: self.printer.warn('%s: %s' % (out['id'], out['message'])) def remote_functions(self): return set(("attachment",))