diff --git a/mkiso.py b/mkiso.py index 1804a5861e19e2808c0906a3ef7e2172d2086473..61d30f2640b50008f3459d697c43678986998bbd 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)