def change_folder(path): if Path.is_absolute(Path(path)): os.chdir(path) else: path = get_absolute_path(path) os.chdir(str(path)) print_debug('change_folder using') print(str(path))
def check_folder_exists(path): if not Path.is_absolute(Path(path)): path = get_absolute_path(path) print_debug('check_folder_exists - Converted to absolute path using') if Path.exists(Path(path)): return True else: return False
def create_folder(path): if check_folder_exists(path): print_warning('create_folder - Folder already exists, nothing done. ') else: if Path.is_absolute(Path(path)): Path.mkdir(Path(path)) else: path = get_absolute_path(path) Path.mkdir(path) print_debug('create_folder using') print(str(path))
def create_initial_files(path, amount, no_filename_gaps): print(path) if not check_folder_exists(path): if not Path.is_absolute(Path(path)): path = get_absolute_path(path) create_folder(path) else: if not Path.is_absolute(Path(path)): path = get_absolute_path(path) print_info('create_files_even using\n' + str(path)) change_folder(path) prn = random.randint(1, 100) for i in range(1, amount + 1): filename = get_filename(i) content = get_file_content(path, filename) if no_filename_gaps: print_debug('create_files - No filename gaps.') print(content) write_file(filename, content) else: if prn >= 50: if i % 2 == 0: print_debug('create_files - Odd filename gaps.') print(content) write_file(filename, content) else: if i % 2 != 0: print_debug('create_files - Even filename gaps.') print(content) write_file(filename, content)
Path.mkdir(Path.cwd() / Path(path_to_convert)) return Path.cwd() / Path(path_to_convert) else: print_error( 'Cannot continue without a valid path, program terminating.') exit(1) print('Enter the file pattern that you want to copy.') file_pattern = input() print('Enter the relative or absolute path where you want to copy from.') source_path = input() print('Enter the relative or absolute path where you want to copy to.') target_path = input() if debugging: print_debug('Printing original input contents.') print(file_pattern) print(source_path) print(target_path) file_pattern = re.compile(r'' + file_pattern) source_path = convert_relative_to_absolute(source_path) target_path = convert_relative_to_absolute(target_path) if debugging: print_debug('Printing updated input contents.') print(file_pattern.pattern) print(source_path) print(target_path) print_info("Copying files matching '" + str(file_pattern) + "' from\n" + str(source_path) + "\nto\n" + str(target_path) + "\n")
file_size = input() if not file_size.isdigit(): print_error('Incorrect file size. Use integers only.') else: break while True: print('Enter how many files to create.') number_to_allocate = input() if not number_to_allocate.isdigit(): print_error('Incorrect amount. Use integers only.') else: break if debugging: print_debug('The file size is ' + file_size) print_debug('The file size unit is ' + file_size_unit) print_debug('The amount of files to allocate space for is ' + number_to_allocate) # Using fallocate to pre-allocate space for each file. https://stackoverflow.com/a/8706714 print_info('Allocating space.') os.chdir(str(work_path)) if debugging: print_debug('Current path is:\n' + str(Path.cwd())) size_units = ['B', 'K', 'M', 'G'] for i in range(int(number_to_allocate) * 2): # For every even number create a file of different size. if i % 2 == 0: random_size_unit = size_units[random.randint(0, len(size_units) - 1)] if random_size_unit != 'B':
def get_absolute_path(path): if Path.is_absolute(Path(path)): return path else: print_debug('get_absolute_path - Returning\n' + str(Path.cwd() / path)) return runtime_path / path
def write_file(filename, content): print_debug('write_file - ' + filename) current_file = open(filename, 'w') current_file.write(str(content)) current_file.close()