Script to list Refine project; apply a JSON operation history; and export a Refine project

This commit is contained in:
Paul Makepeace 2011-05-27 01:20:26 +01:00
commit 31e30df5bd
2 changed files with 13 additions and 7 deletions

View File

@ -291,7 +291,7 @@ class RefineProject:
def wait_until_idle(self, polling_delay=0.5):
while True:
response = self.do('get-processes')
response = self.do_json('get-processes')
if 'processes' in response and len(response['processes']) > 0:
time.sleep(polling_delay)
else:
@ -299,7 +299,7 @@ class RefineProject:
def apply_operations(self, file_path, wait=True):
json = open(file_path).read()
response_json = self.do('apply-operations', {'operations': json})
response_json = self.do_json('apply-operations', {'operations': json})
if response_json['code'] == 'pending' and wait:
self.wait_until_idle()
return 'ok'

View File

@ -45,7 +45,8 @@ PARSER.add_option('-l', '--list', dest='list', action='store_true',
help='List projects')
PARSER.add_option('-E', '--export', dest='export', action='store_true',
help='Export project')
PARSER.add_option('-f', '--apply', dest='apply',
help='Apply a JSON commands file to a project')
def list_projects():
"""Query the Refine server and list projects by ID: name."""
@ -85,6 +86,11 @@ def main():
list_projects()
else:
project = refine.RefineProject(args[0])
if options.apply:
response = project.apply_operations(options.apply)
if response != 'ok':
print >>sys.stderr, 'Failed to apply %s: %s' % (options.apply,
response)
if options.export:
export_project(project, options)