Left: | ||
Right: |
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 datetime | 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.
| |
21 import os | 20 import os |
22 import re | 21 import re |
23 import subprocess | 22 import subprocess |
24 import tarfile | 23 import tarfile |
25 import traceback | 24 import traceback |
26 from StringIO import StringIO | 25 from StringIO import StringIO |
27 | 26 |
28 from sitescripts.utils import get_config | 27 from sitescripts.utils import get_config |
29 | 28 |
30 def _parse_targetspec(value, name): | 29 def _parse_targetspec(value, name): |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 current["message"][locale] = value | 82 current["message"][locale] = value |
84 elif key == "target": | 83 elif key == "target": |
85 target = _parse_targetspec(value, name) | 84 target = _parse_targetspec(value, name) |
86 if "targets" in notification: | 85 if "targets" in notification: |
87 current["targets"].append(target) | 86 current["targets"].append(target) |
88 else: | 87 else: |
89 current["targets"] = [target] | 88 current["targets"] = [target] |
90 elif key == "sample" and is_variant: | 89 elif key == "sample" and is_variant: |
91 current["sample"] = float(value) | 90 current["sample"] = float(value) |
92 elif key in ["start", "end"]: | 91 elif key in ["start", "end"]: |
93 current[key] = dateutil.parser.parse(value) | 92 current[key] = datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M") |
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
| |
94 else: | 93 else: |
95 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name)) | 94 raise Exception("Unknown parameter '%s' in file '%s'" % (key, name)) |
96 | 95 |
97 for text_key in ("title", "message"): | 96 for text_key in ("title", "message"): |
98 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] |
99 if (not has_default_locale(notification) and | 98 if (not has_default_locale(notification) and |
100 not all(map(has_default_locale, notification.get("variants", [])))): | 99 not all(map(has_default_locale, notification.get("variants", [])))): |
101 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'" % |
102 (text_key, name)) | 101 (text_key, name)) |
103 return notification | 102 return notification |
(...skipping 20 matching lines...) Expand all Loading... | |
124 continue | 123 continue |
125 current_time = datetime.datetime.now() | 124 current_time = datetime.datetime.now() |
126 if "start" in notification and current_time < notification["start"]: | 125 if "start" in notification and current_time < notification["start"]: |
127 continue | 126 continue |
128 if "end" in notification and current_time > notification["end"]: | 127 if "end" in notification and current_time > notification["end"]: |
129 continue | 128 continue |
130 notifications.append(notification) | 129 notifications.append(notification) |
131 except: | 130 except: |
132 traceback.print_exc() | 131 traceback.print_exc() |
133 return notifications | 132 return notifications |
LEFT | RIGHT |