Commit 966a395e authored by Lisa's avatar Lisa

Initial, incomplete implementation of pacman-db-import.

This is meant to do the opposite job as akabei-db-import. The
use case is somebody that is using akabei, but needs to go
back to pacman for some reason (i.e. early bug).

Missing features: progress bar, and writing the data on the pacman
local database.

Added new parser classes for parsing the akabei local.db data.
parent e899be6b
......@@ -75,7 +75,7 @@ class AkabeiPackage(object):
def addLicense(self, license):
def addFile(self, filename, backup):
def addFile(self, filename, backup=""):
f = AkabeiFile(filename, backup)
......@@ -157,4 +157,83 @@ class PacmanPackageParser:
if self.install != None:
if self.files != None:
\ No newline at end of file
class AkabeiPackageParser(object):
def __init__(self, dbConnection, packageRow):
self._dbConnection = dbConnection
self._packageRow = packageRow
self._package = None
def _parseVersion(self, version, epoch):
if epoch > 0:
return "%d:%s" % (epoch, version)
return version
def parsePackage(self):
packageId = self._packageRow[0]
self._package = AkabeiPackage() = str(self._packageRow[1])
self._package.version = self._parseVersion(self._packageRow[2], self._packageRow[3])
self._package.filename = str(self._packageRow[4])
self._package.description = self._packageRow[5]
self._package.size = self._packageRow[6]
self._package.installedsize = self._packageRow[7]
self._package.md5sum = str(self._packageRow[8])
self._package.url = str(self._packageRow[9])
self._package.builddate = self._packageRow[10]
self._package.arch = str(self._packageRow[11])
self._package.packager = self._packageRow[12]
self._package.flags = str(self._packageRow[13])
self._package.screenshoturl = str(self._packageRow[14])
self._package.installedreason = self._packageRow[15]
self._package.installdate = self._packageRow[16]
scriptQuery = 'SELECT * FROM scriptlets WHERE package=%d' % packageId
depsQuery = 'SELECT * FROM depends WHERE package=%d' % packageId
conflictsQuery = 'SELECT * FROM conflicts WHERE package=%d' % packageId
providesQuery = 'SELECT * FROM provides WHERE package=%d' % packageId
optionalQuery = 'SELECT * FROM optional WHERE package=%d' % packageId
replacesQuery = 'SELECT * FROM replaces WHERE package=%d' % packageId
mimetypesQuery = 'SELECT * FROM providesmimetype WHERE package=%d' % packageId
groupsQuery = 'SELECT * FROM belongsgroup WHERE package=%d' % packageId
filesQuery = 'SELECT * FROM files WHERE package=%d' % packageId
licenseQuery = 'SELECT * FROM licensed WHERE package=%d' % packageId
for script in self._dbConnection.execute(scriptQuery):
for dep in self._dbConnection.execute(depsQuery):
for conflict in self._dbConnection.execute(conflictsQuery):
for provide in self._dbConnection.execute(providesQuery):
for optdep in self._dbConnection.execute(optionalQuery):
for replace in self._dbConnection.execute(replacesQuery):
for mimetype in self._dbConnection.execute(mimetypesQuery):
for group in self._dbConnection.execute(groupsQuery):
for f in self._dbConnection.execute(filesQuery):
for license in self._dbConnection.execute(licenseQuery):
return True
def getPackage(self):
return self._package
# -*- coding: utf8 -*-
# A script to convert the Akabei local database into a Pacman one
# Copyright (C) 2016 Lisa Vitolo <>
# 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.
import getopt
import sys
import os
import sqlite3
from akabeipackageparser import AkabeiPackageParser
from db_import import *
def parseLocalDatabase(akabeiDb, schemeFile):
c = sqlite3.connect(akabeiDb)
packages = []
# TODO: use progress bar here.
for row in c.execute('SELECT * FROM packages;'):
akabeiParser = AkabeiPackageParser(c, row)
if not akabeiParser.parsePackage():
print '[!!] Invalid package, skipping.'
return packages
def DoConversion(pacmanConf, inputFile, schemeFile):
# Gets the database path from the pacman configuration
print "[**] Reading Pacman database path from " + pacmanConf + "...",
dbpath = getDatabasePath(pacmanConf)
print "done."
if len(dbpath) == 0:
dbpath = "/var/lib/pacman" # if not explicitly set there, then go back to the default value
pacmanLocalPath = os.path.join(dbpath, "local")
# Get local packages from akabei, then write them into the pacman "database" in the right format
print "[**] Parsing Akabei local database..."
localPackages = parseLocalDatabase(inputFile, schemeFile)
print "done."
#dbwriter = PacmanDbWriter(outputFile, schemeFile)
print "[**] Database converted successfully. Hope to see you again soon!"
# Entry point.
# TODO: needs more extensive testing.
if __name__ == "__main__":
# Default values for files
pacmanConf = "/etc/pacman.conf"
inputFile = "local.db"
schemeFile = "/usr/share/akabei/dbschema.sql"
opts = None
# Reads options from command line.
opts = getopt.getopt(sys.argv[1:], "hp:i:s:", ["help", "--pacman=" "--db-input=", "--db-scheme="])
except getopt.GetoptError, error:
print str(error)
# Parse options and overrides defaults if needed.
for opt, arg in opts[0]:
if len(arg) > 0 and arg[0] == '=':
arg = arg[1:]
if opt in ("-h", "--help"):
elif opt in ("-p", "--pacman"):
pacmanConf = arg
elif opt in ("-i", "--db-input"):
inputFile = arg
elif opt in ("-s", "--db-scheme"):
schemeFile = arg
print "==== Akabei database conversion script v0.1 ==== "
print "This script may take some time to finish."
DoConversion(pacmanConf, inputFile, schemeFile)
\ 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