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

Delta Between Two Patch Sets: sitescripts/notifications/parser.py

Issue 29321041: Issue 2707 - Support start/end notification parameters (Closed)
Left Patch Set: Fix import order Created June 23, 2015, 3:51 p.m.
Right Patch Set: Change date format Created June 24, 2015, 7:52 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | sitescripts/notifications/test/parser.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import codecs 18 import codecs
19 import datetime 19 import datetime
20 import os 20 import os
21 import re 21 import re
22 import subprocess 22 import subprocess
23 import tarfile 23 import tarfile
24 import traceback 24 import traceback
25 from StringIO import StringIO 25 from StringIO import StringIO
26
27 import dateutil.parser
28 26
29 from sitescripts.utils import get_config 27 from sitescripts.utils import get_config
30 28
31 def _parse_targetspec(value, name): 29 def _parse_targetspec(value, name):
32 target = {} 30 target = {}
33 for spec in value.split(): 31 for spec in value.split():
34 known = False 32 known = False
35 for parameter in ("extension", "application", "platform"): 33 for parameter in ("extension", "application", "platform"):
36 if spec.startswith(parameter + "="): 34 if spec.startswith(parameter + "="):
37 target[parameter] = spec[len(parameter + "="):] 35 target[parameter] = spec[len(parameter + "="):]
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 current["message"][locale] = value 82 current["message"][locale] = value
85 elif key == "target": 83 elif key == "target":
86 target = _parse_targetspec(value, name) 84 target = _parse_targetspec(value, name)
87 if "targets" in notification: 85 if "targets" in notification:
88 current["targets"].append(target) 86 current["targets"].append(target)
89 else: 87 else:
90 current["targets"] = [target] 88 current["targets"] = [target]
91 elif key == "sample" and is_variant: 89 elif key == "sample" and is_variant:
92 current["sample"] = float(value) 90 current["sample"] = float(value)
93 elif key in ["start", "end"]: 91 elif key in ["start", "end"]:
94 current[key] = dateutil.parser.parse(value) 92 current[key] = datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M")
95 else: 93 else:
96 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name)) 94 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name))
97 95
98 for text_key in ("title", "message"): 96 for text_key in ("title", "message"):
99 def has_default_locale(variant): return "en-US" in variant[text_key] 97 def has_default_locale(variant): return "en-US" in variant[text_key]
100 if (not has_default_locale(notification) and 98 if (not has_default_locale(notification) and
101 not all(map(has_default_locale, notification.get("variants", [])))): 99 not all(map(has_default_locale, notification.get("variants", [])))):
102 raise Exception("No %s for en-US (default language) in file '%s'" % 100 raise Exception("No %s for en-US (default language) in file '%s'" %
103 (text_key, name)) 101 (text_key, name))
104 return notification 102 return notification
(...skipping 20 matching lines...) Expand all
125 continue 123 continue
126 current_time = datetime.datetime.now() 124 current_time = datetime.datetime.now()
127 if "start" in notification and current_time < notification["start"]: 125 if "start" in notification and current_time < notification["start"]:
128 continue 126 continue
129 if "end" in notification and current_time > notification["end"]: 127 if "end" in notification and current_time > notification["end"]:
130 continue 128 continue
131 notifications.append(notification) 129 notifications.append(notification)
132 except: 130 except:
133 traceback.print_exc() 131 traceback.print_exc()
134 return notifications 132 return notifications
LEFTRIGHT

Powered by Google App Engine
This is Rietveld