Move all the files under script to top dir
[lcapit-junk-code.git] / lfs-get-tarballs
blob6a42c92130323f4952d15f043d6c7f326138e54a
1 #!/usr/bin/python
3 # Download all the LFS (development) tarballs from LFS page
5 from os import system
6 from sys import exit
7 import sgmllib, urllib
9 class LFSPackParser(sgmllib.SGMLParser):
10 "LFS download page parser"
12 def parse(self, s):
13 "Parse the given string 's'."
14 self.feed(s)
15 self.close()
17 def __init__(self, verbose=0):
18 "Initialise an object, passing 'verbose' to the superclass."
19 sgmllib.SGMLParser.__init__(self, verbose)
20 self.hyperlinks = []
22 def start_a(self, attributes):
23 "Process a hyperlink and its 'attributes'."
25 for name, value in attributes:
26 if name == "href":
27 self.hyperlinks.append(value)
29 def get_hyperlinks(self):
30 "Return the list of hyperlinks."
31 return self.hyperlinks
33 def get_page_contents():
34 page = urllib.urlopen("http://www.linuxfromscratch.org/lfs/view/development/chapter03/packages.html")
35 contents = page.read()
36 page.close()
37 return contents
39 def get_package_list(page):
40 parser = LFSPackParser()
41 parser.parse(page)
42 packages = []
43 for name in parser.get_hyperlinks():
44 if name.find('.tar') != -1:
45 packages.append(name)
46 return packages
48 def main():
49 page = get_page_contents()
50 for name in get_package_list(page):
51 system("wget " + name)
53 if __name__ == "__main__":
54 main()
56 exit(0)