]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
Änderungan an Statusdatei-Objekt
authorFrank Brehm <frank@brehm-online.com>
Sat, 18 Jun 2011 07:27:45 +0000 (07:27 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sat, 18 Jun 2011 07:27:45 +0000 (07:27 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@255 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateStatusFile.py
po/LogRotateStatusFile.de.po
po/LogRotateStatusFile.pot

index 313102db92a856c15829f5f8a09820fe65dc7a20..6c202f7a8c556065950b1b997e72e15f1d570e7e 100755 (executable)
@@ -158,6 +158,12 @@ class LogrotateStatusFile(object):
         @type: bool
         '''
 
+        self.has_changed = False
+        '''
+        @ivar: flag, whether something has changed and needs to be written
+        @type: bool
+        '''
+
         self.logger = logger
         '''
         @ivar: logger object
@@ -206,6 +212,20 @@ class LogrotateStatusFile(object):
         self._read(must_exists = False)
         self._check_permissions()
 
+    #-------------------------------------------------------
+    def __del__(self):
+        '''
+        Destructor.
+        Enforce saving of status file, if something has changed.
+        '''
+
+        _ = self.t.lgettext
+        msg = _("Status file object will destroyed.")
+        self.logger.debug(msg)
+
+        if self.has_changed:
+            self.write()
+
     #-------------------------------------------------------
     def as_dict(self):
         '''
@@ -227,6 +247,7 @@ class LogrotateStatusFile(object):
         res['logger']                = self.logger
         res['file_state']            = self.file_state
         res['was_read']              = self.was_read
+        res['has_changed']           = self.has_changed
 
         return res
 
@@ -276,15 +297,16 @@ class LogrotateStatusFile(object):
                 % {'file': logfile, 'date': date_utc.isoformat(' ') }
         self.logger.debug(msg)
 
-        self._read(must_exists = False)
+        #self._read(must_exists = False)
         self.file_state[logfile] = date_utc
+        self.has_changed = True
 
-        self._write()
+        #self.write()
 
         return date_utc
 
     #------------------------------------------------------------
-    def _write(self):
+    def write(self):
         '''
         Writes the content of self.file_state in the state file.
 
@@ -353,6 +375,7 @@ class LogrotateStatusFile(object):
                 fd.close()
                 fd = None
 
+        self.has_changed = False
         return True
 
     #------------------------------------------------------------
index 27525ace94475f6038839d26f297006b78d509ed..cda1893a4512c10f58cc0d13e17f7a744bf01cc2 100644 (file)
@@ -20,6 +20,10 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
+#:LogRotateStatusFile.py:223
+msgid "Status file object will destroyed."
+msgstr "Statusdatei-Objekt wird zerstört."
+
 #: LogRotateStatusFile.py:275
 #, python-format
 msgid "Setting rotation date of '%(file)s' to '%(date)s' ..."
index af1ecdb05283717717d655754d448aac6b7e61a2..54202f07b9045d9805b5bf1da1cc40e57e6ff481 100644 (file)
@@ -20,6 +20,10 @@ msgstr ""
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
+#:LogRotateStatusFile.py:223
+msgid "Status file object will destroyed."
+msgstr ""
+
 #: LogRotateStatusFile.py:275
 #, python-format
 msgid "Setting rotation date of '%(file)s' to '%(date)s' ..."