Skip to content
Snippets Groups Projects
Commit 12799a96 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(mk_iso): Once all files are backed up, fill the image

	with the least backed up files.
parent 435b7fc6
No related branches found
No related tags found
No related merge requests found
......@@ -102,17 +102,52 @@ def mk_iso(DBH):
files = []
acc = 0
nr_files = 0
exhausted = None
others_min = 0
others_max = 0
# Fetch more files until we fill the CD (ignoring the filesystem overhead).
while acc <= capacity * 2048:
rows = cursor.fetchmany()
if len(rows) == 0:
exhausted = nr_files
break
files += rows
while acc <= capacity * 2048 and nr_files < len(files):
acc += files[nr_files][3]
nr_files += 1
if exhausted == None:
exhausted = 0
else:
# Fill the media with redundant copies of already backed up files.
cursor.execute("SELECT file.file_id, file.filename, file.dir_id,"
" file.size, file.md5sum, file.sha1sum,"
" count(contents.media) AS cnt"
" FROM file, contents, media"
" WHERE file.file_id = contents.file"
" AND contents.media = media.media_id"
" AND media.broken = 0"
" GROUP BY file.file_id"
" ORDER BY cnt, RAND()")
while acc <= capacity * 2048:
rows = cursor.fetchmany()
if len(rows) == 0:
break
# Store the smallest and largest cnt field.
if others_min == 0:
others_min = rows[0][-1]
others_max = rows[0][-1]
others_max = max(others_max, rows[0][-1])
# Forget the "cnt" field.
for r in rows:
files.append(r[:6])
while acc <= capacity * 2048 and nr_files < len(files):
acc += files[nr_files][3]
nr_files += 1
# Discard more and more files until we have something that fits (not
# ignoring the overhead).
backtrack = 4
......@@ -139,6 +174,10 @@ def mk_iso(DBH):
# it is hardly worth the effort.
used = iso_size(bases, files[:min_files], media_id)
print "Storing %d files. Margin: %d" % (min_files, capacity - used)
if exhausted < min_files:
print "%d of the files are already stored on %d-%d CDs." % (
(min_files - exhausted), others_min, others_max)
raw_input("[CONFIRM]")
run_mkisofs(bases, files[:min_files], media_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment