Have do_json include engine param itself.

This commit is contained in:
Paul Makepeace 2011-04-25 01:28:30 -04:00
parent 5051a0c15f
commit ca2b690a17
1 changed files with 16 additions and 19 deletions

View File

@ -358,13 +358,17 @@ class RefineProject:
"""Issue a command to the server & return a response object.""" """Issue a command to the server & return a response object."""
return self.server.urlopen(command, self.project_id, data) return self.server.urlopen(command, self.project_id, data)
def do_json(self, command, data=None): def do_json(self, command, data=None, include_engine=True):
"""Issue a command to the server, parse & return decoded JSON.""" """Issue a command to the server, parse & return decoded JSON."""
if include_engine:
if data is None:
data = {}
data['engine'] = self.engine.as_json()
return self.server.urlopen_json(command, project_id=self.project_id, data=data) return self.server.urlopen_json(command, project_id=self.project_id, data=data)
def get_models(self): def get_models(self):
"""Fill out column metadata.""" """Fill out column metadata."""
response = self.do_json('get-models') response = self.do_json('get-models', include_engine=False)
column_model = response['columnModel'] column_model = response['columnModel']
columns = column_model['columns'] columns = column_model['columns']
# Pre-extend the list in python # Pre-extend the list in python
@ -395,46 +399,41 @@ class RefineProject:
def export(self, export_format='tsv'): def export(self, export_format='tsv'):
"""Return a fileobject of a project's data.""" """Return a fileobject of a project's data."""
data = { url = ('export-rows/' + urllib.quote(self.project_name) + '.' +
'engine': Engine().as_json(), export_format)
'format': export_format, return self.do_raw(url, {'format': export_format})
}
return self.do_raw(
'export-rows/' + urllib.quote(self.project_name) + '.' + export_format, data)
def export_rows(self, **kwargs): def export_rows(self, **kwargs):
"""Return an iterable of parsed rows of a project's data.""" """Return an iterable of parsed rows of a project's data."""
return csv.reader(self.export(**kwargs), dialect='excel-tab') return csv.reader(self.export(**kwargs), dialect='excel-tab')
def delete(self): def delete(self):
response_json = self.do_json('delete-project') response_json = self.do_json('delete-project', include_engine=False)
return 'code' in response_json and response_json['code'] == 'ok' return 'code' in response_json and response_json['code'] == 'ok'
def compute_facets(self, facets=None): def compute_facets(self, facets=None):
if facets: if facets:
self.engine = Engine(facets) self.engine = Engine(facets)
response = self.do_json('compute-facets', response = self.do_json('compute-facets')
{'engine': self.engine.as_json()})
return FacetsResponse(response) return FacetsResponse(response)
def get_rows(self, facets=None, start=0, limit=10): def get_rows(self, facets=None, start=0, limit=10):
if facets: if facets:
self.engine = Engine(facets) self.engine = Engine(facets)
response = self.do_json('get-rows', { response = self.do_json('get-rows', {
'sorting': "{'criteria': []}", 'engine': self.engine.as_json(), 'sorting': "{'criteria': []}", 'start': start, 'limit': limit})
'start': start, 'limit': limit})
return RowsResponse(response) return RowsResponse(response)
def remove_rows(self, facets=None): def remove_rows(self, facets=None):
if facets: if facets:
self.engine = Engine(facets) self.engine = Engine(facets)
return self.do_json('remove-rows', {'engine': self.engine.as_json()}) return self.do_json('remove-rows')
def text_transform(self, column, expression, on_error='set-to-blank', def text_transform(self, column, expression, on_error='set-to-blank',
repeat=False, repeat_count=10): repeat=False, repeat_count=10):
response = self.do_json('text-transform', { response = self.do_json('text-transform', {
'engine': self.engine.as_json(), 'columnName': column, 'columnName': column, 'expression': expression,
'expression': expression, 'onError': on_error, 'repeat': repeat, 'onError': on_error, 'repeat': repeat,
'repeatCount': repeat_count}) 'repeatCount': repeat_count})
return response return response
@ -446,8 +445,7 @@ class RefineProject:
"""edits is [{'from': ['foo'], 'to': 'bar'}, {...}]""" """edits is [{'from': ['foo'], 'to': 'bar'}, {...}]"""
edits = json.dumps(edits) edits = json.dumps(edits)
response = self.do_json('mass-edit', { response = self.do_json('mass-edit', {
'engine': self.engine.as_json(), 'columnName': column, 'columnName': column, 'expression': expression, 'edits': edits})
'expression': expression, 'edits': edits})
return response return response
clusterer_defaults = { clusterer_defaults = {
@ -475,7 +473,6 @@ class RefineProject:
clusterer['function'] = function clusterer['function'] = function
clusterer['column'] = column clusterer['column'] = column
response = self.do_json('compute-clusters', { response = self.do_json('compute-clusters', {
'engine': self.engine.as_json(),
'clusterer': json.dumps(clusterer)}) 'clusterer': json.dumps(clusterer)})
return [[{'value': x['v'], 'count': x['c']} for x in cluster] return [[{'value': x['v'], 'count': x['c']} for x in cluster]
for cluster in response] for cluster in response]