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 18 matching lines...) Expand all Loading... |
29 def chown((uid, gid), dirname, names): | 29 def chown((uid, gid), dirname, names): |
30 for name in names: | 30 for name in names: |
31 os.chown(os.path.join(dirname, name), uid, gid) | 31 os.chown(os.path.join(dirname, name), uid, gid) |
32 if (name.endswith('.fcgi') or name.endswith('.sh') or name.endswith('.pl')): | 32 if (name.endswith('.fcgi') or name.endswith('.sh') or name.endswith('.pl')): |
33 os.chmod(os.path.join(dirname, name), 0755) | 33 os.chmod(os.path.join(dirname, name), 0755) |
34 | 34 |
35 def syncFiles(name, settings, syncState): | 35 def syncFiles(name, settings, syncState): |
36 repo, path = splitRepositoryPath(settings['source']) | 36 repo, path = splitRepositoryPath(settings['source']) |
37 | 37 |
38 command = ['hg', 'log', '-R', repo, '-r', 'default', '--template', '{node|shor
t}'] | 38 command = ['hg', 'log', '-R', repo, '-r', 'default', '--template', '{node|shor
t}'] |
39 currentRevision, dummy = subprocess.Popen(command, stdout=subprocess.PIPE).com
municate() | 39 currentRevision = subprocess.check_output(command) |
40 | 40 |
41 if not syncState.has_section(name): | 41 if not syncState.has_section(name): |
42 syncState.add_section(name) | 42 syncState.add_section(name) |
43 if syncState.has_option(name, 'latestRevision') and currentRevision == syncSta
te.get(name, 'latestRevision'): | 43 if syncState.has_option(name, 'latestRevision') and currentRevision == syncSta
te.get(name, 'latestRevision'): |
44 # Already up to date, nothing to do | 44 # Already up to date, nothing to do |
45 return | 45 return |
46 | 46 |
47 tempdir = tempfile.mkdtemp(prefix=name) | 47 tempdir = tempfile.mkdtemp(prefix=name) |
48 try: | 48 try: |
49 command = ['hg', 'archive', '-R', repo, '-r', 'default', | 49 command = ['hg', 'archive', '-R', repo, '-r', 'default', |
50 '-I', os.path.join(repo, path), | 50 '-I', os.path.join(repo, path), |
51 '-X', os.path.join(repo, '.hg_archival.txt'), | 51 '-X', os.path.join(repo, '.hg_archival.txt'), |
52 '-X', os.path.join(repo, '.hgtags'), | 52 '-X', os.path.join(repo, '.hgtags'), |
53 '-X', os.path.join(repo, '.hgignore'), | 53 '-X', os.path.join(repo, '.hgignore'), |
54 '-X', os.path.join(repo, '.hgsub'), | 54 '-X', os.path.join(repo, '.hgsub'), |
55 '-X', os.path.join(repo, '.hgsubstate'), | 55 '-X', os.path.join(repo, '.hgsubstate'), |
56 tempdir] | 56 tempdir] |
57 | 57 |
58 subprocess.Popen(command, stdout=subprocess.PIPE).communicate() | 58 subprocess.check_output(command) |
59 srcdir = os.path.normpath(os.path.join(tempdir, path)) | 59 srcdir = os.path.normpath(os.path.join(tempdir, path)) |
60 for relpath in settings['ignore']: | 60 for relpath in settings['ignore']: |
61 abspath = os.path.join(srcdir, relpath) | 61 abspath = os.path.join(srcdir, relpath) |
62 if os.path.commonprefix((abspath, srcdir)) == srcdir and os.path.exists(ab
spath): | 62 if os.path.commonprefix((abspath, srcdir)) == srcdir and os.path.exists(ab
spath): |
63 shutil.rmtree(abspath) | 63 shutil.rmtree(abspath) |
64 | 64 |
65 if hasattr(os, 'chown') and settings['user'] and settings['group']: | 65 if hasattr(os, 'chown') and settings['user'] and settings['group']: |
66 from pwd import getpwnam | 66 from pwd import getpwnam |
67 from grp import getgrnam | 67 from grp import getgrnam |
68 uid = getpwnam(settings['user']).pw_uid | 68 uid = getpwnam(settings['user']).pw_uid |
69 gid = getgrnam(settings['group']).gr_gid | 69 gid = getgrnam(settings['group']).gr_gid |
70 os.path.walk(srcdir, chown, (uid, gid)) | 70 os.path.walk(srcdir, chown, (uid, gid)) |
71 os.chmod(srcdir, 0755) | 71 os.chmod(srcdir, 0755) |
72 os.chown(srcdir, uid, gid) | 72 os.chown(srcdir, uid, gid) |
73 | 73 |
74 command = ['rsync', '-a', '--delete'] | 74 command = ['rsync', '-a', '--delete'] |
75 for relpath in settings['ignore']: | 75 for relpath in settings['ignore']: |
76 abspath = os.path.join(settings['target'], relpath) | 76 abspath = os.path.join(settings['target'], relpath) |
77 if os.path.commonprefix((abspath, settings['target'])) == settings['target
'] and os.path.lexists(abspath): | 77 if os.path.commonprefix((abspath, settings['target'])) == settings['target
'] and os.path.lexists(abspath): |
78 command.append('--exclude') | 78 command.append('--exclude') |
79 if os.path.isdir(abspath) and not os.path.islink(abspath): | 79 if os.path.isdir(abspath) and not os.path.islink(abspath): |
80 command.append(os.path.join(relpath, '')) | 80 command.append(os.path.join(relpath, '')) |
81 else: | 81 else: |
82 command.append(relpath) | 82 command.append(relpath) |
83 command.append(os.path.join(srcdir, '')) | 83 command.append(os.path.join(srcdir, '')) |
84 command.append(settings['target']) | 84 command.append(settings['target']) |
85 subprocess.Popen(command, stdout=subprocess.PIPE).communicate() | 85 subprocess.check_output(command) |
86 | 86 |
87 if settings['postsync']: | 87 if settings['postsync']: |
88 subprocess.Popen(settings['postsync'], stdout=subprocess.PIPE, shell=True,
cwd=settings['target']).communicate() | 88 subprocess.check_output(settings['postsync'], shell=True, cwd=settings['ta
rget']) |
89 | 89 |
90 syncState.set(name, 'latestRevision', currentRevision) | 90 syncState.set(name, 'latestRevision', currentRevision) |
91 finally: | 91 finally: |
92 shutil.rmtree(tempdir, ignore_errors=True) | 92 shutil.rmtree(tempdir, ignore_errors=True) |
93 | 93 |
94 def readSyncSettings(): | 94 def readSyncSettings(): |
95 result = {} | 95 result = {} |
96 for option in get_config().options('filesync'): | 96 for option in get_config().options('filesync'): |
97 if option.find('_') < 0: | 97 if option.find('_') < 0: |
98 continue | 98 continue |
(...skipping 23 matching lines...) Expand all Loading... |
122 syncStateFile = get_config().get('filesync', 'syncData') | 122 syncStateFile = get_config().get('filesync', 'syncData') |
123 if os.path.exists(syncStateFile): | 123 if os.path.exists(syncStateFile): |
124 syncState.read(syncStateFile) | 124 syncState.read(syncStateFile) |
125 | 125 |
126 settings = readSyncSettings() | 126 settings = readSyncSettings() |
127 for name, value in settings.iteritems(): | 127 for name, value in settings.iteritems(): |
128 syncFiles(name, value, syncState) | 128 syncFiles(name, value, syncState) |
129 | 129 |
130 file = open(syncStateFile, 'wb') | 130 file = open(syncStateFile, 'wb') |
131 syncState.write(file) | 131 syncState.write(file) |
OLD | NEW |