import urlparse
# Must fix up PYTHONPATH before importing from within Skia
-import fix_pythonpath # pylint: disable=W0611
+import rs_fixpypath # pylint: disable=W0611
# Imports from within Skia
from py.utils import gs_utils
import imagediffdb
import imagepairset
import results as results_mod
+import writable_expectations as writable_expectations_mod
+
PATHSPLIT_RE = re.compile('/([^/]+)/(.+)')
KEY__EDITS__MODIFICATIONS = 'modifications'
KEY__EDITS__OLD_RESULTS_HASH = 'oldResultsHash'
KEY__EDITS__OLD_RESULTS_TYPE = 'oldResultsType'
+KEY__LIVE_EDITS__MODIFICATIONS = 'modifications'
+KEY__LIVE_EDITS__SET_A_DESCRIPTIONS = 'setA'
+KEY__LIVE_EDITS__SET_B_DESCRIPTIONS = 'setB'
DEFAULT_ACTUALS_DIR = results_mod.DEFAULT_ACTUALS_DIR
DEFAULT_GM_SUMMARIES_BUCKET = download_actuals.GM_SUMMARIES_BUCKET
download_all_images = (
param_dict.get(LIVE_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower()
not in ['1', 'true'])
- setA_dirs = param_dict[LIVE_PARAM__SET_A_DIR]
- setB_dirs = param_dict[LIVE_PARAM__SET_B_DIR]
+ setA_dir = param_dict[LIVE_PARAM__SET_A_DIR][0]
+ setB_dir = param_dict[LIVE_PARAM__SET_B_DIR][0]
setA_section = self._validate_summary_section(
param_dict.get(LIVE_PARAM__SET_A_SECTION, [None])[0])
setB_section = self._validate_summary_section(
# the left (setA).
if ((setA_section == gm_json.JSONKEY_ACTUALRESULTS) and
(setB_section == gm_json.JSONKEY_EXPECTEDRESULTS)):
- setA_dirs, setB_dirs = setB_dirs, setA_dirs
+ setA_dir, setB_dir = setB_dir, setA_dir
setA_section, setB_section = setB_section, setA_section
# Are we comparing some actuals against expectations stored in the repo?
# If so, we can allow the user to submit new baselines.
is_editable = (
(setA_section == gm_json.JSONKEY_EXPECTEDRESULTS) and
- (setA_dirs[0].startswith(compare_rendered_pictures.REPO_URL_PREFIX)) and
+ (setA_dir.startswith(compare_rendered_pictures.REPO_URL_PREFIX)) and
(setB_section == gm_json.JSONKEY_ACTUALRESULTS))
results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
- setA_dirs=setA_dirs, setB_dirs=setB_dirs,
+ setA_dir=setA_dir, setB_dir=setB_dir,
setA_section=setA_section, setB_section=setB_section,
image_diff_db=_SERVER.image_diff_db,
diff_base_url='/static/generated-images',
normpath = posixpath.normpath(self.path)
dispatchers = {
'/edits': self.do_POST_edits,
+ '/live-edits': self.do_POST_live_edits,
}
try:
dispatcher = dispatchers[normpath]
dispatcher()
- self.send_response(200)
except:
self.send_error(404)
raise
# We can do this in a separate thread; we should return our success message
# to the UI as soon as possible.
thread.start_new_thread(_SERVER.update_results, (True,))
+ self.send_response(200)
+
+ def do_POST_live_edits(self):
+ """ Handle a POST request with modifications to SKP expectations, in this
+ format:
+
+ {
+ KEY__LIVE_EDITS__SET_A_DESCRIPTIONS: {
+ # setA descriptions from the original data
+ },
+ KEY__LIVE_EDITS__SET_B_DESCRIPTIONS: {
+ # setB descriptions from the original data
+ },
+ KEY__LIVE_EDITS__MODIFICATIONS: [
+ # as needed by writable_expectations.modify()
+ ],
+ }
+
+ Raises an Exception if there were any problems.
+ """
+ content_type = self.headers[_HTTP_HEADER_CONTENT_TYPE]
+ if content_type != 'application/json;charset=UTF-8':
+ raise Exception('unsupported %s [%s]' % (
+ _HTTP_HEADER_CONTENT_TYPE, content_type))
+
+ content_length = int(self.headers[_HTTP_HEADER_CONTENT_LENGTH])
+ json_data = self.rfile.read(content_length)
+ data = json.loads(json_data)
+ logging.debug('do_POST_live_edits: received new GM expectations data [%s]' %
+ data)
+ with writable_expectations_mod.WritableExpectations(
+ data[KEY__LIVE_EDITS__SET_A_DESCRIPTIONS]) as writable_expectations:
+ writable_expectations.modify(data[KEY__LIVE_EDITS__MODIFICATIONS])
+ diffs = writable_expectations.get_diffs()
+ # TODO(stephana): Move to a simpler web framework so we don't have to
+ # call these functions. See http://skbug.com/2856 ('rebaseline_server:
+ # Refactor server to use a simple web framework')
+ self.send_response(200)
+ self.send_header('Content-type', 'text/plain')
+ self.end_headers()
+ self.wfile.write(diffs)
def redirect_to(self, url):
""" Redirect the HTTP client to a different url.