| 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, | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  21 from shutil import rmtree |  21 from shutil import rmtree | 
|  22  |  22  | 
|  23 def updateExternalFiles(): |  23 def updateExternalFiles(): | 
|  24   settings = readSettings() |  24   settings = readSettings() | 
|  25   for setting in settings.itervalues(): |  25   for setting in settings.itervalues(): | 
|  26     tempdir = mkdtemp(prefix='external') |  26     tempdir = mkdtemp(prefix='external') | 
|  27     try: |  27     try: | 
|  28       repoPath = setting['targetrepository'] |  28       repoPath = setting['targetrepository'] | 
|  29       targetPath = os.path.dirname(setting['targetfile']) |  29       targetPath = os.path.dirname(setting['targetfile']) | 
|  30       filename = os.path.basename(setting['targetfile']) |  30       filename = os.path.basename(setting['targetfile']) | 
|  31        |  31  | 
|  32       subprocess.Popen(['hg', 'clone', '-q', '-U', repoPath, tempdir], stdout=su
    bprocess.PIPE).communicate() |  32       subprocess.check_call(['hg', 'clone', '-q', '-U', repoPath, tempdir]) | 
|  33       subprocess.Popen(['hg', 'up', '-q', '-R', tempdir, '-r', 'default'], stdou
    t=subprocess.PIPE).communicate() |  33       subprocess.check_call(['hg', 'up', '-q', '-R', tempdir, '-r', 'default']) | 
|  34        |  34  | 
|  35       path = os.path.join(tempdir, targetPath) |  35       path = os.path.join(tempdir, targetPath) | 
|  36       if not os.path.exists(path): |  36       if not os.path.exists(path): | 
|  37         os.makedirs(path) |  37         os.makedirs(path) | 
|  38        |  38  | 
|  39       path = os.path.join(path, filename) |  39       path = os.path.join(path, filename) | 
|  40       exists = os.path.exists(path) |  40       exists = os.path.exists(path) | 
|  41       file = codecs.open(path, 'wb', encoding='utf-8') |  41       file = codecs.open(path, 'wb', encoding='utf-8') | 
|  42       data = urllib.urlopen(setting['source']).read().decode('utf-8') |  42       data = urllib.urlopen(setting['source']).read().decode('utf-8') | 
|  43       file.write(data) |  43       file.write(data) | 
|  44       file.close() |  44       file.close() | 
|  45  |  45  | 
|  46       message = 'Updated copy of external file %s' |  46       message = 'Updated copy of external file %s' | 
|  47       if not exists: |  47       if not exists: | 
|  48         message = 'Added copy of external file %s' |  48         message = 'Added copy of external file %s' | 
|  49       subprocess.Popen(['hg', 'commit', '-q', '-A', '-R', tempdir, '-u', 'hgbot'
    , '-m', message % filename], stdout=subprocess.PIPE).communicate() |  49       subprocess.check_call(['hg', 'commit', '-q', '-A', '-R', tempdir, '-u', 'h
    gbot', '-m', message % filename]) | 
|  50       subprocess.Popen(['hg', 'push', '-q', '-R', tempdir], stdout=subprocess.PI
    PE).communicate() |  50  | 
 |  51       # Don't check the result of this call, it will be 1 if nothing needs pushi
    ng | 
 |  52       subprocess.call(['hg', 'push', '-q', '-R', tempdir]) | 
|  51     finally: |  53     finally: | 
|  52       rmtree(tempdir) |  54       rmtree(tempdir) | 
|  53  |  55  | 
|  54 def readSettings(): |  56 def readSettings(): | 
|  55   result = {} |  57   result = {} | 
|  56   for option, value in get_config().items('externalFiles'): |  58   for option, value in get_config().items('externalFiles'): | 
|  57     if option.find('_') < 0: |  59     if option.find('_') < 0: | 
|  58       continue |  60       continue | 
|  59     name, setting = option.rsplit('_', 2) |  61     name, setting = option.rsplit('_', 2) | 
|  60     if not setting in ('source', 'targetrepository', 'targetfile'): |  62     if not setting in ('source', 'targetrepository', 'targetfile'): | 
|  61       continue |  63       continue | 
|  62  |  64  | 
|  63     if not name in result: |  65     if not name in result: | 
|  64       result[name] = { |  66       result[name] = { | 
|  65         'source': None, |  67         'source': None, | 
|  66         'targetrepository': None, |  68         'targetrepository': None, | 
|  67         'targetfile': None |  69         'targetfile': None | 
|  68       } |  70       } | 
|  69     result[name][setting] = value |  71     result[name][setting] = value | 
|  70   return result |  72   return result | 
|  71  |  73  | 
|  72 if __name__ == '__main__': |  74 if __name__ == '__main__': | 
|  73   setupStderr() |  75   setupStderr() | 
|  74   updateExternalFiles() |  76   updateExternalFiles() | 
| OLD | NEW |