From 12799a96fcbc221f540ce9954b18e5e95f4e5986 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Sun, 27 Apr 2003 20:23:26 +0000 Subject: [PATCH] (mk_iso): Once all files are backed up, fill the image with the least backed up files. --- mkiso.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mkiso.py b/mkiso.py index 1804a58..61d30f2 100644 --- a/mkiso.py +++ b/mkiso.py @@ -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) -- GitLab