[xiph-cvs] cvs commit: positron/positron/db MDB.py WOID.py
Stan Seibert
volsung at xiph.org
Sun May 25 16:22:34 PDT 2003
volsung 03/05/25 19:22:34
Modified: positron cmd_rebuild.py cmd_sync.py
positron/db MDB.py WOID.py
Log:
Pack the database during sync only if it is needed.
Revision Changes Path
1.3 +2 -0 positron/positron/cmd_rebuild.py
Index: cmd_rebuild.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/cmd_rebuild.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cmd_rebuild.py 25 May 2003 22:30:03 -0000 1.2
+++ cmd_rebuild.py 25 May 2003 23:22:34 -0000 1.3
@@ -120,6 +120,8 @@
record = (basename, hisi_source(track),
neuros.hostpath_to_neurospath(track))
unidedhisi_db.add_record(record)
+ if config.sort_database:
+ unidedhisi_db.sort()
neuros.close_db("unidedhisi")
except neuros_module.Error, e:
<p><p>1.2 +6 -1 positron/positron/cmd_sync.py
Index: cmd_sync.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/cmd_sync.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- cmd_sync.py 22 May 2003 04:42:52 -0000 1.1
+++ cmd_sync.py 25 May 2003 23:22:34 -0000 1.2
@@ -155,6 +155,11 @@
print " %s..." % (basename,)
util.copy_file(sourcename, targetname)
config.add_recording(neuros_trackname.lower())
-
+
+ # Only pack when necessary
+ if audio_db.count_deleted() > 0:
+ print " Packing audio database."
+ audio_db.pack()
+
neuros.close_db("audio")
<p><p>1.3 +27 -1 positron/positron/db/MDB.py
Index: MDB.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/db/MDB.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MDB.py 24 May 2003 21:25:44 -0000 1.2
+++ MDB.py 25 May 2003 23:22:34 -0000 1.3
@@ -233,7 +233,13 @@
if i != self.header["NumOfFieldsPerRecord"]:
raise Error("Incorrect number of fields in record.")
- return (record, to_pointer(f.tell()))
+ # Check if this is the last record
+ current_offset = f.tell()
+ f.seek(0,2)
+ if current_offset != f.tell():
+ return (record, to_pointer(current_offset))
+ else:
+ return (record, None)
def is_record_deleted_at(self, pointer):
f = self.file
@@ -270,6 +276,26 @@
f.seek(-2, 1)
fwrite_word(f, flags)
f.flush()
+
+ def count_deleted(self):
+ "Returns the number of deleted records in this database."
+
+ f = self.file
+ f.seek(0,2)
+ size = f.tell()
+
+ if to_pointer(size) > self.header["RecordStart"]:
+ curr_ptr = self.header["RecordStart"]
+ else:
+ curr_ptr = None
+
+ count = 0
+ while curr_ptr != None:
+ (curr_record, curr_ptr) = self.read_record_at(curr_ptr)
+ if curr_record != None and curr_record["isDeleted"]:
+ count += 1
+
+ return count
def append_record(self, record):
"""Writes a new record to the end of the file.
<p><p>1.3 +4 -0 positron/positron/db/WOID.py
Index: WOID.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/db/WOID.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WOID.py 25 May 2003 22:28:00 -0000 1.2
+++ WOID.py 25 May 2003 23:22:34 -0000 1.3
@@ -322,6 +322,10 @@
# Add required null record
self.sai.append((null_rec_pointer, pai_ptr))
+ def count_deleted(self):
+ "Returns the number of deleted records in this database"
+ return self.mdb.count_deleted()
+
def pack(self, cmpfunc=None):
"""Removes all deleted records in this database and child databases.
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list