elfs: (Default)
[personal profile] elfs

I’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)
From: [identity profile] pandakahn.livejournal.com
Nice script.

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)
From: [identity profile] elfs.livejournal.com
Excellent suggestion!

http://elfsternberg.com/viewvc/mass_gaffitter/trunk/

Date: 2009-02-05 06:58 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
(Disclaimer: not tried it and don't know Python properly yet so it may well already be doing this!)

Would it be better to build the new directories via links so the existing structure is retained?

Date: 2009-02-05 07:01 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
One of the links on ElfSternberg.com shows what's wrong with some projects - you go to Python Paste and there is no clue as to what it actually does!

Date: 2009-02-05 08:51 pm (UTC)
From: [identity profile] elfs.livejournal.com
Paste is one of those projects that, you either know that you need it, or you don't need to know anything about it. It's an application server based on the pre-ORM model, with a lot of plug-ins "pasted together."

Date: 2009-02-05 08:52 pm (UTC)
From: [identity profile] elfs.livejournal.com
Probably, but I just needed a quick directory structure assembled for burning, and this was my quick-and-dirty solution. The fact that I've used this "dirty" solution reliably for the past three years tells me that it does something essential.

Date: 2009-02-05 09:37 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
So these are files you don't really need on the hard drive and are just making a copy before you delete them?

Date: 2009-02-05 10:20 pm (UTC)
From: [identity profile] elfs.livejournal.com
Yeah, or backing up what you've got. Given that my directories are already huge dumping pools, undoing this is a simple matter of mv gaf_drive_*/* .

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 26th, 2026 11:16 pm
Powered by Dreamwidth Studios