| OLD | NEW |
| 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, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 for text_key in ("title", "message"): | 96 for text_key in ("title", "message"): |
| 97 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] |
| 98 if (not has_default_locale(notification) and | 98 if (not has_default_locale(notification) and |
| 99 not all(map(has_default_locale, notification.get("variants", [])))): | 99 not all(map(has_default_locale, notification.get("variants", [])))): |
| 100 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'" % |
| 101 (text_key, name)) | 101 (text_key, name)) |
| 102 return notification | 102 return notification |
| 103 | 103 |
| 104 def load_notifications(): | 104 def load_notifications(): |
| 105 repo = get_config().get("notifications", "repository") | 105 repo = get_config().get("notifications", "repository") |
| 106 subprocess.call(["hg", "-R", repo, "pull", "-q"]) | |
| 107 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar", | 106 command = ["hg", "-R", repo, "archive", "-r", "default", "-t", "tar", |
| 108 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"] | 107 "-p", ".", "-X", os.path.join(repo, ".hg_archival.txt"), "-"] |
| 109 data = subprocess.check_output(command) | 108 data = subprocess.check_output(command) |
| 110 | 109 |
| 111 notifications = [] | 110 notifications = [] |
| 112 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive: | 111 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive: |
| 113 for fileinfo in archive: | 112 for fileinfo in archive: |
| 114 name = fileinfo.name | 113 name = fileinfo.name |
| 115 if name.startswith("./"): | 114 if name.startswith("./"): |
| 116 name = name[2:] | 115 name = name[2:] |
| 117 | 116 |
| 118 if fileinfo.type == tarfile.REGTYPE: | 117 if fileinfo.type == tarfile.REGTYPE: |
| 119 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) | 118 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) |
| 120 try: | 119 try: |
| 121 notification = _parse_notification(data, name) | 120 notification = _parse_notification(data, name) |
| 122 if "inactive" in notification: | 121 if "inactive" in notification: |
| 123 continue | 122 continue |
| 124 current_time = datetime.datetime.now() | 123 current_time = datetime.datetime.now() |
| 125 start = notification.pop("start", None) | 124 start = notification.pop("start", None) |
| 126 if start is not None and current_time < start: | 125 if start is not None and current_time < start: |
| 127 continue | 126 continue |
| 128 end = notification.pop("end", None) | 127 end = notification.pop("end", None) |
| 129 if end is not None and current_time > end: | 128 if end is not None and current_time > end: |
| 130 continue | 129 continue |
| 131 notifications.append(notification) | 130 notifications.append(notification) |
| 132 except: | 131 except: |
| 133 traceback.print_exc() | 132 traceback.print_exc() |
| 134 return notifications | 133 return notifications |
| OLD | NEW |