]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
Mit _create_olddir angefangen
authorFrank Brehm <frank@brehm-online.com>
Mon, 27 Jun 2011 16:58:54 +0000 (16:58 +0000)
committerFrank Brehm <frank@brehm-online.com>
Mon, 27 Jun 2011 16:58:54 +0000 (16:58 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@263 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateHandler.py

index d7c89b113b5cc889fe983b8485b9a9c2721d84dd..3a7030f5aa50121b6ce4a3f8dff85643f874eb8f 100755 (executable)
@@ -631,7 +631,86 @@ class LogrotateHandler(object):
                         return
                 self.scripts[firstscript]['first'] = True
 
-        # 
+        # Executing prerotate scripts ...
+        # bla bla bla 
+
+        if not self._create_olddir(logfile, definition):
+            return
+
+    #------------------------------------------------------------
+    def _create_olddir(self, logfile, definition):
+        '''
+        Creating the olddir, if necessary.
+
+        @param logfile: the logfile to rotate
+        @type logfile:  str
+        @param definition: definitions from configuration file (for olddir)
+        @type definition:  dict
+
+        @return: successful or not
+        @rtype:  bool
+        '''
+
+        _ = self.t.lgettext
+
+        uid = os.geteuid()
+        gid = os.getegid()
+
+        o = definition['olddir']
+        if not o['dirname']:
+            if self.verbose > 1:
+                msg = _("No dirname directive for olddir given.")
+                self.logger.debug(msg)
+            return True
+        olddir = o['dirname']
+
+        mode = o['mode']
+        if mode is None:
+            mode = int(0755, 8)
+        owner = o['owner']
+        if not owner:
+            owner = uid
+        group = o['group']
+        if not group:
+            group = gid
+
+        basename = os.path.basename(logfile)
+        dirname  = os.path.dirname(logfile)
+
+        match = re.search(r'%', olddir)
+        if match:
+            o['dateformat'] = True
+            olddir = datetime.utcnow().strftime(olddir)
+
+        # Substitution of $dirname
+        olddir = re.sub(r'(?:\${dirname}|\$dirname(?![a-zA-Z0-9_]))', dirname, olddir)
+
+        # Substitution of $basename
+        olddir = re.sub(r'(?:\${basename}|\$basename(?![a-zA-Z0-9_]))', basename, olddir)
+
+        # Substitution of $nodename
+        olddir = re.sub(r'(?:\${nodename}|\$nodename(?![a-zA-Z0-9_]))', self.template['nodename'], olddir)
+
+        # Substitution of $domain
+        olddir = re.sub(r'(?:\${domain}|\$domain(?![a-zA-Z0-9_]))', self.template['domain'], olddir)
+
+        # Substitution of $machine
+        olddir = re.sub(r'(?:\${machine}|\$machine(?![a-zA-Z0-9_]))', self.template['machine'], olddir)
+
+        # Substitution of $release
+        olddir = re.sub(r'(?:\${release}|\$release(?![a-zA-Z0-9_]))', self.template['release'], olddir)
+
+        # Substitution of $sysname
+        olddir = re.sub(r'(?:\${sysname}|\$sysname(?![a-zA-Z0-9_]))', self.template['sysname'], olddir)
+
+        if not os.path.isabs(olddir):
+            olddir = os.path.join(dirname, olddir)
+
+        if self.verbose > 1:
+            msg = _("Olddir name is now '%s'") % (olddir)
+            self.logger.debug(msg)
+
+        return True
 
     #------------------------------------------------------------
     def _execute_command(self, command):