* add a lockeddbshelve module, and use it in installdb
* start implementing a configure-pending command
This commit is contained in:
@@ -31,6 +31,7 @@ def cmdObject(cmd, fail=False):
|
||||
"build-package": BuildPackage,
|
||||
"info": Info,
|
||||
"install": Install,
|
||||
"configure-pending": ConfigurePending,
|
||||
"list-installed": ListInstalled,
|
||||
"list-available": ListAvailable,
|
||||
"search-available": SearchAvailable,
|
||||
@@ -223,6 +224,20 @@ Remove a package from your system. Just give the package name to remove.
|
||||
pisi.toplevel.remove(self.args)
|
||||
self.finalize()
|
||||
|
||||
class ConfigurePending(PackageOp):
|
||||
"""configure pending packages"""
|
||||
def __init__(self):
|
||||
super(Remove, self).__init__()
|
||||
|
||||
def run(self):
|
||||
#if not self.args:
|
||||
# self.help()
|
||||
# return
|
||||
|
||||
self.init()
|
||||
pisi.toplevel.configure_pending()
|
||||
self.finalize()
|
||||
|
||||
class Info(Command):
|
||||
"""Display information about a package
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ install
|
||||
list-installed
|
||||
list-available
|
||||
remove
|
||||
configure-pending
|
||||
add-repo
|
||||
remove-repo
|
||||
list-repo
|
||||
|
||||
+1
-7
@@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
import os, fcntl
|
||||
import bsddb.dbshelve as shelve
|
||||
import lockeddbshelve as shelve
|
||||
|
||||
from config import config
|
||||
from constants import const
|
||||
@@ -33,13 +33,7 @@ class InstallDB:
|
||||
self.db_filename = os.path.join(config.db_dir(), 'install.bdb')
|
||||
self.d = shelve.open(self.db_filename)
|
||||
self.files_dir = os.path.join(config.db_dir(), 'files')
|
||||
self.fdummy = open(self.db_filename)
|
||||
fcntl.flock(self.fdummy, fcntl.LOCK_EX)
|
||||
|
||||
def __del__(self):
|
||||
#fcntl.flock(self.fdummy, fcntl.LOCK_UN)
|
||||
self.fdummy.close()
|
||||
|
||||
def files_name(self, pkg, version, release):
|
||||
from os.path import join
|
||||
pkg_dir = join(config.lib_dir(), pkg + '-' + version + '-' + release)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2005, TUBITAK/UEKAE
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Please read the COPYING file.
|
||||
#
|
||||
# A simple wrapper to implement locking for bsddb's dbshelf
|
||||
|
||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||
|
||||
|
||||
import bsddb.dbshelve as shelve
|
||||
import bsddb.db as db
|
||||
import fcntl
|
||||
|
||||
def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH,
|
||||
dbenv=None, dbname=None):
|
||||
"""
|
||||
A simple factory function for compatibility with the standard
|
||||
shleve.py module. It can be used like this, where key is a string
|
||||
and data is a pickleable object:
|
||||
|
||||
from bsddb import dbshelve
|
||||
db = dbshelve.open(filename)
|
||||
|
||||
db[key] = data
|
||||
|
||||
db.close()
|
||||
"""
|
||||
if type(flags) == type(''):
|
||||
sflag = flags
|
||||
if sflag == 'r':
|
||||
flags = db.DB_RDONLY
|
||||
elif sflag == 'rw':
|
||||
flags = 0
|
||||
elif sflag == 'w':
|
||||
flags = db.DB_CREATE
|
||||
elif sflag == 'c':
|
||||
flags = db.DB_CREATE
|
||||
elif sflag == 'n':
|
||||
flags = db.DB_TRUNCATE | db.DB_CREATE
|
||||
else:
|
||||
raise error, "flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags"
|
||||
|
||||
d = LockedDBShelf(dbenv)
|
||||
d.open(filename, dbname, filetype, flags, mode)
|
||||
return d
|
||||
|
||||
class LockedDBShelf(shelve.DBShelf):
|
||||
|
||||
def __init__(self, env = None):
|
||||
shelve.DBShelf.__init__(self, env)
|
||||
|
||||
def open(self, filename, dbname, filetype, flags, mode):
|
||||
self.lockfile = file(filename + '.lock', 'w')
|
||||
try:
|
||||
fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except IOError:
|
||||
import sys
|
||||
from ui import ui
|
||||
ui.error("Another instance of PISI is running. Try later!\n")
|
||||
sys.exit(1)
|
||||
return self.db.open(filename, dbname, filetype, flags, mode)
|
||||
|
||||
def close(self):
|
||||
self.db.close()
|
||||
self.lockfile.close()
|
||||
|
||||
+8
-4
@@ -37,10 +37,9 @@ class PackageDB(object):
|
||||
util.check_dir(config.db_dir())
|
||||
self.fname = os.path.join(config.db_dir(), 'package-%s.bdb' % id )
|
||||
self.fname2 = os.path.join(config.db_dir(), 'revdep-%s.bdb' % id )
|
||||
self.lockfile = self.fname + '.lock'
|
||||
self.fdummy = file(self.lockfile, 'w')
|
||||
self.lockfile = file(self.fname + '.lock', 'w')
|
||||
try:
|
||||
fcntl.flock(self.fdummy, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except IOError:
|
||||
import sys
|
||||
from ui import ui
|
||||
@@ -48,7 +47,12 @@ class PackageDB(object):
|
||||
sys.exit(1)
|
||||
self.d = shelve.open(self.fname)
|
||||
self.dr = shelve.open(self.fname2)
|
||||
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
#self.d.close()
|
||||
#self.dr.close()
|
||||
#self.lockfile.close()
|
||||
|
||||
def has_package(self, name):
|
||||
name = str(name)
|
||||
|
||||
Reference in New Issue
Block a user