* fix: use dbenv.dbremove to play well with bsddb.
let's not delete files like barbarians :) * add sha1sum creation support to file ops, and endow index creation with this property, also start coding other index enhancements
This commit is contained in:
+6
-6
@@ -299,7 +299,7 @@ def index(dirs, output = 'pisi-index.xml', skip_sources=False):
|
|||||||
for repo_dir in dirs:
|
for repo_dir in dirs:
|
||||||
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
||||||
index.index(repo_dir, skip_sources)
|
index.index(repo_dir, skip_sources)
|
||||||
index.write(output)
|
index.write(output, sha1sum=True)
|
||||||
ctx.ui.info(_('* Index file written'))
|
ctx.ui.info(_('* Index file written'))
|
||||||
|
|
||||||
def add_repo(name, indexuri):
|
def add_repo(name, indexuri):
|
||||||
@@ -336,11 +336,11 @@ def rebuild_db(files=False):
|
|||||||
|
|
||||||
def destroy(files):
|
def destroy(files):
|
||||||
#from pisi.lockeddbshelve import LockedDBShelf
|
#from pisi.lockeddbshelve import LockedDBShelf
|
||||||
#pisi.lockeddbshelve.init_dbenv(write=True)
|
pisi.lockeddbshelve.init_dbenv(write=True)
|
||||||
#TODO: either don't delete version files here, or remove force flag...
|
#TODO: either don't delete version files here, or remove force flag...
|
||||||
import bsddb3.db
|
import bsddb3.db
|
||||||
for db in os.listdir(ctx.config.db_dir()):
|
for db in os.listdir(ctx.config.db_dir()):
|
||||||
if db.endswith('.bdb') or db.startswith('log'): # delete only db files
|
if db.endswith('.bdb'):# or db.startswith('log'): # delete only db files
|
||||||
if db.startswith('files') or db.startswith('filesdbversion'):
|
if db.startswith('files') or db.startswith('filesdbversion'):
|
||||||
clean = files
|
clean = files
|
||||||
else:
|
else:
|
||||||
@@ -349,9 +349,9 @@ def rebuild_db(files=False):
|
|||||||
fn = pisi.util.join_path(ctx.config.db_dir(), db)
|
fn = pisi.util.join_path(ctx.config.db_dir(), db)
|
||||||
#FIXME: there is a bug with bsddb3
|
#FIXME: there is a bug with bsddb3
|
||||||
#ctx.dbenv.dbremove(fn, "", None, bsddb3.db.DB_AUTO_COMMIT)
|
#ctx.dbenv.dbremove(fn, "", None, bsddb3.db.DB_AUTO_COMMIT)
|
||||||
# ctx.dbenv.dbremove(file=fn, flags=bsddb3.db.DB_AUTO_COMMIT)
|
ctx.dbenv.dbremove(file=fn, flags=bsddb3.db.DB_AUTO_COMMIT)
|
||||||
os.unlink(fn)
|
#os.unlink(fn)
|
||||||
#ctx.dbenv.close()
|
ctx.dbenv.close()
|
||||||
|
|
||||||
def reload(files, txn):
|
def reload(files, txn):
|
||||||
for package_fn in os.listdir( pisi.util.join_path( ctx.config.lib_dir(),
|
for package_fn in os.listdir( pisi.util.join_path( ctx.config.lib_dir(),
|
||||||
|
|||||||
+14
-2
@@ -35,7 +35,9 @@ class Error(pisi.Error):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class File:
|
class File:
|
||||||
|
|
||||||
(read, write) = range(2) # modes
|
(read, write) = range(2) # modes
|
||||||
|
(xmill, sevenzip) = range(2) # compress enums
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_uri(uri):
|
def make_uri(uri):
|
||||||
@@ -47,7 +49,8 @@ class File:
|
|||||||
return uri
|
return uri
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download(uri, transfer_dir = "/tmp"):
|
def download(uri, transfer_dir = "/tmp",
|
||||||
|
sha1sum = False, compress = None, sign = None):
|
||||||
assert type(uri == URI)
|
assert type(uri == URI)
|
||||||
if uri.is_remote_file():
|
if uri.is_remote_file():
|
||||||
ctx.ui.info(_("Fetching %s") % uri.get_uri())
|
ctx.ui.info(_("Fetching %s") % uri.get_uri())
|
||||||
@@ -57,8 +60,10 @@ class File:
|
|||||||
localfile = uri.get_uri() #TODO: use a special function here?
|
localfile = uri.get_uri() #TODO: use a special function here?
|
||||||
return localfile
|
return localfile
|
||||||
|
|
||||||
def __init__(self, uri, mode, transfer_dir = "/tmp"):
|
def __init__(self, uri, mode, transfer_dir = "/tmp",
|
||||||
|
sha1sum = False, compress = None, sign = None):
|
||||||
"it is pointless to open a file without a URI and a mode"
|
"it is pointless to open a file without a URI and a mode"
|
||||||
|
self.sha1sum = sha1sum
|
||||||
uri = File.make_uri(uri)
|
uri = File.make_uri(uri)
|
||||||
if mode==File.read or mode==File.write:
|
if mode==File.read or mode==File.write:
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
@@ -79,6 +84,7 @@ class File:
|
|||||||
else:
|
else:
|
||||||
access = 'w'
|
access = 'w'
|
||||||
self.__file__ = file(localfile, access)
|
self.__file__ = file(localfile, access)
|
||||||
|
self.localfile = localfile
|
||||||
|
|
||||||
def local_file(self):
|
def local_file(self):
|
||||||
"returns the underlying file object"
|
"returns the underlying file object"
|
||||||
@@ -87,6 +93,12 @@ class File:
|
|||||||
def close(self, delete_transfer = False):
|
def close(self, delete_transfer = False):
|
||||||
"this method must be called at the end of operation"
|
"this method must be called at the end of operation"
|
||||||
self.__file__.close()
|
self.__file__.close()
|
||||||
|
if self.mode == File.write:
|
||||||
|
if self.sha1sum:
|
||||||
|
sha1 = pisi.util.sha1_file(self.localfile)
|
||||||
|
cs = file(self.localfile + '.sha1sum', 'w')
|
||||||
|
cs.write(sha1)
|
||||||
|
cs.close()
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.__file__.flush()
|
self.__file__.flush()
|
||||||
|
|||||||
@@ -136,3 +136,4 @@ class Index(XmlFile):
|
|||||||
else: # create relative path by default
|
else: # create relative path by default
|
||||||
sf.source.sourceURI = util.removepathprefix(repo_uri, path)
|
sf.source.sourceURI = util.removepathprefix(repo_uri, path)
|
||||||
self.specs.append(sf)
|
self.specs.append(sf)
|
||||||
|
|
||||||
|
|||||||
@@ -428,9 +428,10 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
cls.__ne__ = notequal
|
cls.__ne__ = notequal
|
||||||
|
|
||||||
if xmlfile_support:
|
if xmlfile_support:
|
||||||
def read(self, uri, keepDoc = False, tmpDir = '/tmp'):
|
def read(self, uri, keepDoc = False, tmpDir = '/tmp',
|
||||||
|
sha1sum = False, compress = None):
|
||||||
"read XML file and decode it into a python object"
|
"read XML file and decode it into a python object"
|
||||||
self.readxml(uri, tmpDir)
|
self.readxml(uri, tmpDir, sha1sum=sha1sum, compress=compress)
|
||||||
errs = []
|
errs = []
|
||||||
self.decode(self.rootNode(), errs)
|
self.decode(self.rootNode(), errs)
|
||||||
if hasattr(self, 'read_hook'):
|
if hasattr(self, 'read_hook'):
|
||||||
@@ -447,7 +448,8 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
errs.append(_("autoxml.read: File '%s' has errors") % uri)
|
errs.append(_("autoxml.read: File '%s' has errors") % uri)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
|
|
||||||
def write(self, uri, keepDoc = False, tmpDir = '/tmp'):
|
def write(self, uri, keepDoc = False, tmpDir = '/tmp',
|
||||||
|
sha1sum = False, compress = None):
|
||||||
"encode the contents of the python object into an XML file"
|
"encode the contents of the python object into an XML file"
|
||||||
errs = self.errors()
|
errs = self.errors()
|
||||||
if errs:
|
if errs:
|
||||||
@@ -461,7 +463,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
if errs:
|
if errs:
|
||||||
errs.append(_("autoxml.write: File encoding '%s' has errors") % uri)
|
errs.append(_("autoxml.write: File encoding '%s' has errors") % uri)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
self.writexml(uri, tmpDir)
|
self.writexml(uri, tmpDir, sha1sum=sha1sum, compress=compress)
|
||||||
if not keepDoc:
|
if not keepDoc:
|
||||||
self.unlink() # get rid of the tree
|
self.unlink() # get rid of the tree
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ class XmlFile(object):
|
|||||||
"""returns root document element"""
|
"""returns root document element"""
|
||||||
return self.doc.documentElement
|
return self.doc.documentElement
|
||||||
|
|
||||||
def readxml(self, uri, tmpDir = '/tmp'):
|
def readxml(self, uri, tmpDir = '/tmp', sha1sum=False, compress=None):
|
||||||
uri = File.make_uri(uri)
|
uri = File.make_uri(uri)
|
||||||
localpath = File.download(uri, tmpDir)
|
localpath = File.download(uri, tmpDir,sha1sum=sha1sum,compress=compress)
|
||||||
try:
|
try:
|
||||||
self.doc = NoExtDtdReader.parseUri(Ft.Lib.Uri.OsPathToUri(localpath))
|
self.doc = NoExtDtdReader.parseUri(Ft.Lib.Uri.OsPathToUri(localpath))
|
||||||
return self.doc.documentElement
|
return self.doc.documentElement
|
||||||
@@ -78,8 +78,8 @@ class XmlFile(object):
|
|||||||
except exceptions.ValueError, e:
|
except exceptions.ValueError, e:
|
||||||
raise Error(_("File '%s' not found") % localpath )
|
raise Error(_("File '%s' not found") % localpath )
|
||||||
|
|
||||||
def writexml(self, uri, tmpDir = '/tmp'):
|
def writexml(self, uri, tmpDir = '/tmp', sha1sum=False, compress=None):
|
||||||
f = file(uri, 'w')
|
f = File(uri, File.write, sha1sum=sha1sum, compress=compress)
|
||||||
PrettyPrint(self.rootNode(), stream = f)
|
PrettyPrint(self.rootNode(), stream = f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user