3 """ Split queue/done into date based subdirectories """
4 # Copyright (C) 2004, 2005, 2006 James Troup <james@nocrew.org>
5 # Copyright (C) 2008 Joerg Jaspert <joerg@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
23 import glob, os, stat, time
24 from daklib import utils
26 ################################################################################
29 Cnf = utils.get_conf()
31 move_date = int(time.time())-(30*84600)
32 os.chdir(Cnf["Dir::Queue::Done"])
33 files = glob.glob("%s/*" % (Cnf["Dir::Queue::Done"]))
34 for filename in files:
35 if os.path.isfile(filename):
36 filemtime = os.stat(filename)[stat.ST_MTIME]
37 if filemtime > move_date:
39 mtime = time.gmtime(filemtime)
40 dirname = time.strftime("%Y/%m/%d", mtime)
41 if not os.path.exists(dirname):
42 print "Creating: %s" % (dirname)
44 dest = dirname + '/' + os.path.basename(filename)
45 if os.path.exists(dest):
46 utils.fubar("%s already exists." % (dest))
47 print "Move: %s -> %s" % (filename, dest)
48 os.rename(filename, dest)
50 print "Moved %d files." % (count)
52 ############################################################
54 if __name__ == '__main__':