def read_dir(paths): paths = get_files(paths) t = time.time() n = 0 for p in paths: f = open_file(p) n += file_length(f) t = time.time() - t print("total size {}B, use time {}s".format(n, t)) return n
def file_info(paths): paths = get_files(paths) for p in paths: f = open_file(p) print(p) num_block = (f.length + CHUNKSIZE)/CHUNKSIZE d = Counter() for i in range(num_block): c = f.get_chunk(i) print("\t%03d %d %015d %s" % (i, c.id, c.length, c.addrs)) d[c.id] = f.length * len(c.addrs) return d
def _get_state(self): for fn in self.files: try: realname = os.path.realpath(fn) with closing(open_file(realname)) as f: if f: yield realname, (f.info.inode, f.info.length, f.info.mtime) else: st = os.stat(realname) yield realname, (st.st_ino, st.st_size, st.st_mtime) except (OSError, Error): pass
def du(paths): paths = get_files(paths) d1 = Counter() d2 = {} t = time.time() for p in paths: f = open_file(p) d = get_sizes(f) d1 += d d2.update(d) t = time.time() - t fmt = "size {} = {}, real size {} = {}, ratio= {}, use time {}s" s1 = sum(d1.values()) s2 = sum(d2.values()) print(fmt.format(s1, str_size(s1), s2, str_size(s2), float(s1)/s2, t))
def open_file(self): return open_file(self.path)