| 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-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 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 os, re, subprocess, urllib | 18 import os, re, subprocess, urllib |
| 19 from sitescripts.utils import get_config, setupStderr | 19 from sitescripts.utils import get_config, setupStderr |
| 20 from ConfigParser import SafeConfigParser, NoOptionError | 20 from ConfigParser import SafeConfigParser, NoOptionError |
| 21 from StringIO import StringIO | 21 from StringIO import StringIO |
| 22 | 22 |
| 23 def readStatsFile(path): | 23 def readStatsFile(path): |
| 24 result = SafeConfigParser() | 24 result = SafeConfigParser() |
| 25 match = re.search(r'^ssh://(\w+)@([^/:]+)(?::(\d+))?', path) | 25 match = re.search(r'^ssh://(\w+)@([^/:]+)(?::(\d+))?', path) |
| 26 if match: | 26 if match: |
| 27 command = ['ssh', '-q', '-o' 'NumberOfPasswordPrompts 0', '-T', '-k', '-l',
match.group(1), match.group(2)] | 27 command = ['ssh', '-q', '-o' 'NumberOfPasswordPrompts 0', '-T', '-k', '-l',
match.group(1), match.group(2)] |
| 28 if match.group(3): | 28 if match.group(3): |
| 29 command[1:1] = ['-P', match.group(3)] | 29 command[1:1] = ['-P', match.group(3)] |
| 30 (data, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE).communicat
e() | 30 data = subprocess.check_output(command) |
| 31 result.readfp(StringIO(data)) | 31 result.readfp(StringIO(data)) |
| 32 elif path.startswith('http://') or path.startswith('https://'): | 32 elif path.startswith('http://') or path.startswith('https://'): |
| 33 result.readfp(urllib.urlopen(path)) | 33 result.readfp(urllib.urlopen(path)) |
| 34 elif os.path.exists(path): | 34 elif os.path.exists(path): |
| 35 result.read(path) | 35 result.read(path) |
| 36 return result | 36 return result |
| 37 | 37 |
| 38 def getStatsFiles(): | 38 def getStatsFiles(): |
| 39 config = get_config() | 39 config = get_config() |
| 40 | 40 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 63 increaseOption(section, '%s %s mirror %s' % (match.group(1), match.group
(2), mirrorName), increase) | 63 increaseOption(section, '%s %s mirror %s' % (match.group(1), match.group
(2), mirrorName), increase) |
| 64 | 64 |
| 65 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 66 setupStderr() | 66 setupStderr() |
| 67 | 67 |
| 68 result = readStatsFile(get_config().get('subscriptionStats', 'mainFile')) | 68 result = readStatsFile(get_config().get('subscriptionStats', 'mainFile')) |
| 69 for (mirrorName, statsFile) in getStatsFiles(): | 69 for (mirrorName, statsFile) in getStatsFiles(): |
| 70 mergeStatsFile(mirrorName, result, readStatsFile(statsFile)) | 70 mergeStatsFile(mirrorName, result, readStatsFile(statsFile)) |
| 71 file = open(get_config().get('subscriptionStats', 'mainFile'), 'wb') | 71 file = open(get_config().get('subscriptionStats', 'mainFile'), 'wb') |
| 72 result.write(file) | 72 result.write(file) |
| OLD | NEW |