Introduce emu8086
[lcapit-junk-code.git] / lfs-get-tarballs
blob77759b7b2b0f43a32023481a26f6fa7e39349ff3
1 #!/usr/bin/python
3 # Download all the LFS tarballs (or patches) from the provided download page
5 # Luiz Fernando N. Capitulino
6 # <lcapitulino@gmail.com>
8 from os import system
9 from urllib import urlopen
10 from sys import argv, exit
11 from HTMLParser import HTMLParser
13 class LFSPackParser(HTMLParser):
14 def is_package(self, url):
15 if url.find('.tar.') != -1:
16 return True
17 if url.endswith('.patch'):
18 return True
19 return False
21 def handle_starttag(self, tag, attrs):
22 if tag == 'a' and self.is_package(attrs[1][1]):
23 self.hyperlinks.append(attrs[1][1])
25 def get_hyperlinks(self):
26 return self.hyperlinks
28 def __init__(self):
29 HTMLParser.__init__(self)
30 self.hyperlinks = []
32 def get_package_list(addr):
33 page = urlopen(addr)
34 parser = LFSPackParser()
35 parser.feed(page.read())
36 parser.close()
37 page.close()
38 return parser.get_hyperlinks()
40 def main():
41 if len(argv) != 2 or argv[1] == '-h':
42 print 'usage: lfs-get-tarballs < LFS download page >'
43 exit(1)
45 failed = []
46 pack_list = get_package_list(argv[1])
48 print '\nDownloading ' + str(len(pack_list)) + ' packages\n'
50 for name in pack_list:
51 ret = system('wget ' + name)
52 if ret != 0:
53 failed.append(name)
55 if len(failed) != 0:
56 print '\nWARNING: could not download the following packages\n'
57 for name in failed:
58 print '\t-> ' + name
59 print
61 if __name__ == '__main__':
62 main()