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 ConfigParser | 19 import ConfigParser |
20 import json | 20 import json |
21 import os | 21 import os |
22 from StringIO import StringIO | 22 from StringIO import StringIO |
23 import subprocess | 23 import subprocess |
24 import sys | |
25 import urlparse | 24 import urlparse |
26 import zipfile | 25 import zipfile |
| 26 import logging |
27 | 27 |
28 class Source: | 28 class Source: |
29 def resolve_link(self, url, locale): | 29 def resolve_link(self, url, locale): |
30 parsed = urlparse.urlparse(url) | 30 parsed = urlparse.urlparse(url) |
31 page = parsed.path | 31 page = parsed.path |
32 if parsed.scheme != "" or page.startswith("/") or page.startswith("."): | 32 if parsed.scheme != "" or page.startswith("/") or page.startswith("."): |
33 # Not a page link | 33 # Not a page link |
34 return None, None | 34 return None, None |
35 | 35 |
36 if page == "" and url != "": | 36 if page == "" and url != "": |
(...skipping 15 matching lines...) Expand all Loading... |
52 if self.has_localizable_file(default_locale, page): | 52 if self.has_localizable_file(default_locale, page): |
53 if not self.has_localizable_file(locale, page): | 53 if not self.has_localizable_file(locale, page): |
54 locale = default_locale | 54 locale = default_locale |
55 elif self.has_page(page): | 55 elif self.has_page(page): |
56 if not has_locale(locale, page): | 56 if not has_locale(locale, page): |
57 locale = default_locale | 57 locale = default_locale |
58 elif self.has_page(alternative_page): | 58 elif self.has_page(alternative_page): |
59 if not has_locale(locale, alternative_page): | 59 if not has_locale(locale, alternative_page): |
60 locale = default_locale | 60 locale = default_locale |
61 else: | 61 else: |
62 print >>sys.stderr, "Warning: Link to %s cannot be resolved" % page | 62 logging.warning("Link to %s cannot be resolved", page) |
63 | 63 |
64 parts = page.split("/") | 64 parts = page.split("/") |
65 if parts[-1] == default_page: | 65 if parts[-1] == default_page: |
66 page = "/".join(parts[:-1]) | 66 page = "/".join(parts[:-1]) |
67 | 67 |
68 path = "/%s/%s" % (locale, page) | 68 path = "/%s/%s" % (locale, page) |
69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) | 69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) |
70 | 70 |
71 def read_config(self): | 71 def read_config(self): |
72 configdata = self.read_file("settings.ini") | 72 configdata = self.read_file("settings.ini") |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 path = os.path.join(dir, filename) | 282 path = os.path.join(dir, filename) |
283 if os.path.isfile(path): | 283 if os.path.isfile(path): |
284 result.append(relpath + filename) | 284 result.append(relpath + filename) |
285 elif os.path.isdir(path): | 285 elif os.path.isdir(path): |
286 do_list(path, relpath + filename + "/") | 286 do_list(path, relpath + filename + "/") |
287 do_list(self.get_path(subdir), "") | 287 do_list(self.get_path(subdir), "") |
288 return result | 288 return result |
289 | 289 |
290 def get_cache_dir(self): | 290 def get_cache_dir(self): |
291 return os.path.join(self._dir, "cache") | 291 return os.path.join(self._dir, "cache") |
OLD | NEW |