Kaydet (Commit) 1865d351 authored tarafından Eray Özkural's avatar Eray Özkural

* 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
üst 6eff1490
......@@ -299,7 +299,7 @@ def index(dirs, output = 'pisi-index.xml', skip_sources=False):
for repo_dir in dirs:
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
index.index(repo_dir, skip_sources)
index.write(output)
index.write(output, sha1sum=True)
ctx.ui.info(_('* Index file written'))
def add_repo(name, indexuri):
......@@ -336,11 +336,11 @@ def rebuild_db(files=False):
def destroy(files):
#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...
import bsddb3.db
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'):
clean = files
else:
......@@ -349,9 +349,9 @@ def rebuild_db(files=False):
fn = pisi.util.join_path(ctx.config.db_dir(), db)
#FIXME: there is a bug with bsddb3
#ctx.dbenv.dbremove(fn, "", None, bsddb3.db.DB_AUTO_COMMIT)
# ctx.dbenv.dbremove(file=fn, flags=bsddb3.db.DB_AUTO_COMMIT)
os.unlink(fn)
#ctx.dbenv.close()
ctx.dbenv.dbremove(file=fn, flags=bsddb3.db.DB_AUTO_COMMIT)
#os.unlink(fn)
ctx.dbenv.close()
def reload(files, txn):
for package_fn in os.listdir( pisi.util.join_path( ctx.config.lib_dir(),
......
......@@ -35,7 +35,9 @@ class Error(pisi.Error):
pass
class File:
(read, write) = range(2) # modes
(xmill, sevenzip) = range(2) # compress enums
@staticmethod
def make_uri(uri):
......@@ -47,7 +49,8 @@ class File:
return uri
@staticmethod
def download(uri, transfer_dir = "/tmp"):
def download(uri, transfer_dir = "/tmp",
sha1sum = False, compress = None, sign = None):
assert type(uri == URI)
if uri.is_remote_file():
ctx.ui.info(_("Fetching %s") % uri.get_uri())
......@@ -57,8 +60,10 @@ class File:
localfile = uri.get_uri() #TODO: use a special function here?
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"
self.sha1sum = sha1sum
uri = File.make_uri(uri)
if mode==File.read or mode==File.write:
self.mode = mode
......@@ -79,6 +84,7 @@ class File:
else:
access = 'w'
self.__file__ = file(localfile, access)
self.localfile = localfile
def local_file(self):
"returns the underlying file object"
......@@ -87,6 +93,12 @@ class File:
def close(self, delete_transfer = False):
"this method must be called at the end of operation"
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):
self.__file__.flush()
......
......@@ -136,3 +136,4 @@ class Index(XmlFile):
else: # create relative path by default
sf.source.sourceURI = util.removepathprefix(repo_uri, path)
self.specs.append(sf)
......@@ -428,9 +428,10 @@ class autoxml(oo.autosuper, oo.autoprop):
cls.__ne__ = notequal
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"
self.readxml(uri, tmpDir)
self.readxml(uri, tmpDir, sha1sum=sha1sum, compress=compress)
errs = []
self.decode(self.rootNode(), errs)
if hasattr(self, 'read_hook'):
......@@ -447,7 +448,8 @@ class autoxml(oo.autosuper, oo.autoprop):
errs.append(_("autoxml.read: File '%s' has errors") % uri)
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"
errs = self.errors()
if errs:
......@@ -461,7 +463,7 @@ class autoxml(oo.autosuper, oo.autoprop):
if errs:
errs.append(_("autoxml.write: File encoding '%s' has errors") % uri)
raise Error(*errs)
self.writexml(uri, tmpDir)
self.writexml(uri, tmpDir, sha1sum=sha1sum, compress=compress)
if not keepDoc:
self.unlink() # get rid of the tree
......
......@@ -67,9 +67,9 @@ class XmlFile(object):
"""returns root document element"""
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)
localpath = File.download(uri, tmpDir)
localpath = File.download(uri, tmpDir,sha1sum=sha1sum,compress=compress)
try:
self.doc = NoExtDtdReader.parseUri(Ft.Lib.Uri.OsPathToUri(localpath))
return self.doc.documentElement
......@@ -78,8 +78,8 @@ class XmlFile(object):
except exceptions.ValueError, e:
raise Error(_("File '%s' not found") % localpath )
def writexml(self, uri, tmpDir = '/tmp'):
f = file(uri, 'w')
def writexml(self, uri, tmpDir = '/tmp', sha1sum=False, compress=None):
f = File(uri, File.write, sha1sum=sha1sum, compress=compress)
PrettyPrint(self.rootNode(), stream = f)
f.close()
......
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