Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/notifications/parser.py

Issue 29345242: Noissue - Adapt quotes for compliance with our coding style in sitescripts (Closed)
Patch Set: Fixed raw string Created May 30, 2016, 8:47 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/notifications/parser.py
===================================================================
--- a/sitescripts/notifications/parser.py
+++ b/sitescripts/notifications/parser.py
@@ -29,18 +29,18 @@
target = {}
for spec in value.split():
known = False
- for parameter in ("extension", "application", "platform"):
- if spec.startswith(parameter + "="):
- target[parameter] = spec[len(parameter + "="):]
+ for parameter in ('extension', 'application', 'platform'):
+ if spec.startswith(parameter + '='):
+ target[parameter] = spec[len(parameter + '='):]
known = True
- elif spec.startswith(parameter + "Version>="):
- target[parameter + "MinVersion"] = spec[len(parameter + "Version>="):]
+ elif spec.startswith(parameter + 'Version>='):
+ target[parameter + 'MinVersion'] = spec[len(parameter + 'Version>='):]
known = True
- elif spec.startswith(parameter + "Version<="):
- target[parameter + "MaxVersion"] = spec[len(parameter + "Version<="):]
+ elif spec.startswith(parameter + 'Version<='):
+ target[parameter + 'MaxVersion'] = spec[len(parameter + 'Version<='):]
known = True
- elif spec.startswith(parameter + "Version="):
- target[parameter + "MinVersion"] = target[parameter + "MaxVersion"] = spec[len(parameter + "Version="):]
+ elif spec.startswith(parameter + 'Version='):
+ target[parameter + 'MinVersion'] = target[parameter + 'MaxVersion'] = spec[len(parameter + 'Version='):]
known = True
if not known:
raise Exception("Unknown target specifier '%s' in file '%s'" % (spec, name))
@@ -48,85 +48,85 @@
def _parse_notification(data, name):
- notification = {"id": name, "severity": "information", "message": {}, "title": {}}
+ notification = {'id': name, 'severity': 'information', 'message': {}, 'title': {}}
current = notification
for line in data:
- if not re.search(r"\S", line):
+ if not re.search(r'\S', line):
continue
- if re.search(r"^\[.*\]$", line):
- current = {"title": {}, "message": {}}
- notification.setdefault("variants", []).append(current)
+ if re.search(r'^\[.*\]$', line):
+ current = {'title': {}, 'message': {}}
+ notification.setdefault('variants', []).append(current)
continue
- if line.find("=") < 0:
+ if line.find('=') < 0:
raise Exception("Could not process line '%s' in file '%s'" % (line.strip(), name))
- key, value = map(unicode.strip, line.split("=", 1))
+ key, value = map(unicode.strip, line.split('=', 1))
is_variant = current != notification
- if key == "inactive" and not is_variant:
- current["inactive"] = value.lower() not in ("", "0", "no", "false", "off")
- elif key == "severity":
- if value not in ("information", "critical", "normal"):
+ if key == 'inactive' and not is_variant:
+ current['inactive'] = value.lower() not in ('', '0', 'no', 'false', 'off')
+ elif key == 'severity':
+ if value not in ('information', 'critical', 'normal'):
raise Exception("Unknown severity value '%s' in file '%s'" % (value, name))
- current["severity"] = value
- elif key == "links":
- current["links"] = value.split()
- elif key.startswith("title."):
- locale = key[len("title."):]
- current["title"][locale] = value
- elif key.startswith("message."):
- locale = key[len("message."):]
- current["message"][locale] = value
- elif key == "target":
+ current['severity'] = value
+ elif key == 'links':
+ current['links'] = value.split()
+ elif key.startswith('title.'):
+ locale = key[len('title.'):]
+ current['title'][locale] = value
+ elif key.startswith('message.'):
+ locale = key[len('message.'):]
+ current['message'][locale] = value
+ elif key == 'target':
target = _parse_targetspec(value, name)
- if "targets" in notification:
- current["targets"].append(target)
+ if 'targets' in notification:
+ current['targets'].append(target)
else:
- current["targets"] = [target]
- elif key == "sample" and is_variant:
- current["sample"] = float(value)
- elif key in ["start", "end"]:
- current[key] = datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M")
+ current['targets'] = [target]
+ elif key == 'sample' and is_variant:
+ current['sample'] = float(value)
+ elif key in ['start', 'end']:
+ current[key] = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M')
else:
raise Exception("Unknown parameter '%s' in file '%s'" % (key, name))
- for text_key in ("title", "message"):
+ for text_key in ('title', 'message'):
def has_default_locale(variant):
- return "en-US" in variant[text_key]
+ return 'en-US' in variant[text_key]
if not has_default_locale(notification):
- variants = notification.get("variants", [])
+ variants = notification.get('variants', [])
if not all(map(has_default_locale, variants)):
- raise Exception("No %s for en-US (default language) "
+ raise Exception('No %s for en-US (default language) '
"in file '%s'" % (text_key, name))
return notification
def load_notifications():
- repo = get_config().get("notifications", "repository")
- command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar",
- "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"]
+ repo = get_config().get('notifications', 'repository')
+ command = ['hg', '-R', repo, 'archive', '-r', 'default', '-t', 'tar',
+ '-p', '.', '-X', os.path.join(repo, '.hg_archival.txt'), '-']
data = subprocess.check_output(command)
notifications = []
- with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive:
+ with tarfile.open(mode='r:', fileobj=StringIO(data)) as archive:
for fileinfo in archive:
name = fileinfo.name
- if name.startswith("./"):
+ if name.startswith('./'):
name = name[2:]
if fileinfo.type == tarfile.REGTYPE:
- data = codecs.getreader("utf8")(archive.extractfile(fileinfo))
+ data = codecs.getreader('utf8')(archive.extractfile(fileinfo))
try:
notification = _parse_notification(data, name)
- if not "inactive" in notification:
+ if not 'inactive' in notification:
current_time = datetime.datetime.now()
- start = notification.pop("start", current_time)
- end = notification.pop("end", current_time)
+ start = notification.pop('start', current_time)
+ end = notification.pop('end', current_time)
if not start <= current_time <= end:
- notification["inactive"] = True
+ notification['inactive'] = True
notifications.append(notification)
except:
traceback.print_exc()

Powered by Google App Engine
This is Rietveld