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

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

Issue 6582297721569280: Issue 2275 - Parse notification groups (Closed)
Left Patch Set: Address comments, parse sample Created April 15, 2015, 8:39 a.m.
Right Patch Set: Rebased Created April 15, 2015, 9:26 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/management/bin/generateNotifications.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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 (text_key, name)) 98 (text_key, name))
100 return notification 99 return notification
101 100
102 def load_notifications(): 101 def load_notifications():
103 repo = get_config().get("notifications", "repository") 102 repo = get_config().get("notifications", "repository")
104 subprocess.call(["hg", "-R", repo, "pull", "-q"]) 103 subprocess.call(["hg", "-R", repo, "pull", "-q"])
105 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar", 104 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar",
106 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"] 105 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"]
107 data = subprocess.check_output(command) 106 data = subprocess.check_output(command)
108 107
109 result = {"version": time.strftime("%Y%m%d%H%M", time.gmtime()), "notification s": []} 108 notifications = []
110 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive: 109 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive:
111 for fileinfo in archive: 110 for fileinfo in archive:
112 name = fileinfo.name 111 name = fileinfo.name
113 if name.startswith("./"): 112 if name.startswith("./"):
114 name = name[2:] 113 name = name[2:]
115 114
116 if fileinfo.type == tarfile.REGTYPE: 115 if fileinfo.type == tarfile.REGTYPE:
117 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) 116 data = codecs.getreader("utf8")(archive.extractfile(fileinfo))
118 try: 117 try:
119 notification = _parse_notification(data, name) 118 notification = _parse_notification(data, name)
120 if "inactive" in notification: 119 if "inactive" in notification:
121 continue 120 continue
122 result["notifications"].append(notification) 121 notifications.append(notification)
123 except: 122 except:
124 traceback.print_exc() 123 traceback.print_exc()
125 return result 124 return notifications
LEFTRIGHT

Powered by Google App Engine
This is Rietveld