| Left: | ||
| Right: |
| 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, |
| 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 | |
| 20 import dateutil.parser | |
|
Sebastian Noack
2015/06/23 15:41:36
Nit: Third party module imports go below corelib i
Felix Dahlke
2015/06/23 15:51:43
Oh, didn't even realise it's third party... Done.
| |
| 19 import os | 21 import os |
| 20 import re | 22 import re |
| 21 import subprocess | 23 import subprocess |
| 22 import tarfile | 24 import tarfile |
| 23 import traceback | 25 import traceback |
| 24 from StringIO import StringIO | 26 from StringIO import StringIO |
| 25 | 27 |
| 26 from sitescripts.utils import get_config | 28 from sitescripts.utils import get_config |
| 27 | 29 |
| 28 def _parse_targetspec(value, name): | 30 def _parse_targetspec(value, name): |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 locale = key[len("message."):] | 82 locale = key[len("message."):] |
| 81 current["message"][locale] = value | 83 current["message"][locale] = value |
| 82 elif key == "target": | 84 elif key == "target": |
| 83 target = _parse_targetspec(value, name) | 85 target = _parse_targetspec(value, name) |
| 84 if "targets" in notification: | 86 if "targets" in notification: |
| 85 current["targets"].append(target) | 87 current["targets"].append(target) |
| 86 else: | 88 else: |
| 87 current["targets"] = [target] | 89 current["targets"] = [target] |
| 88 elif key == "sample" and is_variant: | 90 elif key == "sample" and is_variant: |
| 89 current["sample"] = float(value) | 91 current["sample"] = float(value) |
| 92 elif key in ["start", "end"]: | |
| 93 current[key] = dateutil.parser.parse(value) | |
|
Sebastian Noack
2015/06/23 15:41:36
I wonder why we don't simply use a more simply for
Felix Dahlke
2015/06/23 15:51:43
Now that I know that dateutil is third party, it'd
Sebastian Noack
2015/06/23 15:58:38
IIRC, the initial idea was to serve one static fil
Wladimir Palant
2015/06/23 17:24:00
I don't think the idea was ever having this checke
Felix Dahlke
2015/06/24 07:53:16
I really don't think we want to parse ISO 8601 our
| |
| 90 else: | 94 else: |
| 91 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name)) | 95 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name)) |
| 92 | 96 |
| 93 for text_key in ("title", "message"): | 97 for text_key in ("title", "message"): |
| 94 def has_default_locale(variant): return "en-US" in variant[text_key] | 98 def has_default_locale(variant): return "en-US" in variant[text_key] |
| 95 if (not has_default_locale(notification) and | 99 if (not has_default_locale(notification) and |
| 96 not all(map(has_default_locale, notification.get("variants", [])))): | 100 not all(map(has_default_locale, notification.get("variants", [])))): |
| 97 raise Exception("No %s for en-US (default language) in file '%s'" % | 101 raise Exception("No %s for en-US (default language) in file '%s'" % |
| 98 (text_key, name)) | 102 (text_key, name)) |
| 99 return notification | 103 return notification |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 111 name = fileinfo.name | 115 name = fileinfo.name |
| 112 if name.startswith("./"): | 116 if name.startswith("./"): |
| 113 name = name[2:] | 117 name = name[2:] |
| 114 | 118 |
| 115 if fileinfo.type == tarfile.REGTYPE: | 119 if fileinfo.type == tarfile.REGTYPE: |
| 116 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) | 120 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) |
| 117 try: | 121 try: |
| 118 notification = _parse_notification(data, name) | 122 notification = _parse_notification(data, name) |
| 119 if "inactive" in notification: | 123 if "inactive" in notification: |
| 120 continue | 124 continue |
| 125 current_time = datetime.datetime.now() | |
| 126 if "start" in notification and current_time < notification["start"]: | |
| 127 continue | |
| 128 if "end" in notification and current_time > notification["end"]: | |
| 129 continue | |
| 121 notifications.append(notification) | 130 notifications.append(notification) |
| 122 except: | 131 except: |
| 123 traceback.print_exc() | 132 traceback.print_exc() |
| 124 return notifications | 133 return notifications |
| OLD | NEW |