Ejemplo n.º 1
0
    def writeActivityLog(self, trans):
        """Write an entry to the activity log.

        Writes an entry to the script log file. Uses settings
        ``ActivityLogFilename`` and ``ActivityLogColumns``.
        """
        filename = self.serverSidePath(self.setting('ActivityLogFilename'))
        if os.path.exists(filename):
            f = open(filename, 'a')
        else:
            f = open(filename, 'w')
            f.write(','.join(self.setting('ActivityLogColumns')) + '\n')
        values = []
        objects = dict(
            application=self,
            transaction=trans,
            request=trans.request(),
            response=trans.response(),
            # don't cause creation of session here:
            servlet=trans.servlet(),
            session=trans._session)
        for column in self.setting('ActivityLogColumns'):
            try:
                value = valueForName(objects, column)
            except Exception:
                value = '(unknown)'
            if isinstance(value, float):
                # probably need more flexibility in the future
                value = '%0.2f' % value
            else:
                value = str(value)
            values.append(value)
        f.write(','.join(values) + '\n')
        f.close()
Ejemplo n.º 2
0
    def writeActivityLog(self, trans):
        """Write an entry to the activity log.

        Writes an entry to the script log file. Uses settings
        ``ActivityLogFilename`` and ``ActivityLogColumns``.

        """
        filename = self.serverSidePath(
            self.setting('ActivityLogFilename'))
        if os.path.exists(filename):
            f = open(filename, 'a')
        else:
            f = open(filename, 'w')
            f.write(','.join(self.setting('ActivityLogColumns')) + '\n')
        values = []
        objects = dict(application=self, transaction=trans,
            request=trans.request(), response=trans.response(),
             # don't cause creation of session here:
            servlet=trans.servlet(), session=trans._session)
        for column in self.setting('ActivityLogColumns'):
            try:
                value = valueForName(objects, column)
            except Exception:
                value = '(unknown)'
            if isinstance(value, float):
                # probably need more flexibility in the future
                value = '%0.2f' % value
            else:
                value = str(value)
            values.append(value)
        f.write(','.join(values) + '\n')
        f.close()
 def lookup(self, obj, key, default=NoDefault):
     if type(obj) is not types.InstanceType:
         # just so non-obj cases pass
         return valueForName(obj, key, default)
     else:
         # What we're really testing, the mix-in method:
         return obj.valueForName(key, default)
Ejemplo n.º 4
0
    def writeActivityLog(self, trans):
        """Write an entry to the activity log.

        Writes an entry to the script log file. Uses settings
        ``ActivityLogFilename`` and ``ActivityLogColumns``.
        """
        filename = self.setting('ActivityLogFilename')
        if '/' not in filename:
            filename = os.path.join(self._logDir, filename)
        filename = self.serverSidePath(filename)
        mode = 'a' if os.path.exists(filename) else 'w'
        with open(filename, mode, encoding='utf-8') as f:
            if mode == 'w':
                f.write(','.join(self.setting('ActivityLogColumns')) + '\n')
            values = []
            objects = dict(
                application=self,
                transaction=trans,
                request=trans.request(),
                response=trans.response(),
                servlet=trans.servlet(),
                # don't cause creation of session here:
                session=trans._session)
            for column in self.setting('ActivityLogColumns'):
                try:
                    value = valueForName(objects, column)
                except Exception:
                    value = '(unknown)'
                if isinstance(value, float):
                    # probably need more flexibility in the future
                    value = f'{value:02f}'
                else:
                    value = str(value)
                values.append(value)
            f.write(','.join(values) + '\n')
Ejemplo n.º 5
0
 def debugStr(self):
     out = [self.__class__.__name__, '(', '0x%x' % id(self)]
     sep = ', '
     for key in self._debugKeys:
         out.append(sep)
         out.append(key)
         out.append('=')
         try:
             out.append(repr(valueForName(self, key)))
         except Exception, exc:
             from MiscUtils.Funcs import excstr
             out.append('('+excstr(exc)+')')
Ejemplo n.º 6
0
 def debugStr(self):
     out = [self.__class__.__name__, '(', '0x%x' % id(self)]
     sep = ', '
     for key in self._debugKeys:
         out.append(sep)
         out.append(key)
         out.append('=')
         try:
             out.append(repr(valueForName(self, key)))
         except Exception as exc:
             from MiscUtils.Funcs import excstr
             out.append('(' + excstr(exc) + ')')
     out.append(')')
     out = ''.join(out)
     return out
Ejemplo n.º 7
0
    def writeScriptLog(self):
        """Write an entry to the script log file.

        Uses settings ScriptLogFilename and ScriptLogColumns.
        """
        filename = self.setting('ScriptLogFilename')
        if os.path.exists(filename):
            f = open(filename, 'a')
        else:
            f = open(filename, 'w')
            f.write(','.join(self.setting('ScriptLogColumns')) + '\n')
        values = []
        for column in self.setting('ScriptLogColumns'):
            value = valueForName(self, column)
            if isinstance(value, float):
                # might need more flexibility in the future
                value = '%0.4f' % value
            else:
                value = str(value)
            values.append(value)
        f.write(','.join(values) + '\n')
        f.close()
Ejemplo n.º 8
0
    def writeScriptLog(self):
        """Write an entry to the script log file.

        Uses settings ScriptLogFilename and ScriptLogColumns.

        """
        filename = self.setting('ScriptLogFilename')
        if os.path.exists(filename):
            f = open(filename, 'a')
        else:
            f = open(filename, 'w')
            f.write(','.join(self.setting('ScriptLogColumns')) + '\n')
        values = []
        for column in self.setting('ScriptLogColumns'):
            value = valueForName(self, column)
            if isinstance(value, float):
                # might need more flexibility in the future
                value = '%0.4f' % value
            else:
                value = str(value)
            values.append(value)
        f.write(','.join(values) + '\n')
        f.close()
Ejemplo n.º 9
0
 def lookup(self, obj, key, default=NoDefault):
     return valueForName(obj, key, default)
Ejemplo n.º 10
0
 def lookup(self, obj, key, default=NoDefault):
     return valueForName(obj, key, default)