Beispiel #1
0
 def urandom(n):
     result = []
     hasher = sha1(str(os.getpid()) + str(time.time()))
     while len(result) * hasher.digest_size < n:
         hasher.update(str(_entropy.random()))
         result.append(hasher.digest())
     result = ''.join(result)
     return result[:n] if len(result) > n else result
Beispiel #2
0
    def _get_hashed_filename(cls, filename):
        """Get the hashed filename corresponding to the given filename.

        WARNING: This method is used by db28.py for moving attachments from
        the old "attachments" directory to the "files" directory. Please check
        all changes so that they don't break the upgrade.
        """
        hash = sha1(filename.encode('utf-8')).hexdigest()
        match = cls._extension_re.search(filename)
        return hash + match.group(0) if match else hash
Beispiel #3
0
    def _get_path(cls, env_path, parent_realm, parent_id, filename):
        """Get the path of an attachment.

        WARNING: This method is used by db28.py for moving attachments from
        the old "attachments" directory to the "files" directory. Please check
        all changes so that they don't break the upgrade.
        """
        path = os.path.join(env_path, 'files', 'attachments', parent_realm)
        hash = sha1(parent_id.encode('utf-8')).hexdigest()
        path = os.path.join(path, hash[0:3], hash)
        if filename:
            path = os.path.join(path, cls._get_hashed_filename(filename))
        return os.path.normpath(path)
 def _update_diagram(self, req, params):
     _, errors = self._validate_workflow(req, params)
     data = {'result': (1, 0)[len(errors) == 0],     # 0 if cond else 1
             'errors': errors}
     if len(errors) == 0:
         script = self._create_dot_script(params)
         self._image_path_setup(req)
         dir = os.path.join(self.env.get_htdocs_dir(), 'tracworkflowadmin')
         basename = '%s.png' % sha1(script).hexdigest()
         path = os.path.join(dir, basename)
         if not self.diagram_cache or not os.path.isfile(path):
             self._create_diagram_image(path, dir, script, errors)
         timestamp = int(os.path.getmtime(path))
         data['image_url'] = self._image_tmp_url(req, basename, timestamp)
     req.send(json.dumps(data))
 def _update_diagram(self, req, params):
     _, errors = self._validate_workflow(req, params)
     data = {
         'result': (1, 0)[len(errors) == 0],  # 0 if cond else 1
         'errors': errors
     }
     if len(errors) == 0:
         script = self._create_dot_script(params)
         self._image_path_setup(req)
         dir = os.path.join(self._env_htdocs_dir, 'tracworkflowadmin')
         basename = '%s.png' % sha1(script).hexdigest()
         path = os.path.join(dir, basename)
         if not self.diagram_cache or not os.path.isfile(path):
             self._create_diagram_image(path, dir, script, errors)
         timestamp = int(os.path.getmtime(path))
         data['image_url'] = self._image_tmp_url(req, basename, timestamp)
     req.send(json.dumps(data))
Beispiel #6
0
Datei: env.py Projekt: t2y/trac
 def setup_log(self):
     """Initialize the logging sub-system."""
     from trac.log import logger_handler_factory
     logtype = self.log_type
     logfile = self.log_file
     if logtype == 'file' and not os.path.isabs(logfile):
         logfile = os.path.join(self.get_log_dir(), logfile)
     format = self.log_format
     logid = 'Trac.%s' % sha1(self.path).hexdigest()
     if format:
         format = format.replace('$(', '%(') \
                  .replace('%(path)s', self.path) \
                  .replace('%(basename)s', os.path.basename(self.path)) \
                  .replace('%(project)s', self.project_name)
     self.log, self._log_handler = logger_handler_factory(
         logtype, logfile, self.log_level, logid, format=format)
     from trac import core, __version__ as VERSION
     self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                   get_pkginfo(core).get('version', VERSION))
Beispiel #7
0
    def setup_log(self):
        """Initialize the logging sub-system."""
        from trac.log import logger_handler_factory
        logtype = self.log_type
        logfile = self.log_file
        format = self.log_format

        self.parent.log.debug("Log type '%s' for product '%s'", logtype,
                              self.product.prefix)

        # Force logger inheritance on identical configuration
        if (logtype, logfile,
                format) == (self.parent.log_type, self.parent.log_file,
                            self.parent.log_format):
            logtype = 'inherit'

        if logtype == 'inherit':
            self.log = self.parent.log
            self._log_handler = self.parent._log_handler
            self.parent.log.warning(
                "Inheriting parent logger for product '%s'",
                self.product.prefix)
        else:
            if logtype == 'file' and not os.path.isabs(logfile):
                logfile = os.path.join(self.get_log_dir(), logfile)
            logid = 'Trac.%s.%s' % \
                    (sha1(self.parent.path).hexdigest(), self.product.prefix)
            if format:
                format = format.replace('$(', '%(') \
                         .replace('%(path)s', self.path) \
                         .replace('%(basename)s', os.path.basename(self.path)) \
                         .replace('%(project)s', self.project_name)
            self.log, self._log_handler = logger_handler_factory(
                logtype, logfile, self.log_level, logid, format=format)

        from trac import core, __version__ as VERSION
        self.log.info(
            '-' * 32 + ' product %s environment startup [Trac %s] ' + '-' * 32,
            self.product.prefix,
            get_pkginfo(core).get('version', VERSION))
Beispiel #8
0
    def setup_log(self):
        """Initialize the logging sub-system."""
        from trac.log import logger_handler_factory
        logtype = self.log_type
        logfile = self.log_file
        format = self.log_format

        self.parent.log.debug("Log type '%s' for product '%s'",
                logtype, self.product.prefix)

        # Force logger inheritance on identical configuration
        if (logtype, logfile, format) == (self.parent.log_type,
                self.parent.log_file, self.parent.log_format):
            logtype = 'inherit'

        if logtype == 'inherit':
            self.log = self.parent.log
            self._log_handler = self.parent._log_handler
            self.parent.log.info("Inheriting parent logger for product '%s'",
                    self.product.prefix)
        else:
            if logtype == 'file' and not os.path.isabs(logfile):
                logfile = os.path.join(self.get_log_dir(), logfile)
            logid = 'Trac.%s.%s' % \
                    (sha1(self.parent.path).hexdigest(), self.product.prefix)
            if format:
                format = format.replace('$(', '%(') \
                         .replace('%(path)s', self.path) \
                         .replace('%(basename)s', os.path.basename(self.path)) \
                         .replace('%(project)s', self.project_name)
            self.log, self._log_handler = logger_handler_factory(
                logtype, logfile, self.log_level, logid, format=format)

        from trac import core, __version__ as VERSION
        self.log.info('-' * 32 +
                        ' product %s environment startup [Trac %s] ' +
                        '-' * 32,
                      self.product.prefix,
                      get_pkginfo(core).get('version', VERSION))
Beispiel #9
0
 def _get_hashed_screenshot_name(self, filename):
     hash = sha1(filename.encode("utf-8")).hexdigest()
     return hash
Beispiel #10
0
def hex_entropy(bytes=32):
    return sha1(str(_entropy.random())).hexdigest()[:bytes]
Beispiel #11
0
 def _get_hashed_screenshot_name(self, filename):
     hash = sha1(filename.encode("utf-8")).hexdigest()
     return hash
Beispiel #12
0
def hex_entropy(bytes=32):
    import random

    return sha1(str(random.random())).hexdigest()[:bytes]