From: Ansgar Burchardt Date: Wed, 19 Sep 2012 10:44:17 +0000 (+0200) Subject: Rename process-commands.py to process_commands.py. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=44ad10099864ca7a124f7baab6524ec10ec88e54;p=dak.git Rename process-commands.py to process_commands.py. --- diff --git a/dak/process-commands.py b/dak/process-commands.py deleted file mode 100644 index 9bc2d3f1..00000000 --- a/dak/process-commands.py +++ /dev/null @@ -1,82 +0,0 @@ -#! /usr/bin/env python -# -# Copyright (C) 2012, Ansgar Burchardt -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -import apt_pkg -import datetime -import os -import sys - -from daklib.config import Config -from daklib.command import CommandError, CommandFile -from daklib.daklog import Logger -from daklib.fstransactions import FilesystemTransaction -from daklib.utils import find_next_free - -def usage(): - print """Usage: dak command ... - -process command files -""" - -def main(argv=None): - if argv is None: - argv = sys.argv - - arguments = [('h', 'help', 'Process-Commands::Options::Help'), - ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')] - - cnf = Config() - cnf['Command::Options::Dummy'] = '' - filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) - options = cnf.subtree('Command::Options') - - if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options): - usage() - sys.exit(0) - - log = Logger('command') - - now = datetime.datetime.now() - donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d')) - rejectdir = cnf['Dir::Reject'] - - if len(filenames) == 0: - filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ] - - for fn in filenames: - basename = os.path.basename(fn) - if not fn.endswith('.dak-commands'): - log.log(['unexpected filename', basename]) - continue - - command = CommandFile(fn, log) - if command.evaluate(): - log.log(['moving to done', basename]) - dst = find_next_free(os.path.join(donedir, basename)) - else: - log.log(['moving to reject', basename]) - dst = find_next_free(os.path.join(rejectdir, basename)) - - with FilesystemTransaction() as fs: - fs.move(fn, dst, mode=0o644) - fs.commit() - - log.close() - -if __name__ == '__main__': - main() diff --git a/dak/process_commands.py b/dak/process_commands.py new file mode 100644 index 00000000..7e013dcd --- /dev/null +++ b/dak/process_commands.py @@ -0,0 +1,82 @@ +#! /usr/bin/env python +# +# Copyright (C) 2012, Ansgar Burchardt +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import apt_pkg +import datetime +import os +import sys + +from daklib.config import Config +from daklib.command import CommandError, CommandFile +from daklib.daklog import Logger +from daklib.fstransactions import FilesystemTransaction +from daklib.utils import find_next_free + +def usage(): + print """Usage: dak process-commands [-d ] [...] + +process command files +""" + +def main(argv=None): + if argv is None: + argv = sys.argv + + arguments = [('h', 'help', 'Process-Commands::Options::Help'), + ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')] + + cnf = Config() + cnf['Process-Command::Options::Dummy'] = '' + filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) + options = cnf.subtree('Process-Commands::Options') + + if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options): + usage() + sys.exit(0) + + log = Logger('command') + + now = datetime.datetime.now() + donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d')) + rejectdir = cnf['Dir::Reject'] + + if len(filenames) == 0: + filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ] + + for fn in filenames: + basename = os.path.basename(fn) + if not fn.endswith('.dak-commands'): + log.log(['unexpected filename', basename]) + continue + + command = CommandFile(fn, log) + if command.evaluate(): + log.log(['moving to done', basename]) + dst = find_next_free(os.path.join(donedir, basename)) + else: + log.log(['moving to reject', basename]) + dst = find_next_free(os.path.join(rejectdir, basename)) + + with FilesystemTransaction() as fs: + fs.move(fn, dst, mode=0o644) + fs.commit() + + log.close() + +if __name__ == '__main__': + main()