another lost part of the frontend refactoring. this is changes to rpc_utils to be more generic and more organized.
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1653 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index e57a183..14fa987 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -9,23 +9,28 @@
from frontend.afe import models
def prepare_for_serialization(objects):
- """\
- Do necessary type conversions to values in data to allow for RPC
- serialization.
- -convert datetimes to strings
"""
- objects = gather_unique_dicts(objects)
+ Prepare Python objects to be returned via RPC.
+ """
+ if (isinstance(objects, list) and len(objects) and
+ isinstance(objects[0], dict) and 'id' in objects[0]):
+ objects = gather_unique_dicts(objects)
return _prepare_data(objects)
def _prepare_data(data):
- 'Recursively process data structures'
+ """
+ Recursively process data structures, performing necessary type
+ conversions to values in data to allow for RPC serialization:
+ -convert datetimes to strings
+ -convert tuples to lists
+ """
if isinstance(data, dict):
new_data = {}
for key, value in data.iteritems():
new_data[key] = _prepare_data(value)
return new_data
- elif isinstance(data, list):
+ elif isinstance(data, list) or isinstance(data, tuple):
return [_prepare_data(item) for item in data]
elif isinstance(data, datetime.datetime):
return str(data)
@@ -33,6 +38,19 @@
return data
+def gather_unique_dicts(dict_iterable):
+ """\
+ Pick out unique objects (by ID) from an iterable of object dicts.
+ """
+ id_set = set()
+ result = []
+ for obj in dict_iterable:
+ if obj['id'] not in id_set:
+ id_set.add(obj['id'])
+ result.append(obj)
+ return result
+
+
def extra_job_filters(not_yet_run=False, running=False, finished=False):
"""\
Generate a SQL WHERE clause for job status filtering, and return it in
@@ -130,19 +148,6 @@
return is_server, is_synchronous, test_objects, label
-def gather_unique_dicts(dict_iterable):
- """\
- Pick out unique objects (by ID) from an iterable of object dicts.
- """
- id_set = set()
- result = []
- for obj in dict_iterable:
- if obj['id'] not in id_set:
- id_set.add(obj['id'])
- result.append(obj)
- return result
-
-
def sorted(in_list):
new_list = list(in_list)
new_list.sort()