Ejemplo n.º 1
0
    def add_path(self, src_path):
        """add file/dir and copy files.

        @src_path: unicode encoding is required
        @ext_pool: startswith . and separated by ,
        @ignore_hidden: boolen

        """
        if not os.path.exists(src_path):  # not exists
            return None

        # common check
        # sensitive information

        if os.path.isfile(src_path):  # file
            rawname, ext = os.path.splitext(os.path.basename(src_path))
            if not ext or ext not in self.ext_pool:  # file extension check
                return 0
            file_meta = {'rawname': [rawname],
                         'ext': ext
                         }
            self._add_file(src_path, file_meta)
            return 1
        else:  # dir
            added = 0
            # ignore log/.git etc
            tar_path = set(os.listdir(src_path)) - ignore_seq
            for rel_path in tar_path:
                abs_path = os.path.join(src_path, rel_path)
                if not self.ignore_hidden or not is_hiden(abs_path):
                    # ignore hidden
                    added += self.add_path(abs_path) or 0
            return added
Ejemplo n.º 2
0
    def add_path(self, src_path):
        """add file/dir and copy files.

        @src_path: unicode encoding is required
        @ext_pool: startswith . and separated by ,
        @ignore_hidden: boolen

        """
        if not os.path.exists(src_path):  # not exists
            return None

        # common check
        # sensitive information

        if os.path.isfile(src_path):  # file
            rawname, ext = os.path.splitext(os.path.basename(src_path))
            if not ext or ext not in self.ext_pool:  # file extension check
                return 0
            file_meta = {'rawname': [rawname], 'ext': ext}
            self._add_file(src_path, file_meta)
            return 1
        else:  # dir
            added = 0
            # ignore log/.git etc
            tar_path = set(os.listdir(src_path)) - ignore_seq
            for rel_path in tar_path:
                abs_path = os.path.join(src_path, rel_path)
                if not self.ignore_hidden or not is_hiden(abs_path):
                    # ignore hidden
                    added += self.add_path(abs_path) or 0
            return added
Ejemplo n.º 3
0
    def scan_path(self, src_path):
        """scan path to detect target files

        @src_path: unicode encoding is required"""
        if not os.path.exists(src_path):  # not exists
            return None

        if os.path.isfile(src_path):  # file
            rawname, ext = os.path.splitext(os.path.basename(src_path))
            if not ext or ext not in self.ext_pool:  # file extension check
                return 0
            file_meta = {'rawname': [rawname],
                         'ext': ext,
                         'md5': util.md5_for_file(src_path),
                         'bytes': os.path.getsize(src_path),
                         }
            wx.CallAfter(self.window.file_found, src_path, file_meta['md5'])
            return self.file_hdlr(src_path, file_meta) or 0
        else:  # dir
            added = 0
            # ignore log/.git etc
            tar_path = set(os.listdir(src_path)) - self.ignore_seq
            self.cnt_scanned += len(tar_path)
            wx.CallAfter(self.window.file_scanned, self.cnt_scanned)
            for rel_path in tar_path:
                if self.stopFlag:
                    return added
                abs_path = os.path.join(src_path, rel_path)
                if self.ignore_hidden and util.is_hiden(abs_path):
                    continue  # ignore hidden
                else:
                    added += self.scan_path(abs_path) or 0
            return added