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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 path = "/%s/%s" % (locale, page) | 61 path = "/%s/%s" % (locale, page) |
62 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) | 62 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) |
63 | 63 |
64 def read_config(self): | 64 def read_config(self): |
65 configdata = self.read_file("settings.ini") | 65 configdata = self.read_file("settings.ini") |
66 config = ConfigParser.SafeConfigParser() | 66 config = ConfigParser.SafeConfigParser() |
67 config.readfp(StringIO(configdata)) | 67 config.readfp(StringIO(configdata)) |
68 return config | 68 return config |
69 | 69 |
| 70 def import_symbol(self, filename, symbol): |
| 71 code = self.read_file(filename) |
| 72 namespace = {} |
| 73 exec code in namespace |
| 74 |
| 75 try: |
| 76 return namespace[symbol] |
| 77 except KeyError: |
| 78 raise Exception("Expected symbol %s not found in %s" % (symbol, filename)) |
| 79 |
70 # | 80 # |
71 # Page helpers | 81 # Page helpers |
72 # | 82 # |
73 | 83 |
74 @staticmethod | 84 @staticmethod |
75 def page_filename(page, format): | 85 def page_filename(page, format): |
76 return "pages/%s.%s" % (page, format) | 86 return "pages/%s.%s" % (page, format) |
77 | 87 |
78 def list_pages(self): | 88 def list_pages(self): |
79 for filename in self.list_files("pages"): | 89 for filename in self.list_files("pages"): |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 path = os.path.join(dir, filename) | 287 path = os.path.join(dir, filename) |
278 if os.path.isfile(path): | 288 if os.path.isfile(path): |
279 result.append(relpath + filename) | 289 result.append(relpath + filename) |
280 elif os.path.isdir(path): | 290 elif os.path.isdir(path): |
281 do_list(path, relpath + filename + "/") | 291 do_list(path, relpath + filename + "/") |
282 do_list(self.get_path(subdir), "") | 292 do_list(self.get_path(subdir), "") |
283 return result | 293 return result |
284 | 294 |
285 def get_cache_dir(self): | 295 def get_cache_dir(self): |
286 return os.path.join(self._dir, "cache") | 296 return os.path.join(self._dir, "cache") |
OLD | NEW |