3 # Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
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.
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.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 from daklib.config import Config
26 from daklib.command import CommandError, CommandFile
27 from daklib.daklog import Logger
28 from daklib.fstransactions import FilesystemTransaction
29 from daklib.gpg import GpgException
30 from daklib.utils import find_next_free
33 print """Usage: dak process-commands [-d <directory>] [<command-file>...]
42 arguments = [('h', 'help', 'Process-Commands::Options::Help'),
43 ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')]
46 cnf['Process-Commands::Options::Dummy'] = ''
47 filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
48 options = cnf.subtree('Process-Commands::Options')
50 if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options):
54 log = Logger('command')
56 now = datetime.datetime.now()
57 donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d'))
58 rejectdir = cnf['Dir::Reject']
60 if len(filenames) == 0:
61 filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ]
64 basename = os.path.basename(fn)
65 if not fn.endswith('.dak-commands'):
66 log.log(['unexpected filename', basename])
69 with open(fn, 'r') as fh:
73 command = CommandFile(basename, data, log)
76 created = os.stat(fn).st_mtime
78 too_new = (now - created < int(cnf.get('Dinstall::SkipTime', '60')))
80 log.log(['skipped (too new)'])
82 log.log(['reject', basename])
83 dst = find_next_free(os.path.join(rejectdir, basename))
85 log.log(['done', basename])
86 dst = find_next_free(os.path.join(donedir, basename))
88 with FilesystemTransaction() as fs:
90 fs.create(dst, mode=0o644).write(data)
95 if __name__ == '__main__':