]> git.decadent.org.uk Git - dak.git/blob - dak/split_done.py
Done isn't a queue either
[dak.git] / dak / split_done.py
1 #!/usr/bin/env python
2
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>
6
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.
11
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.
16
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
20
21 ################################################################################
22
23 import glob, os, stat, time
24 from daklib import utils
25
26 ################################################################################
27
28 def main():
29     Cnf = utils.get_conf()
30     count = 0
31     move_date = int(time.time())
32     os.chdir(Cnf["Dir::Done"])
33     files = glob.glob("%s/*" % (Cnf["Dir::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:
38                 continue
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)
43                 os.makedirs(dirname)
44             dest = dirname + '/' + os.path.basename(filename)
45             if os.path.exists(dest):
46                 utils.warn("%s already exists." % (dest))
47                 continue
48             print "Move: %s -> %s" % (filename, dest)
49             os.rename(filename, dest)
50             count = count + 1
51     print "Moved %d files." % (count)
52
53 ############################################################
54
55 if __name__ == '__main__':
56     main()