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.
24 from daklib.config import Config
25 from daklib.command import CommandError, CommandFile
26 from daklib.daklog import Logger
27 from daklib.fstransactions import FilesystemTransaction
28 from daklib.utils import find_next_free
31 print """Usage: dak process-commands [-d <directory>] [<command-file>...]
40 arguments = [('h', 'help', 'Process-Commands::Options::Help'),
41 ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')]
44 cnf['Process-Commands::Options::Dummy'] = ''
45 filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
46 options = cnf.subtree('Process-Commands::Options')
48 if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options):
52 log = Logger('command')
54 now = datetime.datetime.now()
55 donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d'))
56 rejectdir = cnf['Dir::Reject']
58 if len(filenames) == 0:
59 filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ]
62 basename = os.path.basename(fn)
63 if not fn.endswith('.dak-commands'):
64 log.log(['unexpected filename', basename])
67 command = CommandFile(fn, log)
68 if command.evaluate():
69 log.log(['moving to done', basename])
70 dst = find_next_free(os.path.join(donedir, basename))
72 log.log(['moving to reject', basename])
73 dst = find_next_free(os.path.join(rejectdir, basename))
75 with FilesystemTransaction() as fs:
76 fs.move(fn, dst, mode=0o644)
81 if __name__ == '__main__':