OLD | NEW |
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-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 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 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 links = {} | 26 links = {} |
27 UPDATE_INTERVAL = 10 * 60 # 10 minutes | 27 UPDATE_INTERVAL = 10 * 60 # 10 minutes |
28 | 28 |
29 | 29 |
30 @url_handler('/latest/') | 30 @url_handler('/latest/') |
31 def handle_request(environ, start_response): | 31 def handle_request(environ, start_response): |
32 request = urlparse.urlparse(environ.get('REQUEST_URI', '')) | 32 request = urlparse.urlparse(environ.get('REQUEST_URI', '')) |
33 basename = posixpath.splitext(posixpath.basename(request.path))[0] | 33 basename = posixpath.splitext(posixpath.basename(request.path))[0] |
34 if basename in links: | 34 if basename in links: |
35 start_response('302 Found', [('Location', links[basename].encode("utf-8"
))]) | 35 start_response('302 Found', [('Location', links[basename].encode('utf-8'
))]) |
36 else: | 36 else: |
37 start_response('404 Not Found', []) | 37 start_response('404 Not Found', []) |
38 return [] | 38 return [] |
39 | 39 |
40 | 40 |
41 def _get_links(): | 41 def _get_links(): |
42 parser = SafeConfigParser() | 42 parser = SafeConfigParser() |
43 getDownloadLinks(parser) | 43 getDownloadLinks(parser) |
44 result = {} | 44 result = {} |
45 for section in parser.sections(): | 45 for section in parser.sections(): |
46 result[section] = parser.get(section, "downloadURL") | 46 result[section] = parser.get(section, 'downloadURL') |
47 return result | 47 return result |
48 | 48 |
49 | 49 |
50 def _update_links(): | 50 def _update_links(): |
51 global links | 51 global links |
52 | 52 |
53 while True: | 53 while True: |
54 try: | 54 try: |
55 links = _get_links() | 55 links = _get_links() |
56 except: | 56 except: |
57 traceback.print_exc() | 57 traceback.print_exc() |
58 time.sleep(UPDATE_INTERVAL) | 58 time.sleep(UPDATE_INTERVAL) |
59 | 59 |
60 t = threading.Thread(target=_update_links) | 60 t = threading.Thread(target=_update_links) |
61 t.daemon = True | 61 t.daemon = True |
62 t.start() | 62 t.start() |
OLD | NEW |