Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: publicSuffixListUpdater.py

Issue 8627097: Moved Chrome extension scripts to buildtools repository (Closed)
Patch Set: Created Oct. 19, 2012, 10:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packagerKMeleon.py ('k') | releaseAutomationGecko.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This Source Code is subject to the terms of the Mozilla Public License
4 # version 2.0 (the "License"). You can obtain a copy of the License at
5 # http://mozilla.org/MPL/2.0/.
6
7 """
8 Update the public suffix list
9 ==============================
10
11 This script generates a js array of public suffixes (http://publicsuffix.org/)
12 """
13
14 import os
15 import urllib
16 import json
17
18 def urlopen(url, attempts=3):
19 """
20 Tries to open a particular URL, retries on failure.
21 """
22 for i in range(attempts):
23 try:
24 return urllib.urlopen(url)
25 except IOError, e:
26 error = e
27 time.sleep(5)
28 raise error
29
30 def getPublicSuffixList():
31 """
32 gets download link for a Gecko add-on from the Mozilla Addons site
33 """
34 suffixes = {};
35 url = 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld _names.dat?raw=1'
36 resource = urlopen(url)
37
38 for line in resource:
39 line = line.rstrip()
40 if line.startswith("//") or "." not in line:
41 continue
42 if line.startswith('*.'):
43 suffixes[line[2:]] = 2
44 elif line.startswith('!'):
45 suffixes[line[1:]] = 0
46 else:
47 suffixes[line] = 1
48
49 return suffixes
50
51 def updatePSL(baseDir):
52 """
53 writes the current public suffix list to js file in json format
54 """
55
56 psl = getPublicSuffixList()
57 file = open(os.path.join(baseDir, 'lib', 'publicSuffixList.js'), 'w')
58 file.write('var publicSuffixes = ' + json.dumps(psl, sort_keys=True, indent=4) + ';')
59 file.close()
OLDNEW
« no previous file with comments | « packagerKMeleon.py ('k') | releaseAutomationGecko.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld