diff --git a/google/refine/refine.py b/google/refine/refine.py index ffded26..911fba6 100644 --- a/google/refine/refine.py +++ b/google/refine/refine.py @@ -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' diff --git a/refine.py b/refine.py index 8d83850..f552202 100755 --- a/refine.py +++ b/refine.py @@ -23,7 +23,7 @@ refine --export --output=project.xls 1234... # You should have received a copy of the GNU General Public License # along with this program. If not, see - + import optparse import os @@ -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.""" @@ -69,7 +70,7 @@ def export_project(project, options): output = sys.stdout output.writelines(project.export(export_format=export_format)) output.close() - + def main(): "Main." options, args = PARSER.parse_args() @@ -78,16 +79,21 @@ def main(): refine.REFINE_HOST = options.host if options.port: refine.REFINE_PORT = options.port - + if not options.list and len(args) != 1: PARSER.error('expecting --list or project ID/URL') if options.list: 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) - + if __name__ == '__main__': main()