From: Mark Hymers Date: Mon, 25 May 2009 17:31:20 +0000 (+0100) Subject: rename logging module to not conflict with the python one X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=307823ca2367f65ccfbbc7c0bd5054f2883b9c9c;hp=10c964315953c1da8a3f388c4fd9c11c94fa8af4;p=dak.git rename logging module to not conflict with the python one Signed-off-by: Mark Hymers --- diff --git a/dak/add_user.py b/dak/add_user.py index 2916075d..851e0e2e 100755 --- a/dak/add_user.py +++ b/dak/add_user.py @@ -25,7 +25,7 @@ import time import os import apt_pkg from daklib import database -from daklib import logging +from daklib import daklog from daklib import queue from daklib import utils from daklib.regexes import re_gpg_fingerprint, re_user_address, re_user_mails, re_user_name diff --git a/dak/check_overrides.py b/dak/check_overrides.py index 1e7e5384..e21b849a 100755 --- a/dak/check_overrides.py +++ b/dak/check_overrides.py @@ -51,7 +51,7 @@ import pg, sys, os import apt_pkg from daklib import database -from daklib import logging +from daklib import daklog from daklib import utils ################################################################################ @@ -291,9 +291,9 @@ def main (): priorities[i[0]] = i[1] if not Options["No-Action"]: - Logger = logging.Logger(Cnf, "check-overrides") + Logger = daklog.Logger(Cnf, "check-overrides") else: - Logger = logging.Logger(Cnf, "check-overrides", 1) + Logger = daklog.Logger(Cnf, "check-overrides", 1) gen_blacklist(Cnf["Dir::Queue::Accepted"]) diff --git a/dak/control_overrides.py b/dak/control_overrides.py index 5d6ba46c..ff265266 100755 --- a/dak/control_overrides.py +++ b/dak/control_overrides.py @@ -53,7 +53,7 @@ import pg, sys, time import apt_pkg from daklib import utils from daklib import database -from daklib import logging +from daklib import daklog from daklib.regexes import re_comments ################################################################################ @@ -305,7 +305,7 @@ def main (): utils.warn("In No-Action Mode") noaction = 1 - Logger = logging.Logger(Cnf, "control-overrides", noaction) + Logger = daklog.Logger(Cnf, "control-overrides", noaction) if file_list: for f in file_list: process_file(utils.open_file(f), suite, component, otype, action, noaction) diff --git a/dak/control_suite.py b/dak/control_suite.py index c6084d8b..8dc57022 100755 --- a/dak/control_suite.py +++ b/dak/control_suite.py @@ -44,7 +44,7 @@ import pg, sys import apt_pkg from daklib import database -from daklib import logging +from daklib import daklog from daklib import utils ####################################################################################### @@ -281,7 +281,7 @@ def main (): if action == "list": get_list(suite) else: - Logger = logging.Logger(Cnf, "control-suite") + Logger = daklog.Logger(Cnf, "control-suite") if file_list: for f in file_list: process_file(utils.open_file(f), suite, action) diff --git a/dak/make_suite_file_list.py b/dak/make_suite_file_list.py index 8bb9142c..829e5c84 100755 --- a/dak/make_suite_file_list.py +++ b/dak/make_suite_file_list.py @@ -43,7 +43,7 @@ import pg import sys import apt_pkg from daklib import database -from daklib import logging +from daklib import daklog from daklib import utils ################################################################################ @@ -374,7 +374,7 @@ def main(): projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])) database.init(Cnf, projectB) - Logger = logging.Logger(Cnf, "make-suite-file-list") + Logger = daklog.Logger(Cnf, "make-suite-file-list") do_da_do_da() Logger.close() diff --git a/dak/new_security_install.py b/dak/new_security_install.py index f6a7354b..fec030b7 100755 --- a/dak/new_security_install.py +++ b/dak/new_security_install.py @@ -23,7 +23,7 @@ import apt_pkg, os, sys, pwd, time, commands from daklib import queue -from daklib import logging +from daklib import daklog from daklib import utils from daklib import database from daklib.regexes import re_taint_free @@ -78,7 +78,7 @@ def init(): if Options["No-Action"]: Options["Sudo"] = "" if not Options["Sudo"] and not Options["No-Action"]: - Logger = Upload.Logger = logging.Logger(Cnf, "new-security-install") + Logger = Upload.Logger = daklog.Logger(Cnf, "new-security-install") return arguments diff --git a/dak/override.py b/dak/override.py index 4b92ae11..72b0836e 100755 --- a/dak/override.py +++ b/dak/override.py @@ -27,7 +27,7 @@ import pg, sys import apt_pkg -from daklib import logging +from daklib import daklog from daklib import database from daklib import utils @@ -202,7 +202,7 @@ def main (): game_over() - Logger = logging.Logger(Cnf, "override") + Logger = daklog.Logger(Cnf, "override") projectB.query("BEGIN WORK") # We're in "do it" mode, we have something to do... do it diff --git a/dak/process_accepted.py b/dak/process_accepted.py index 9883bb20..00893fdf 100755 --- a/dak/process_accepted.py +++ b/dak/process_accepted.py @@ -43,7 +43,7 @@ import time import re import apt_pkg, commands from daklib import database -from daklib import logging +from daklib import daklog from daklib import queue from daklib import utils from daklib.dak_exceptions import * @@ -649,7 +649,7 @@ def main(): utils.fubar("Couldn't obtain lock; assuming another 'dak process-accepted' is already running.") else: raise - Logger = Upload.Logger = logging.Logger(Cnf, "process-accepted") + Logger = Upload.Logger = daklog.Logger(Cnf, "process-accepted") if not installing_to_stable and Cnf.get("Dir::UrgencyLog"): Urgency_Logger = Urgency_Log(Cnf) diff --git a/dak/process_new.py b/dak/process_new.py index a07470fa..7979b7c1 100755 --- a/dak/process_new.py +++ b/dak/process_new.py @@ -55,7 +55,7 @@ import pwd import apt_pkg, apt_inst import examine_package from daklib import database -from daklib import logging +from daklib import daklog from daklib import queue from daklib import utils from daklib.regexes import re_no_epoch, re_default_answer, re_isanum @@ -769,7 +769,7 @@ def init(): if not Options["No-Action"]: try: - Logger = Upload.Logger = logging.Logger(Cnf, "process-new") + Logger = Upload.Logger = daklog.Logger(Cnf, "process-new") except CantOpenError, e: Options["Trainee"] = "True" diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index e69919bc..6aa89e12 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -49,7 +49,7 @@ import apt_pkg from debian_bundle import deb822 from daklib.dbconn import * from daklib.binary import Binary -from daklib import logging +from daklib import daklog from daklib import queue from daklib import utils from daklib.textutils import fix_maintainer @@ -1582,7 +1582,7 @@ def main(): utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.") else: raise - Logger = Upload.Logger = logging.Logger(Cnf, "process-unchecked") + Logger = Upload.Logger = daklog.Logger(Cnf, "process-unchecked") # debian-{devel-,}-changes@lists.debian.org toggles writes access based on this header bcc = "X-DAK: dak process-unchecked\nX-Katie: $Revision: 1.65 $" diff --git a/dak/reject_proposed_updates.py b/dak/reject_proposed_updates.py index 7770f66e..99dae877 100755 --- a/dak/reject_proposed_updates.py +++ b/dak/reject_proposed_updates.py @@ -22,7 +22,7 @@ import os, pg, sys import apt_pkg from daklib import database -from daklib import logging +from daklib import daklog from daklib import queue from daklib import utils from daklib.regexes import re_default_answer @@ -72,7 +72,7 @@ def main(): database.init(Cnf, projectB) Upload = queue.Upload(Cnf) - Logger = Upload.Logger = logging.Logger(Cnf, "reject-proposed-updates") + Logger = Upload.Logger = daklog.Logger(Cnf, "reject-proposed-updates") bcc = "X-DAK: dak rejected-proposed-updates\nX-Katie: lauren $Revision: 1.4 $" if Cnf.has_key("Dinstall::Bcc"): diff --git a/daklib/daklog.py b/daklib/daklog.py new file mode 100755 index 00000000..0cca205e --- /dev/null +++ b/daklib/daklog.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +""" +Logging functions + +@contact: Debian FTP Master +@copyright: 2001, 2002, 2006 James Troup +@license: GNU General Public License version 2 or later +""" + +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +import os +import pwd +import time +import sys +import utils + +################################################################################ + +class Logger: + "Logger object" + Cnf = None + logfile = None + program = None + + def __init__ (self, Cnf, program, debug=0): + "Initialize a new Logger object" + self.Cnf = Cnf + self.program = program + # Create the log directory if it doesn't exist + logdir = Cnf["Dir::Log"] + if not os.path.exists(logdir): + umask = os.umask(00000) + os.makedirs(logdir, 02775) + os.umask(umask) + # Open the logfile + logfilename = "%s/%s" % (logdir, time.strftime("%Y-%m")) + logfile = None + if debug: + logfile = sys.stderr + else: + umask = os.umask(00002) + logfile = utils.open_file(logfilename, 'a') + os.umask(umask) + self.logfile = logfile + # Log the start of the program + user = pwd.getpwuid(os.getuid())[0] + self.log(["program start", user]) + + def log (self, details): + "Log an event" + # Prepend the timestamp and program name + details.insert(0, self.program) + timestamp = time.strftime("%Y%m%d%H%M%S") + details.insert(0, timestamp) + # Force the contents of the list to be string.join-able + details = [ str(i) for i in details ] + # Write out the log in TSV + self.logfile.write("|".join(details)+'\n') + # Flush the output to enable tail-ing + self.logfile.flush() + + def close (self): + "Close a Logger object" + self.log(["program end"]) + self.logfile.flush() + self.logfile.close() diff --git a/daklib/logging.py b/daklib/logging.py deleted file mode 100755 index 0cca205e..00000000 --- a/daklib/logging.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python - -""" -Logging functions - -@contact: Debian FTP Master -@copyright: 2001, 2002, 2006 James Troup -@license: GNU General Public License version 2 or later -""" - -# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os -import pwd -import time -import sys -import utils - -################################################################################ - -class Logger: - "Logger object" - Cnf = None - logfile = None - program = None - - def __init__ (self, Cnf, program, debug=0): - "Initialize a new Logger object" - self.Cnf = Cnf - self.program = program - # Create the log directory if it doesn't exist - logdir = Cnf["Dir::Log"] - if not os.path.exists(logdir): - umask = os.umask(00000) - os.makedirs(logdir, 02775) - os.umask(umask) - # Open the logfile - logfilename = "%s/%s" % (logdir, time.strftime("%Y-%m")) - logfile = None - if debug: - logfile = sys.stderr - else: - umask = os.umask(00002) - logfile = utils.open_file(logfilename, 'a') - os.umask(umask) - self.logfile = logfile - # Log the start of the program - user = pwd.getpwuid(os.getuid())[0] - self.log(["program start", user]) - - def log (self, details): - "Log an event" - # Prepend the timestamp and program name - details.insert(0, self.program) - timestamp = time.strftime("%Y%m%d%H%M%S") - details.insert(0, timestamp) - # Force the contents of the list to be string.join-able - details = [ str(i) for i in details ] - # Write out the log in TSV - self.logfile.write("|".join(details)+'\n') - # Flush the output to enable tail-ing - self.logfile.flush() - - def close (self): - "Close a Logger object" - self.log(["program end"]) - self.logfile.flush() - self.logfile.close()