[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 3/9] Centralise UrgencyLog handling



Signed-off-by: Mark Hymers <mhy@debian.org>
---
 dak/process_upload.py |   12 +++++-------
 daklib/queue.py       |    2 +-
 daklib/urgencylog.py  |   33 +++++++++++++++++++++++++--------
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/dak/process_upload.py b/dak/process_upload.py
index f74993c..4e734da 100755
--- a/dak/process_upload.py
+++ b/dak/process_upload.py
@@ -424,7 +424,6 @@ def main():
 
     cnf = Config()
     summarystats = SummaryStats()
-    log_urgency = False
 
     DBConn()
 
@@ -464,10 +463,10 @@ def main():
                 utils.fubar("Couldn't obtain lock; assuming another 'dak process-upload' is already running.")
             else:
                 raise
-        if cnf.get("Dir::UrgencyLog"):
-            # Initialise UrgencyLog()
-            log_urgency = True
-            UrgencyLog()
+
+        # Initialise UrgencyLog() - it will deal with the case where we don't
+        # want to log urgencies
+        urgencylog = UrgencyLog()
 
     Logger = daklog.Logger("process-upload", Options["No-Action"])
 
@@ -513,8 +512,7 @@ def main():
     byebye()
 
     if not Options["No-Action"]:
-        if log_urgency:
-            UrgencyLog().close()
+        urgencylog.close()
 
     Logger.close()
 
diff --git a/daklib/queue.py b/daklib/queue.py
index 5055ea5..63375f2 100755
--- a/daklib/queue.py
+++ b/daklib/queue.py
@@ -2181,7 +2181,7 @@ distribution."""
         utils.move(self.pkg.changes_file,
                    os.path.join(donedir, os.path.basename(self.pkg.changes_file)))
 
-        if self.pkg.changes["architecture"].has_key("source") and cnf.get("Dir::UrgencyLog"):
+        if self.pkg.changes["architecture"].has_key("source"):
             UrgencyLog().log(self.pkg.dsc["source"], self.pkg.dsc["version"], self.pkg.changes["urgency"])
 
         self.update_subst()
diff --git a/daklib/urgencylog.py b/daklib/urgencylog.py
index 7d67905..a47974d 100644
--- a/daklib/urgencylog.py
+++ b/daklib/urgencylog.py
@@ -47,26 +47,43 @@ class UrgencyLog(object):
 
             self.timestamp = time.strftime("%Y%m%d%H%M%S")
 
-            # Create the log directory if it doesn't exist
-            self.log_dir = Config()["Dir::UrgencyLog"]
+            cnf = Config()
+            if cnf.has_key("Dir::UrgencyLog"):
+                # Create the log directory if it doesn't exist
+                self.log_dir = cnf["Dir::UrgencyLog"]
 
-            if not os.path.exists(self.log_dir) or not os.access(self.log_dir, os.W_OK):
-                warn("UrgencyLog directory %s does not exist or is not writeable, using /srv/ftp.debian.org/tmp/ instead" % (self.log_dir))
-                self.log_dir = '/srv/ftp.debian.org/tmp/'
+                if not os.path.exists(self.log_dir) or not os.access(self.log_dir, os.W_OK):
+                    warn("UrgencyLog directory %s does not exist or is not writeable, using /srv/ftp.debian.org/tmp/ instead" % (self.log_dir))
+                    self.log_dir = '/srv/ftp.debian.org/tmp/'
+
+                # Open the logfile
+                self.log_filename = "%s/.install-urgencies-%s.new" % (self.log_dir, self.timestamp)
+                self.log_file = open_file(self.log_filename, 'w')
+
+            else:
+                self.log_dir = None
+                self.log_filename = None
+                self.log_file = None
 
-            # Open the logfile
-            self.log_filename = "%s/.install-urgencies-%s.new" % (self.log_dir, self.timestamp)
-            self.log_file = open_file(self.log_filename, 'w')
             self.writes = 0
 
     def log(self, source, version, urgency):
         "Log an event"
+
+        # Don't try and log if Dir::UrgencyLog is not configured
+        if self.log_file is None:
+            return
+
         self.log_file.write(" ".join([source, version, urgency])+'\n')
         self.log_file.flush()
         self.writes += 1
 
     def close(self):
         "Close a Logger object"
+        # Don't try and log if Dir::UrgencyLog is not configured
+        if self.log_file is None:
+            return
+
         self.log_file.flush()
         self.log_file.close()
 
-- 
1.7.2.5



Reply to: