Commit 0ea3b5a2 authored by AlmAck's avatar AlmAck

Merge branch 'master' of ssh://git.chakralinux.org:/akabei

parents 705675b1 966a395e
......@@ -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
......
......@@ -75,7 +75,7 @@ class AkabeiPackage(object):
def addLicense(self, license):
self.licenses.append(license)
def addFile(self, filename, backup):
def addFile(self, filename, backup=""):
f = AkabeiFile(filename, backup)
self.files.append(f)
......
......@@ -157,4 +157,83 @@ class PacmanPackageParser:
if self.install != None:
self.install.close()
if self.files != None:
self.files.close()
\ No newline at end of file
self.files.close()
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()
self._package.name = 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):
self._package.addScriptlet(str(script[2]))
for dep in self._dbConnection.execute(depsQuery):
self._package.addDependency(str(dep[2]))
for conflict in self._dbConnection.execute(conflictsQuery):
self._package.addConflict(str(conflict[2]))
for provide in self._dbConnection.execute(providesQuery):
self._package.addProvide(str(provide[2]))
for optdep in self._dbConnection.execute(optionalQuery):
self._package.addOptional(str(optdep[2]))
for replace in self._dbConnection.execute(replacesQuery):
self._package.addReplace(str(replace[2]))
for mimetype in self._dbConnection.execute(mimetypesQuery):
self._package.addMimeType(str(mimetype[2]))
for group in self._dbConnection.execute(groupsQuery):
self._package.addGroup(str(group[1]))
for f in self._dbConnection.execute(filesQuery):
self._package.addFile(str(f[2]))
for license in self._dbConnection.execute(licenseQuery):
self._package.addLicense(str(license[1]))
return True
def getPackage(self):
return self._package
#!/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
#!/usr/bin/python
# -*- coding: utf8 -*-
# A script to convert the Akabei local database into a Pacman one
#
# 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.
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.'
continue
packages.append(akabeiParser.getPackage())
print(akabeiParser.getPackage())
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."
# TODO
#dbwriter = PacmanDbWriter(outputFile, schemeFile)
#dbwriter.addPackages(localPackages)
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.
try:
opts = getopt.getopt(sys.argv[1:], "hp:i:s:", ["help", "--pacman=" "--db-input=", "--db-scheme="])
except getopt.GetoptError, error:
print str(error)
usage()
sys.exit(-1)
# 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"):
usage()
sys.exit(0)
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."
print
DoConversion(pacmanConf, inputFile, schemeFile)
\ No newline at end of file
......@@ -21,18 +21,11 @@ except ImportError:
print "[!!] You need to install the python-pysqlite package to execute this script. Quitting..."
sys.exit(-1)
# Concatenate two paths (relative or non) safely
def concatenatePaths(path1, path2):
if (path1[-1] != '/'):
path1 += "/"
path1 += path2
return path1
# Reads the package name directly from the main information file
# This is much safer than obtaining it from the directory name for cause of
# inconsistencies in version specifications
def getPackageName(pkgDir):
descFile = open(concatenatePaths(pkgDir, "desc"), "r")
descFile = open(os.path.join(pkgDir, "desc"), "r")
isName = False
for line in descFile.readlines():
......@@ -68,7 +61,10 @@ def compareDatabases(pacmanDb, akabeiDb):
# Takes every package in the pacman database directory and looks for it in the akabei database
for pkgDir in os.listdir(pacmanDb):
pkgname = getPackageName(concatenatePaths(pacmanDb, pkgDir))
if not os.path.isdir(pkgDir):
continue
pkgname = getPackageName(os.path.join(pacmanDb, pkgDir))
query = "SELECT * FROM packages WHERE name='" + pkgname + "'"
dbcursor.execute(query)
......@@ -153,4 +149,4 @@ if __name__ == "__main__":
if len(diff) > 0:
print "[!!] Package " + diff + " was found in pacman db but not in akabei db"
else:
print "[**] Test passed."
\ No newline at end of file
print "[**] Test passed."
......@@ -311,7 +311,7 @@ void SyncOperation::listRepo(const QString &repo)
break;
}
}
if (!db || !db->database()) {
if (!db || !db->isValid()) {
QTextStream err(stderr);
err << Akabei::errorPrefix << QObject::tr("No repository found!") << endl;
nextOperation();
......
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