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

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

Issue 6308119894294528: Issue 2274 - Move notification parsing into a module (Closed)
Left Patch Set: hg mv generateNotifications.py to parser.py Created April 5, 2015, 4:29 p.m.
Right Patch Set: Don't set the version in parser.load_notifications() Created April 15, 2015, 9:24 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 | « sitescripts/notifications/__init__.py ('k') | no next file » | 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 os 19 import os
20 import re 20 import re
21 import subprocess 21 import subprocess
22 import tarfile 22 import tarfile
23 import time
24 import traceback 23 import traceback
25 from StringIO import StringIO 24 from StringIO import StringIO
26 25
27 from sitescripts.utils import get_config 26 from sitescripts.utils import get_config
28 27
29 def _parse_targetspec(value, name): 28 def _parse_targetspec(value, name):
30 target = {} 29 target = {}
31 for spec in value.split(): 30 for spec in value.split():
32 known = False 31 known = False
33 for parameter in ("extension", "application", "platform"): 32 for parameter in ("extension", "application", "platform"):
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 raise Exception("No message for en-US (default language) in file '%s'" % nam e) 87 raise Exception("No message for en-US (default language) in file '%s'" % nam e)
89 return notification 88 return notification
90 89
91 def load_notifications(): 90 def load_notifications():
92 repo = get_config().get("notifications", "repository") 91 repo = get_config().get("notifications", "repository")
93 subprocess.call(["hg", "-R", repo, "pull", "-q"]) 92 subprocess.call(["hg", "-R", repo, "pull", "-q"])
94 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar", 93 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar",
95 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"] 94 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"]
96 data = subprocess.check_output(command) 95 data = subprocess.check_output(command)
97 96
98 result = {"version": time.strftime("%Y%m%d%H%M", time.gmtime()), "notification s": []} 97 notifications = []
99 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive: 98 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive:
100 for fileinfo in archive: 99 for fileinfo in archive:
101 name = fileinfo.name 100 name = fileinfo.name
102 if name.startswith("./"): 101 if name.startswith("./"):
103 name = name[2:] 102 name = name[2:]
104 103
105 if fileinfo.type == tarfile.REGTYPE: 104 if fileinfo.type == tarfile.REGTYPE:
106 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) 105 data = codecs.getreader("utf8")(archive.extractfile(fileinfo))
107 try: 106 try:
108 notification = _parse_notification(data, name) 107 notification = _parse_notification(data, name)
109 if "inactive" in notification: 108 if "inactive" in notification:
110 continue 109 continue
111 result["notifications"].append(notification) 110 notifications.append(notification)
112 except: 111 except:
113 traceback.print_exc() 112 traceback.print_exc()
114 return result 113 return notifications
LEFTRIGHT

Powered by Google App Engine
This is Rietveld