| LEFT | RIGHT |
| 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 Loading... |
| 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 |
| LEFT | RIGHT |