Script to list Refine project; apply a JSON operation history; and export a Refine project
This commit is contained in:
commit
31e30df5bd
|
@ -291,7 +291,7 @@ class RefineProject:
|
||||||
|
|
||||||
def wait_until_idle(self, polling_delay=0.5):
|
def wait_until_idle(self, polling_delay=0.5):
|
||||||
while True:
|
while True:
|
||||||
response = self.do('get-processes')
|
response = self.do_json('get-processes')
|
||||||
if 'processes' in response and len(response['processes']) > 0:
|
if 'processes' in response and len(response['processes']) > 0:
|
||||||
time.sleep(polling_delay)
|
time.sleep(polling_delay)
|
||||||
else:
|
else:
|
||||||
|
@ -299,7 +299,7 @@ class RefineProject:
|
||||||
|
|
||||||
def apply_operations(self, file_path, wait=True):
|
def apply_operations(self, file_path, wait=True):
|
||||||
json = open(file_path).read()
|
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:
|
if response_json['code'] == 'pending' and wait:
|
||||||
self.wait_until_idle()
|
self.wait_until_idle()
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
16
refine.py
16
refine.py
|
@ -23,7 +23,7 @@ refine --export --output=project.xls 1234...
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
@ -45,7 +45,8 @@ PARSER.add_option('-l', '--list', dest='list', action='store_true',
|
||||||
help='List projects')
|
help='List projects')
|
||||||
PARSER.add_option('-E', '--export', dest='export', action='store_true',
|
PARSER.add_option('-E', '--export', dest='export', action='store_true',
|
||||||
help='Export project')
|
help='Export project')
|
||||||
|
PARSER.add_option('-f', '--apply', dest='apply',
|
||||||
|
help='Apply a JSON commands file to a project')
|
||||||
|
|
||||||
def list_projects():
|
def list_projects():
|
||||||
"""Query the Refine server and list projects by ID: name."""
|
"""Query the Refine server and list projects by ID: name."""
|
||||||
|
@ -69,7 +70,7 @@ def export_project(project, options):
|
||||||
output = sys.stdout
|
output = sys.stdout
|
||||||
output.writelines(project.export(export_format=export_format))
|
output.writelines(project.export(export_format=export_format))
|
||||||
output.close()
|
output.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"Main."
|
"Main."
|
||||||
options, args = PARSER.parse_args()
|
options, args = PARSER.parse_args()
|
||||||
|
@ -78,16 +79,21 @@ def main():
|
||||||
refine.REFINE_HOST = options.host
|
refine.REFINE_HOST = options.host
|
||||||
if options.port:
|
if options.port:
|
||||||
refine.REFINE_PORT = options.port
|
refine.REFINE_PORT = options.port
|
||||||
|
|
||||||
if not options.list and len(args) != 1:
|
if not options.list and len(args) != 1:
|
||||||
PARSER.error('expecting --list or project ID/URL')
|
PARSER.error('expecting --list or project ID/URL')
|
||||||
if options.list:
|
if options.list:
|
||||||
list_projects()
|
list_projects()
|
||||||
else:
|
else:
|
||||||
project = refine.RefineProject(args[0])
|
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:
|
if options.export:
|
||||||
export_project(project, options)
|
export_project(project, options)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue