Commit 2feb4b61 authored by Lisa's avatar Lisa

akabei-conf-import.py now also generates the mirrorlist (with args for source...

akabei-conf-import.py now also generates the mirrorlist (with args for source and dest paths), and it supports running with python3 too.
parent 1aa5da5e
#!/usr/bin/python
# A script to convert a Pacman config file into an Akabei config file
# A script to convert a Pacman config file and mirrorlist into an
# Akabei config file and mirrorlist.
#
# Copyright (C) 2011 Lisa Vitolo <shainer@chakra-project.org>
# Copyright (C) 2011 Lisa Vitolo <shainer@chakraos.org>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
......@@ -51,25 +52,45 @@ def parseOptionLine(line, akabeiConf):
akabeiConf.write(sep)
akabeiConf.write(value)
# There is no format conversion to do here, we just copy the
# whole content.
def CopyMirrorlist(pacmanMirrorFile, akabeiMirrorFile):
pacmanMirrors = ''
with open(pacmanMirrorFile, 'r') as pm:
pacmanMirrors = pm.read()
with open(akabeiMirrorFile, 'w') as am:
am.write(pacmanMirrors)
# Prints an help message
def usage():
print "usage: " + sys.argv[0] + " [--help] [--pacman=<path to pacman.conf>] [--akabei=<path to akabei.conf>]"
print("usage: " + sys.argv[0] + " [--help] [--pacman=<path to pacman.conf>] [--akabei=<path to akabei.conf>]")
print
print "Options:"
print " -h, --help Prints this help message"
print " -p, --pacman <file> Reads pacman configuration from <file> (default: /etc/pacman.conf)"
print " -a, --akabei <file> Writes akabei configuration in <file> (default: /etc/akabei.conf)"
print("Options:")
print(" -h, --help Prints this help message")
print(" -p, --pacman <file> Reads pacman configuration from <file> (default: /etc/pacman.conf)")
print(" -a, --akabei <file> Writes akabei configuration in <file> (default: /etc/akabei.conf)")
print(" -m, --pacman-mirrors <file> Reads pacman mirrorlist from <file> (default: /etc/pacman.d/mirrorlist)")
print(" -n --akabei-mirrors <file> Writes akabei mirrorlist to <file> (default: /etc/akabei.d/mirrorlist))")
print("Note: if your destination paths already exists, they will be overwritten.")
# Start point
if __name__ == "__main__":
# Default values for the commandline arguments.
pacmanFile = "/etc/pacman.conf"
akabeiFile = "/etc/akabei.conf"
pacmanMirrorFile = "/etc/pacman.d/mirrorlist"
akabeiMirrorFile = "/etc/akabei.d/mirrorlist"
opts = None
try:
opts = getopt.getopt(sys.argv[1:], "hp:a:", ["help", "pacman=", "akabei="])
except getopt.GetoptError, error:
print str(error)
opts = getopt.getopt(
sys.argv[1:], "hp:a:m:n:",
["help", "pacman=", "akabei=", "pacman-mirrors=", "akabei-mirrors="])
except getopt.GetoptError as error:
print(str(error))
usage()
sys.exit(-1)
......@@ -81,6 +102,10 @@ if __name__ == "__main__":
pacmanFile = arg
elif opt in ("-a", "--akabei"):
akabeiFile = arg
elif opt in ("-m", "--pacman-mirrors"):
pacmanMirrorFile = arg
elif opt in ("-n", "--akabei-mirrors"):
akabeiMirrorFile = arg
pacmanConf = None
akabeiConf = None
......@@ -88,11 +113,12 @@ if __name__ == "__main__":
try:
pacmanConf = open(pacmanFile, "r")
akabeiConf = open(akabeiFile, "w")
except IOError, error:
print str(error)
except IOError as error:
print(str(error))
sys.exit(-1)
for pacmanLine in pacmanConf.readlines():
if pacmanLine == "\n" or "[options]" in pacmanLine:
akabeiConf.write("\n")
continue
......@@ -117,6 +143,9 @@ if __name__ == "__main__":
# they are be deleted/modified to avoid confusion for the reader
parseOptionLine(separatedLine[2], akabeiConf)
print "[**] Your akabei configuration was created successfully. Exiting..."
print("[**] Your akabei configuration was created successfully.")
pacmanConf.close()
akabeiConf.close()
\ No newline at end of file
akabeiConf.close()
CopyMirrorlist(pacmanMirrorFile, akabeiMirrorFile)
print("[**] Your akabei mirrorlist was created successfully.")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment