diff options
author | Fabian Affolter <fabian@bernewireless.net> | 2011-07-24 01:04:43 +0200 |
---|---|---|
committer | Fabian Affolter <fabian@affolter-engineering.ch> | 2019-01-10 17:29:54 +0000 |
commit | 4e1f621cdaa8d3560c4606f45cca32404abda9c3 (patch) | |
tree | 001e49539ab01616d439ef83b009fc1d811bf947 | |
parent | 5e4d1c8c25d7424c391c2dbaaf792c15e9d20e36 (diff) | |
download | alpine-iso-4e1f621cdaa8d3560c4606f45cca32404abda9c3.tar.bz2 alpine-iso-4e1f621cdaa8d3560c4606f45cca32404abda9c3.tar.xz |
config-builder is able to create a package list from a mediawiki
page or the Alpine Linux Git repository. In the list below are two
pages shown that are included in the config-builder script.
Alpine Rescue http://wiki.alpinelinux.org/wiki/Alpine_rescue
Alpine Mini http://wiki.alpinelinux.org/wiki/Alpine_mini
config-builder allows you to grab data from any mediawiki instance
to build your package list. A requirement for the mediawiki pages
is that the package names are placed in a table (class wikitable).
Beside that nothing else is needed. You are free to format your
page as you like. If you are unsure about the table layout just
take a look at one of the two page mentioned above.
-rw-r--r-- | config-builder.py | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/config-builder.py b/config-builder.py new file mode 100644 index 0000000..7b388b6 --- /dev/null +++ b/config-builder.py @@ -0,0 +1,172 @@ +# This simple script can be used to create package list +# Copyright (c) 2011 Fabian Affolter <fabian@affolter-engineering.ch> +# +# All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import os +import sys +import urllib2 +import unicodedata +import codecs +from optparse import OptionParser +from BeautifulSoup import BeautifulSoup + +def get_pkg(url): + """Retrieve the data from the website.""" + page = urllib2.urlopen(url) + soup = BeautifulSoup(page) + completeList = [] + outputList = [] + for node in soup.findAll(attrs={'class':'wikitable'}): + rows = node.findAll('tr') + nameList = [] + for tr in rows: + cols = tr.findAll('td') + if len(cols) == 0: + continue + toolDetails = [] + for td in cols: + entries = unicodedata.normalize('NFKD', + ''.join(td.find(text=True))).encode('ascii', 'replace') + toolDetails.append(entries.strip()) + # Prints list with the tool's details + #print toolDetails + nameList.append(toolDetails[0]) + outputList.append(toolDetails[0]) + completeList.append(nameList) + return outputList + +def get_git(volume): + """Retrieve all packages from the Alpine Git repository.""" + if volume == 'everything': + urls = ['http://git.alpinelinux.org/cgit/aports.git/tree/main', + 'http://git.alpinelinux.org/cgit/aports.git/tree/testing'] + else: + urls = ['http://git.alpinelinux.org/cgit/aports.git/tree/main'] + outputList = [] + for url in urls: + page = urllib2.urlopen(url) + soup = BeautifulSoup(page) + for node in soup.findAll(attrs={'class':'ls-dir'}): + outputList.append(node.contents[0]) + return outputList + +def create_files(names, flavor): + """Creates the configuration files.""" + data = """ALPINE_NAME\t\t:= alpine-%s\nKERNEL_FLAVOR\t:= grsec\nMODLOOP_EXTRA\t:= """ % (flavor) + if names != None: + filename = 'alpine-' + flavor + '.packages' + else: + filename = 'alpine-' + flavor + '.conf.mk' + if os.path.exists(os.getcwd() + '/' + filename): + try: + result = raw_input("\nWarning: %s already exists. " + "Overwrite? [N/y]: " % (filename)) + except NameError: + result = input("\nWarning: %s already exists. " + "Overwrite? [N/y]: " % (filename)) + if result not in ['Y', 'y']: + print "Leaving %s unchanged." % (filename) + return + try: + if names != None: + pkg_file = open(os.getcwd() + '/' + filename, "w") + for entry in names: + pkg_file.write(entry + u'\n') + print "%s packages added to '%s'." % (len(names), filename) + else: + open(os.getcwd() + '/' + filename, "w").write(data) + print "Configuration written to '%s'." % (filename) + except Exception: + e = sys.exc_info()[1] + print("Error %s occured while trying to write the package list " + "file to '%s'.\n" % + (e, os.getcwd() + '/' + filename)) + raise SystemExit(1) + +def main(): + parser = OptionParser( + usage = "usage: %prog [options]", + version = "%prog 0.1", + description = """This tool can help you to create configurations and package lists to use with the alpine-iso script.""", + epilog = "Please report all bug: <http://bugs.alpinelinux.org/>") + + parser.add_option("-f", "--flavor", + type = 'choice', + action = 'store', + dest = 'flavor', + choices = ['security', + 'rescue', + 'main', + 'everything', + 'mini' + ], + help = "create a list of all available packages") + + parser.add_option("-u", "--URL", + action = "store", + dest = "url", + help = "fetch the data from the given URL") + + parser.add_option("-n", "--Name", + action = "store", + dest = "name", + help = "used as name for the custom ISO image") + + (options, args) = parser.parse_args() + + if options.url == None and options.flavor == None and options.name == None: + parser.print_help() + exit(-1) + + if options.url == None and options.name !=None: + print "'-n, --Name' can only be used with the URL option." + exit(-1) + + if options.flavor != None: + if options.flavor == 'main': + print """Package list of '%s' is created...""" % (options.flavor) + create_files(get_git(options.flavor), options.flavor) + create_files(None, options.flavor) + return + if options.flavor == 'everything': + print """Package list of '%s' is created...""" % (options.flavor) + create_files(get_git(options.flavor), options.flavor) + create_files(None, options.flavor) + return + else: + print """Package list for Alpine %s is created...""" \ + % (options.flavor).capitalize() + url = "http://wiki.alpinelinux.org/wiki/Alpine_" + options.flavor + print "Source: %s" % url + create_files(get_pkg(url), options.flavor) + create_files(None, options.flavor.lower()) + + if options.url != None and options.flavor == None: + url = options.url + if options.name != None: + flavor = (options.name).lower() + else: + flavor = 'custom' + print """Package list for Alpine %s is created...""" \ + % (flavor.capitalize()) + print "Source: %s" % url + create_files(get_pkg(url), flavor) + create_files(None, flavor) + +if __name__ == '__main__': + main() |