Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: tools/android/loading/cloud/common/clovis_task.py

Issue 2041193008: tools/android/loading Move task creation to background and add dashboard (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@frontendNumberFix
Patch Set: Review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/android/loading/cloud/frontend/clovis_frontend.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/cloud/common/clovis_task.py
diff --git a/tools/android/loading/cloud/common/clovis_task.py b/tools/android/loading/cloud/common/clovis_task.py
index 739bb9cb6712b070fb3dea7970fd7141a3c2fd39..97c88a53e238a278ea5d28ebc6ec7ea20c503796 100644
--- a/tools/android/loading/cloud/common/clovis_task.py
+++ b/tools/android/loading/cloud/common/clovis_task.py
@@ -30,16 +30,15 @@ class ClovisTask(object):
self._backend_params.update({'tag': str(uuid.uuid1())})
@classmethod
- def FromJsonString(cls, json_dict):
- """Loads a ClovisTask from a JSON string.
+ def FromJsonDict(cls, json_dict):
+ """Loads a ClovisTask from a JSON dictionary.
Returns:
ClovisTask: The task, or None if the string is invalid.
"""
try:
- data = json.loads(json_dict)
- action = data['action']
- action_params = data['action_params']
+ action = json_dict['action']
+ action_params = json_dict['action_params']
# Vaidate the format.
if action == 'trace':
urls = action_params['urls']
@@ -51,7 +50,19 @@ class ClovisTask(object):
else:
# When more actions are supported, check that they are valid here.
return None
- return cls(action, action_params, data.get('backend_params'))
+ return cls(action, action_params, json_dict.get('backend_params'))
+ except Exception:
+ return None
+
+ @classmethod
+ def FromJsonString(cls, json_string):
+ """Loads a ClovisTask from a JSON string.
+
+ Returns:
+ ClovisTask: The task, or None if the string is invalid.
+ """
+ try:
+ return cls.FromJsonDict(json.loads(json_string))
except Exception:
return None
@@ -60,11 +71,14 @@ class ClovisTask(object):
"""Loads a ClovisTask from a base 64 string."""
return ClovisTask.FromJsonString(base64.b64decode(base64_string))
+ def ToJsonDict(self):
+ """Returns the JSON representation of the task as a dictionary."""
+ return {'action': self._action, 'action_params': self._action_params,
+ 'backend_params': self._backend_params}
+
def ToJsonString(self):
- """Returns the JSON representation of the task."""
- task_dict = {'action': self._action, 'action_params': self._action_params,
- 'backend_params': self._backend_params}
- return json.dumps(task_dict)
+ """Returns the JSON representation of the task as a string."""
+ return json.dumps(self.ToJsonDict())
def Action(self):
return self._action
« no previous file with comments | « no previous file | tools/android/loading/cloud/frontend/clovis_frontend.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698