LEFT | RIGHT |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 def list_localizable_files(self): | 118 def list_localizable_files(self): |
119 default_locale = self.read_config().get('general', 'defaultlocale') | 119 default_locale = self.read_config().get('general', 'defaultlocale') |
120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', | 120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', |
121 self.list_files('locales/%s' % default_locale)) | 121 self.list_files('locales/%s' % default_locale)) |
122 | 122 |
123 def has_localizable_file(self, locale, filename): | 123 def has_localizable_file(self, locale, filename): |
124 return self.has_file(self.localizable_file_filename(locale, filename)) | 124 return self.has_file(self.localizable_file_filename(locale, filename)) |
125 | 125 |
126 def read_localizable_file(self, locale, filename): | 126 def read_localizable_file(self, locale, filename): |
127 return self.read_file(self.localizable_file_filename(locale, filename),
binary=True)[0] | 127 return self.read_file(self.localizable_file_filename(locale, filename),
True)[0] |
128 | 128 |
129 # | 129 # |
130 # Static file helpers | 130 # Static file helpers |
131 # | 131 # |
132 | 132 |
133 @staticmethod | 133 @staticmethod |
134 def static_filename(filename): | 134 def static_filename(filename): |
135 return 'static/%s' % filename | 135 return 'static/%s' % filename |
136 | 136 |
137 def list_static(self): | 137 def list_static(self): |
138 return self.list_files('static') | 138 return self.list_files('static') |
139 | 139 |
140 def has_static(self, filename): | 140 def has_static(self, filename): |
141 return self.has_file(self.static_filename(filename)) | 141 return self.has_file(self.static_filename(filename)) |
142 | 142 |
143 def read_static(self, filename): | 143 def read_static(self, filename): |
144 return self.read_file(self.static_filename(filename), binary=True)[0] | 144 return self.read_file(self.static_filename(filename), True)[0] |
145 | 145 |
146 # | 146 # |
147 # Locale helpers | 147 # Locale helpers |
148 # | 148 # |
149 | 149 |
150 def locale_filename(self, locale, page): | 150 def locale_filename(self, locale, page): |
151 config = self.read_config() | 151 config = self.read_config() |
152 try: | 152 try: |
153 page = config.get('locale_overrides', page) | 153 page = config.get('locale_overrides', page) |
154 except ConfigParser.Error: | 154 except ConfigParser.Error: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 path = os.path.join(dir, filename) | 267 path = os.path.join(dir, filename) |
268 if os.path.isfile(path): | 268 if os.path.isfile(path): |
269 result.append(relpath + filename) | 269 result.append(relpath + filename) |
270 elif os.path.isdir(path): | 270 elif os.path.isdir(path): |
271 do_list(path, relpath + filename + '/') | 271 do_list(path, relpath + filename + '/') |
272 do_list(self.get_path(subdir), '') | 272 do_list(self.get_path(subdir), '') |
273 return result | 273 return result |
274 | 274 |
275 def write_to_config(self, section, option, value): | 275 def write_to_config(self, section, option, value): |
276 config = self.read_config() | 276 config = self.read_config() |
277 config.set(section, option, value) | 277 try: |
278 config.write(open(self.get_path('settings.ini'), 'w')) | 278 config.set(section, option, value) |
| 279 except ConfigParser.NoSectionError: |
| 280 config.add_section(section) |
| 281 config.set(section, option, value) |
| 282 with open(self.get_path('settings.ini'), 'w') as cnf: |
| 283 config.write(cnf) |
279 | 284 |
280 def get_cache_dir(self): | 285 def get_cache_dir(self): |
281 return os.path.join(self._dir, 'cache') | 286 return os.path.join(self._dir, 'cache') |
282 | 287 |
283 | 288 |
284 class MultiSource(Source): | 289 class MultiSource(Source): |
285 """A source that combines the contents of multiple other sources.""" | 290 """A source that combines the contents of multiple other sources.""" |
286 | 291 |
287 def __init__(self, base_sources): | 292 def __init__(self, base_sources): |
288 self._bases = base_sources | 293 self._bases = base_sources |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 397 |
393 if additional_paths: | 398 if additional_paths: |
394 additional_sources = [ | 399 additional_sources = [ |
395 create_source(os.path.join(path, p)) | 400 create_source(os.path.join(path, p)) |
396 for p in additional_paths | 401 for p in additional_paths |
397 ] | 402 ] |
398 source = MultiSource([source] + additional_sources) | 403 source = MultiSource([source] + additional_sources) |
399 | 404 |
400 if cached: | 405 if cached: |
401 for fname in [ | 406 for fname in [ |
| 407 'list_files', |
| 408 'list_locales', |
402 'resolve_link', | 409 'resolve_link', |
403 'read_config', | 410 'read_config', |
404 'read_template', | 411 'read_template', |
405 'read_locale', | 412 'read_locale', |
| 413 'read_file', |
406 'read_include', | 414 'read_include', |
407 'exec_file', | 415 'exec_file', |
408 ]: | 416 ]: |
409 setattr(source, fname, _memoize(getattr(source, fname))) | 417 setattr(source, fname, _memoize(getattr(source, fname))) |
410 | 418 |
411 return source | 419 return source |
LEFT | RIGHT |