Commit e899be6b authored by Lisa's avatar Lisa

Split off some functions in akabei-db-import to a common module, so we can use...

Split off some functions in akabei-db-import to a common module, so we can use them for the new pacman-db-import script too. Add more docstrings.
parent efef3991
......@@ -14,45 +14,17 @@ import sys
import os
import getopt
from db_import import *
from akabeipackage import *
from akabeipackageparser import *
from akabeidbwriter import *
from akabeiprogressbar import *
# Try to read the DBPath config line from pacman.conf
# to see if the user set a different value from the default one
def getDatabasePath(pf):
try:
conf = open(pf, "r")
except IOError, err:
print str(err)
print "[!!] This script needs your pacman config file to perform the conversion."
print "[!!] Use " + sys.argv[0] + " -p <path to your pacman.conf> to specify a different configuration file."
sys.exit(-1)
for pacmanLine in conf.readlines():
separatedLine = pacmanLine.partition("=")
optname = separatedLine[0]
# Deletes trailing whitespaces on both sides
optname = optname.lstrip()
optname = optname.rstrip()
if (optname == "DBPath"):
optvalue = separatedLine[2].partition("#")[0] # leaves out comments after the db path
optvalue = optvalue.lstrip()
optvalue = optvalue.rstrip()
conf.close()
return optvalue
conf.close()
return ""
# Each local package is represented in pacman as a directory in the form name-version
# in this path. This directory contains: desc, files (always), install (not always).
# in this path. This directory contains: desc, files (always), install (optional).
def parseLocalDatabase(path):
"""Parses a Pacman local database, found in |path|, and returns the packages
as a list of AkabeiPackage objects."""
desc = ""
install = ""
files = ""
......@@ -113,6 +85,12 @@ def usage():
print " -s, --db-scheme <file> Reads the database scheme from <file> (default: /usr/share/akabei/dbschema.sql)"
def DoConversion(pacmanConf, outputFile, schemeFile):
"""Entry point for converting the pacman db into an akabei one.
Args:
pacmanConf: path to pacman configuration
outputFile: path of the output database.
schemeFile: path of the SQLite scheme file for the Akabei database.
"""
# Gets the database path from the pacman configuration
print "[**] Reading Pacman database path from " + pacmanConf + "...",
dbpath = getDatabasePath(pacmanConf)
......@@ -133,7 +111,7 @@ def DoConversion(pacmanConf, outputFile, schemeFile):
print "[**] Database converted successfully. Now enjoy akabei!"
# Start point
# Start here.
if __name__ == "__main__":
# Default values for files
......
#!/usr/bin/python
# -*- coding: utf8 -*-
# Functionalities common to akabei-db-import and pacman-db-import
#
# Copyright (C) 2016 Lisa Vitolo <shainer@chakralinux.org>
# 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.
def getDatabasePath(pf):
"""Reads the path of the local Pacman database from the configuration.
Args:
pf: path of the configuration file.
Returns:
The path of the database, or an empty string if none was found.
"""
try:
conf = open(pf, "r")
except IOError, err:
print str(err)
print "[!!] This script needs your pacman config file to perform the conversion."
print "[!!] Use " + sys.argv[0] + " -p <path to your pacman.conf> to specify a different configuration file."
sys.exit(-1)
for pacmanLine in conf.readlines():
separatedLine = pacmanLine.partition("=")
optname = separatedLine[0]
# Deletes trailing whitespaces on both sides
optname = optname.lstrip()
optname = optname.rstrip()
if (optname == "DBPath"):
optvalue = separatedLine[2].partition("#")[0] # leaves out comments after the db path
optvalue = optvalue.lstrip()
optvalue = optvalue.rstrip()
conf.close()
return optvalue
conf.close()
return ""
\ 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