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

@ -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 <http://www.gnu.org/licenses/>
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()