Example #1
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
Example #2
0
    def _add_file(self, src_path, file_meta):
        if 'md5' not in file_meta:
            file_meta['md5'] = md5_for_file(src_path)
        if "rawname" in file_meta:
            rawname = file_meta.pop("rawname").pop()
            self.output("add %s\n" % rawname)
        file_meta.update({'sizeInBytes': os.path.getsize(src_path),
                          'create_time': time.time()
                          })
        matcher = {'md5': file_meta['md5']}
        setter = {"$set": file_meta, "$addToSet": {"rawname": rawname}}
        self.db.book.update(matcher, setter, True)

        filename = '%s%s' % (file_meta['md5'], file_meta['ext'])
        dst_file = os.path.join(media_path, filename)
        if not os.path.exists(dst_file):
            shutil.copy(src_path, dst_file)
Example #3
0
    def _add_file(self, src_path, file_meta):
        if 'md5' not in file_meta:
            file_meta['md5'] = md5_for_file(src_path)
        if "rawname" in file_meta:
            rawname = file_meta.pop("rawname").pop()
            self.output("add %s\n" % rawname)
        file_meta.update({
            'sizeInBytes': os.path.getsize(src_path),
            'create_time': time.time()
        })
        matcher = {'md5': file_meta['md5']}
        setter = {"$set": file_meta, "$addToSet": {"rawname": rawname}}
        self.db.book.update(matcher, setter, True)

        filename = '%s%s' % (file_meta['md5'], file_meta['ext'])
        dst_file = os.path.join(media_path, filename)
        if not os.path.exists(dst_file):
            shutil.copy(src_path, dst_file)