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, subprocess, codecs, urllib, zipfile, tempfile, shutil | 18 import os, subprocess, codecs, urllib, zipfile, tempfile, shutil |
19 from StringIO import StringIO | 19 from StringIO import StringIO |
20 from sitescripts.utils import get_config, setupStderr | 20 from sitescripts.utils import get_config, setupStderr |
21 | 21 |
22 if __name__ == '__main__': | 22 if __name__ == '__main__': |
23 setupStderr() | 23 setupStderr() |
24 | 24 |
25 repository = get_config().get('subscriptionDownloads', 'malwaredomains_reposit
ory') | 25 repository = get_config().get('subscriptionDownloads', 'malwaredomains_reposit
ory') |
26 tempdir = tempfile.mkdtemp(prefix='malwaredomains') | 26 tempdir = tempfile.mkdtemp(prefix='malwaredomains') |
27 try: | 27 try: |
28 subprocess.Popen(['hg', '-q', 'clone', '-U', repository, tempdir]).communic
ate() | 28 subprocess.check_call(['hg', '-q', 'clone', '-U', repository, tempdir]) |
29 subprocess.Popen(['hg', '-q', 'up', '-R', tempdir, '-r', 'default']).communi
cate() | 29 subprocess.check_call(['hg', '-q', 'up', '-R', tempdir, '-r', 'default']) |
30 | 30 |
31 path = os.path.join(tempdir, 'malwaredomains_full.txt') | 31 path = os.path.join(tempdir, 'malwaredomains_full.txt') |
32 file = codecs.open(path, 'wb', encoding='utf-8') | 32 file = codecs.open(path, 'wb', encoding='utf-8') |
33 | 33 |
34 print >>file, '''[Adblock Plus 1.1] | 34 print >>file, '''[Adblock Plus 1.1] |
35 ! This is a list of malware domains generated from malwaredomains.com data. | 35 ! This is a list of malware domains generated from malwaredomains.com data. |
36 ! Homepage: http://malwaredomains.com/?page_id=2 | 36 ! Homepage: http://malwaredomains.com/?page_id=2 |
37 ! Last modified: %timestamp% | 37 ! Last modified: %timestamp% |
38 ! Expires: 1d | 38 ! Expires: 1d |
39 !''' | 39 !''' |
40 | 40 |
41 data = urllib.urlopen('http://mirror3.malwaredomains.com/files/justdomains.z
ip').read() | 41 data = urllib.urlopen('http://mirror3.malwaredomains.com/files/justdomains.z
ip').read() |
42 zip = zipfile.ZipFile(StringIO(data), 'r') | 42 zip = zipfile.ZipFile(StringIO(data), 'r') |
43 info = zip.infolist()[0] | 43 info = zip.infolist()[0] |
44 for line in str(zip.read(info.filename)).splitlines(): | 44 for line in str(zip.read(info.filename)).splitlines(): |
45 if not line: | 45 if not line: |
46 continue | 46 continue |
47 print >>file, '||%s^' % line.strip().decode('iso-8859-1') | 47 print >>file, '||%s^' % line.strip().decode('iso-8859-1') |
48 file.close(); | 48 file.close(); |
49 | 49 |
50 subprocess.Popen(['hg', '-q', 'commit', '-R', tempdir, '-A', '-u', 'hgbot',
'-m', 'Updated malwaredomains.com data']).communicate() | 50 subprocess.check_call(['hg', '-q', 'commit', '-R', tempdir, '-A', '-u', 'hgb
ot', '-m', 'Updated malwaredomains.com data']) |
51 subprocess.Popen(['hg', '-q', 'push', '-R', tempdir]).communicate() | 51 |
| 52 # Don't check the result of this call, it will be 1 if nothing needs pushing |
| 53 subprocess.call(['hg', '-q', 'push', '-R', tempdir]) |
52 finally: | 54 finally: |
53 shutil.rmtree(tempdir, ignore_errors=True) | 55 shutil.rmtree(tempdir, ignore_errors=True) |
OLD | NEW |