def dump_path(path, prefix="", tab=" ", file=None): if file is None: file = sys.stdout p = Path(path) if p.islink(): print >>file, "%s%s -> %s" % (prefix, p.name, p.read_link()) elif p.isdir(): print >>file, "%s%s:" % (prefix, p.name) for p2 in p.listdir(): dump_path(p2, prefix+tab, tab, file) else: print >>file, "%s%s (%d)" % (prefix, p.name, p.size())
def split_file(path, number_of_files, splitted_file_size, output_file_name, chunk_size, no_increase): path = Path(path) if not splitted_file_size is None: splitted_file_size = get_real_size(splitted_file_size) chunk_size = get_real_size(chunk_size) origin_file_size = path.size() if splitted_file_size and number_of_files is None: if no_increase: number_of_files = int(origin_file_size / splitted_file_size) else: number_of_files = ceil( float(origin_file_size) / splitted_file_size) else: if number_of_files is None: number_of_files = 5 splitted_file_size = origin_file_size / number_of_files if output_file_name is None: output_file_name = path.name new_files_name = '{output_file_name}.part%d'.format( output_file_name=output_file_name) new_files = [ new_files_name % i for i in range(1, int(number_of_files) + 1) ] with open(path, 'rb') as origin_file: file_iter = read_in_chunks(origin_file, chunk_size) for cur_file_name in new_files: is_last = cur_file_name == new_files[-1] cur_file_path = Path(cur_file_name) cur_file_size = 0 with open(cur_file_path, 'wb') as cur_writing_file: while (cur_file_size < splitted_file_size if not is_last else True): try: piece = next(file_iter) except StopIteration: break cur_writing_file.write(piece) cur_file_size += chunk_size
def split_file(path, number_of_files, splitted_file_size, output_file_name, chunk_size, no_increase): path = Path(path) if not splitted_file_size is None: splitted_file_size = get_real_size(splitted_file_size) chunk_size = get_real_size(chunk_size) origin_file_size = path.size() if splitted_file_size and number_of_files is None: if no_increase: number_of_files = int(origin_file_size / splitted_file_size) else: number_of_files = ceil(float(origin_file_size) / splitted_file_size) else: if number_of_files is None: number_of_files = 5 splitted_file_size = origin_file_size / number_of_files if output_file_name is None: output_file_name = path.name new_files_name = '{output_file_name}.part%d'.format(output_file_name=output_file_name) new_files = [new_files_name % i for i in range(1, int(number_of_files)+1)] with open(path, 'rb') as origin_file: file_iter = read_in_chunks(origin_file, chunk_size) for cur_file_name in new_files: is_last = cur_file_name == new_files[-1] cur_file_path = Path(cur_file_name) cur_file_size = 0 with open(cur_file_path, 'wb') as cur_writing_file: while (cur_file_size < splitted_file_size if not is_last else True): try: piece = next(file_iter) except StopIteration: break cur_writing_file.write(piece) cur_file_size += chunk_size
# File Attributes and permissions print("\n*** File Attributes and permissions") # noinspection PyArgumentList print(here.atime()) # Last access time; seconds past epcoh # noinspection PyArgumentList print(here.ctime()) # Last permission or ownership modification; windows is creation time; # noinspection PyArgumentList print(here.isfile()) # Is a file; symbolic links are followed. print(here.isdir()) # Is a directory; symbolic links are followed. # noinspection PyArgumentList print(here.islink()) # Is a symbolic link # noinspection PyArgumentList print(here.ismount()) # Is a mount point; ie the parent is on a different device. # noinspection PyArgumentList print(here.exists()) # File exists; symbolic links are followed. # noinspection PyArgumentList print(here.lexists()) # Same as exists but symbolic links are not followed. # noinspection PyArgumentList print(here.size()) # File size in bytes. print(Path("/foo").isabsolute()) # Is absolute and not relative path # Epoch? print("\n*** gmtime") print(gmtime(0)) # Stat and lstat print("\n*** Stat and lstat") print(here.stat()) # File stat object for size, permissions etc. Symbolic links are followed. print(here.lstat()) # Same as stat but symbolic links are not followed.
# noinspection PyArgumentList print(here.atime()) # Last access time; seconds past epcoh # noinspection PyArgumentList print(here.ctime() ) # Last permission or ownership modification; windows is creation time; # noinspection PyArgumentList print(here.isfile()) # Is a file; symbolic links are followed. print(here.isdir()) # Is a directory; symbolic links are followed. # noinspection PyArgumentList print(here.islink()) # Is a symbolic link # noinspection PyArgumentList print(here.ismount() ) # Is a mount point; ie the parent is on a different device. # noinspection PyArgumentList print(here.exists()) # File exists; symbolic links are followed. # noinspection PyArgumentList print(here.lexists()) # Same as exists but symbolic links are not followed. # noinspection PyArgumentList print(here.size()) # File size in bytes. print(Path("/foo").isabsolute()) # Is absolute and not relative path # Epoch? print("\n*** gmtime") print(gmtime(0)) # Stat and lstat print("\n*** Stat and lstat") print(here.stat( )) # File stat object for size, permissions etc. Symbolic links are followed. print(here.lstat()) # Same as stat but symbolic links are not followed.