コード例 #1
0
    def notify(self, notifier: INotify, filepath: FilePath, mask: int) -> None:
        try:
            maskNames = humanReadableMask(mask)
            if maskNames[0] == 'delete_self':
                if not filepath.exists():
                    log.info("%s delete_self", filepath)
                    self.fileGone()
                    return
                else:
                    log.warn(
                        "%s delete_self event but file is here. "
                        "probably a new version moved in", filepath)

            # we could filter these out in the watch() call, but I want
            # the debugging
            if maskNames[0] in ['open', 'access', 'close_nowrite', 'attrib']:
                log.debug("%s %s event, ignoring" % (filepath, maskNames))
                return

            try:
                if filepath.getModificationTime() == self.lastWriteTimestamp:
                    log.debug("%s changed, but we did this write", filepath)
                    return
            except OSError as e:
                log.error("%s: %r" % (filepath, e))
                # getting OSError no such file, followed by no future reads
                reactor.callLater(.5, self.addWatch)  # ?

                return

            log.info("reread %s because of %s event", filepath, maskNames)

            self.reread()
        except Exception:
            traceback.print_exc()
コード例 #2
0
 def load_revokations(self):
     """
     Load PEM formatted certificates that are no longer trustworthy
     and store the suject and issuer.
     `cert_list` is the path to a file that contains glob-like patterns
     to PEM-formatted certificates.
     """
     revoke_file = self.revoke_file
     revoke_state = self.revoke_state 
     if revoke_file is not None:
         last_mod_time = revoke_state['last_mod_time']
         fp = FilePath(revoke_file)
         if not fp.exists():
             return
         mod_time = fp.getModificationTime()
         if last_mod_time is None or mod_time > last_mod_time:
             log.msg("[INFO] Loading revoked certificate files specified in '{0}'.".format(
                 revoke_file))
             revoke_state['last_mod_time'] = mod_time
             revoked = set([])
             with open(revoke_file) as f:
                 for line in f:
                     pattern = line.rstrip('\r\n')
                     if pattern == '' or pattern.startswith('#'):
                         continue
                     for path in glob.glob(pattern):
                         certs = [pem_cert_to_x509(cert)
                             for cert in pem.parse_file(path)]
                         for certificate in certs:
                             revoked.add((
                                 tuple(certificate.get_subject().get_components()),
                                 tuple(certificate.get_issuer().get_components())))
             revoke_state['revoked'] = revoked
コード例 #3
0
ファイル: json_service_manager.py プロジェクト: patolin/txcas
    def _reload(self):
        """
        """
        path = self._path
        filepath = FilePath(path)
        modtime = filepath.getModificationTime()
        if modtime != self._modtime:
            log.msg("[INFO][JSONServiceRegistry] Reloading service registry '%s' ..." % self._path)    
            self._modtime = modtime
            with open(path, 'r') as f:
                self._registry = json.load(f)
            self._apply_defaults()
            self._cache = {}

        reactor.callLater(self.poll_interval, self._reload)
コード例 #4
0
ファイル: client.py プロジェクト: priestd09/backtrac
 def get_index(self, path):
     index = {}
     for root, dirs, files in os.walk(path):
         index[root] = {}
         for f in files:
             path = os.path.join(root, f)
             filepath = FilePath(path)
             try:
                 index[path] = {
                     'mtime': filepath.getModificationTime(),
                     'size': filepath.getsize(),
                 }
             except OSError:
                 # file could be a broken symlink, or deleted mid-scan
                 continue
     return index
コード例 #5
0
ファイル: test_lore.py プロジェクト: svpcom/twisted-cdeferred
    def test_addMtime(self):
        """
        L{tree.addMtime} inserts a text node giving the last modification time
        of the specified file wherever it encounters an element with the
        I{mtime} class.
        """
        path = FilePath(self.mktemp())
        path.setContent("")
        when = time.ctime(path.getModificationTime())

        parent = dom.Element("div")
        mtime = dom.Element("span")
        mtime.setAttribute("class", "mtime")
        parent.appendChild(mtime)

        tree.addMtime(parent, path.path)
        self.assertEqual(mtime.toxml(), '<span class="mtime">' + when + "</span>")
コード例 #6
0
ファイル: test_lore.py プロジェクト: 309972460/software
    def test_addMtime(self):
        """
        L{tree.addMtime} inserts a text node giving the last modification time
        of the specified file wherever it encounters an element with the
        I{mtime} class.
        """
        path = FilePath(self.mktemp())
        path.setContent('')
        when = time.ctime(path.getModificationTime())

        parent = dom.Element('div')
        mtime = dom.Element('span')
        mtime.setAttribute('class', 'mtime')
        parent.appendChild(mtime)

        tree.addMtime(parent, path.path)
        self.assertEqual(mtime.toxml(),
                         '<span class="mtime">' + when + '</span>')
コード例 #7
0
    def getDirectory(self, path='/'):

        self.fs = yield FilePath(path)

        if not self.fs.getPermissions():
            defer.returnValue(False)

        files = []

        for f in self.fs.listdir():
            if f == '/':
                continue

            fp = path+f
            fs = FilePath(fp)

            # dont follow symlinks
            if fs.realpath().path != fp:
                continue

            perm = None
            isdir = fs.isdir()
            size = fs.getsize()
            modified = datetime.utcfromtimestamp(fs.getModificationTime())

            df = DiscoveredFile(
                resource_id=self.data['resource_id'],
                file_path=path,
                file_name=f,
                file_isdir=isdir,
                file_size=size,
                file_modified=modified,
                file_perm=perm
            )

            print '[%s] LIST %s.' % (self.data['resource_name'], fp if not fp.endswith('.') else fp)
            files.append(df)

        defer.returnValue(files)
コード例 #8
0
 def load_revokations(self):
     """
     Load PEM formatted certificates that are no longer trustworthy
     and store the suject and issuer.
     `cert_list` is the path to a file that contains glob-like patterns
     to PEM-formatted certificates.
     """
     revoke_file = self.revoke_file
     revoke_state = self.revoke_state
     if revoke_file is not None:
         last_mod_time = revoke_state['last_mod_time']
         fp = FilePath(revoke_file)
         if not fp.exists():
             return
         mod_time = fp.getModificationTime()
         if last_mod_time is None or mod_time > last_mod_time:
             log.msg(
                 "[INFO] Loading revoked certificate files specified in '{0}'."
                 .format(revoke_file))
             revoke_state['last_mod_time'] = mod_time
             revoked = set([])
             with open(revoke_file) as f:
                 for line in f:
                     pattern = line.rstrip('\r\n')
                     if pattern == '' or pattern.startswith('#'):
                         continue
                     for path in glob.glob(pattern):
                         certs = [
                             pem_cert_to_x509(cert)
                             for cert in pem.parse_file(path)
                         ]
                         for certificate in certs:
                             revoked.add((tuple(certificate.get_subject().
                                                get_components()),
                                          tuple(certificate.get_issuer().
                                                get_components())))
             revoke_state['revoked'] = revoked