Mass Gaffitter
Feb. 5th, 2009 10:38 amI’m very fond of gaffitter, a smart little console program that scans a list of files and/or directories and fumbles through them until it comes up with a subset of that list that will fit in a given space. It’s perfect for taking large directories of stuff and segmenting them into archivable collections.
I recently ran out of disk space on my desktop and realized I had hundreds, nay thousands, of music directories that I needed to put somewhere else. I suppose I could have bought more hard drive space, but more than that I wanted a lot of it just to be put away. I ran gaffitter on the collection with a limit of 4.2 GB, the reliable size of a data DVD, and it said I had about 35 collections worth. Great, I thought, but how to organize the output of gaffitter into subdirectories that I could then burn onto DVDs?
For that, I wrote mass_gaffiter.py. It’s a very simple little script that uses gaffitter’s regular output as its input, and then turns around and spits out another script (a shell script this time) that, for each collection gaffitter has identified, creates a subdirectory and moves everything in that collection into the subdirectory. When it’s done, your cluttered directory is organized into a collection of subdirs named “gaf_disk_01″, “gaf_disk_02″, etc., all ready for growisofs or whatever other DVD burning software you like.
I’m trying to get into the habit of sharing the little utilities in life that I can’t work without. I think of them as little throwaways, but some of them I’ve kept for years, so I figure someone else might have good use of them. Here’s mass_gaffiter.py:
#!/usr/bin/env python
import sys
import re
re_m = re.compile(r'^\[(\d+)\] Sum')
f = open(sys.argv[1], "r")
accum = []
for l in f:
g = re_m.match(l)
if not g:
accum.append(l[:-1])
continue
print 'mkdir gaf_disk_%03d' % int(g.group(1))
print 'mv %s gaf_disk_%03d' % (
' '.join(['"' + i + '"' for i in accum if i]),
int(g.group(1)))
accum = []
This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com
Archives and access
Date: 2009-02-05 06:51 pm (UTC)You had mentioned that you have a large number of these scripts. Do you have an archive or repository that is open for public revue/download?
I am a relative new comer to serious open source and find it is helpful to see what other people (those who know what they are really doing) are implementing on their own systems.
Thanks.
MPK
Re: Archives and access
Date: 2009-02-05 09:03 pm (UTC)http://elfsternberg.com/viewvc/mass_gaffitter/trunk/
no subject
Date: 2009-02-05 06:58 pm (UTC)Would it be better to build the new directories via links so the existing structure is retained?
no subject
Date: 2009-02-05 07:01 pm (UTC)no subject
Date: 2009-02-05 08:51 pm (UTC)no subject
Date: 2009-02-05 08:52 pm (UTC)no subject
Date: 2009-02-05 09:37 pm (UTC)no subject
Date: 2009-02-05 10:20 pm (UTC)