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