From: James Troup Date: Sat, 27 Nov 2004 19:25:59 +0000 (+0000) Subject: 2004-11-27 James Troup * nina: new script to split monolithic... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3052ced859b5fe47e99cf6be80de1926630833a8;p=dak 2004-11-27 James Troup * nina: new script to split monolithic queue/done into date-based hierarchy. --- diff --git a/nina b/nina new file mode 100755 index 00000000..71922122 --- /dev/null +++ b/nina @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +# Copyright (C) 2004 James Troup +# $Id: nina,v 1.1 2004-11-27 19:25:59 troup Exp $ + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +import glob, os, stat, time; +import utils; + +################################################################################ + +def main(): + Cnf = utils.get_conf() + count = 0; + os.chdir(Cnf["Dir::Queue::Done"]) + files = glob.glob("%s/*" % (Cnf["Dir::Queue::Done"])); + for filename in files: + if os.path.isfile(filename): + ctime = time.gmtime(os.stat(filename)[stat.ST_CTIME]); + dirname = time.strftime("%Y/%m/%d", ctime); + if not os.path.exists(dirname): + print "Creating: %s" % (dirname); + os.makedirs(dirname); + dest = dirname + '/' + os.path.basename(filename); + if os.path.exists(dest): + utils.fubar("%s already exists." % (dest)); + print "Move: %s -> %s" % (filename, dest) ; + os.rename(filename, dest); + count = count + 1; + print "Moved %d files." % (count); + +############################################################ + +if __name__ == '__main__': + main()