def create_bin(path, options=None): """Create Function Function allow to create bin in new location with empty bin. Previous bin location is not deleter. Parameters: path: where to create. options: list of copy politics. Returns: value: 0 - successful, 1 - fail. """ try: # Check if command run in confirm mod and if it's so, ask # user about activity confirmation. if not confirm_question("Try to create bin: \n{}\n".format(path), "yes", options): return 1 # Check if command run in dry mode and if so skip main management # operation and only print info if not bin_config_manager.is_dry_mode(options): user_config_manager.set_property('bin_path', os.path.abspath(path)) bin_config_manager.history_empty() os.mkdir(user_config_manager.get_property('bin_path')) # Print info about what was done while operation get_log().info(INFO_MESSAGES['bin_create'].format( os.path.abspath(path))) return 0 except Exception as e: get_log().error(e) return 1
def move_bin(path, options=None): """Move Function Function allow move bin folder by path with bin history changes. Parameters: path: where to move. options: list of copy politics. Returns: value: 0 - successful, 1 - fail. """ try: # Check if command run in confirm mod and if it's so, ask # user about activity confirmation. if not confirm_question("Try to move bin to: \n{}\n".format(path), "no", options): return 1 # Check if command run in dry mode and if so skip main management # operation and only print info if not bin_config_manager.is_dry_mode(options): clean_path.move(user_config_manager.get_property('bin_path'), os.path.abspath(path)) user_config_manager.set_property('bin_path', os.path.abspath(path)) # Print info about what was done while operation get_log().info(INFO_MESSAGES['bin_move'].format(os.path.abspath(path))) return 0 except Exception as e: get_log().error(e) return 1
def _delete(paths, options=None): """Delete Function Do not use this function outside of module. Function deletes every path of paths. Parameters: paths: what to delete. options: list of delete politics. """ # Go through ecery path and delete it from # src location. for path in paths: clean_path.delete(path, options) if os.path.dirname(path) == user_config_manager.get_property('bin_path'): bin_config_manager.history_del(os.path.basename(path), options) # Print progress of operation get_log().info( INFO_MESSAGES['progress_del'].format( ascii_bar.get_progress_bar( paths.index(path) + 1, len(paths) ), path ) )
def _move_from_bin(paths, options=None): """Copy From Bin Function Do not use this function outside of module. Function allow copy bin files to destination. Parameters: paths: what to copy. options: list of copy politics. """ # Go through every path in paths and move every element # from bin folder for path in paths: # Move obj to src location. clean_path.move( os.path.join( user_config_manager.get_property('bin_path'), bin_config_manager.history_get(path, options)['bin_name'] ), os.path.join( bin_config_manager.history_get(path, options)['src_dir'], bin_config_manager.history_get(path, options)['src_name'], ), options ) # Delete element from history list bin_config_manager.history_del(path, options) # Print Progress bar of operation get_log().info( INFO_MESSAGES['progress_res'].format( ascii_bar.get_progress_bar( paths.index(path) + 1, len(paths) ), path ) )
def restore(paths, options=None): """Restore Function Function allow to restore file/dirs by paths in different mods. Parameters: paths: what to restore. options: list of restore politics. Returns: value: 0 - successful, 1 - fail. """ try: restore_paths = _get_restore_paths(paths, options) # Check if command run in confirm mod and if it's so, ask # user about activity confirmation. if not confirm_question( "Try to restore: \n{}\n".format( "\n".join(map(lambda x: '--' + x, restore_paths)) ), "no", options ): return 1 # Check if command run in dry mode and if so skip main management # operation and only print info if not bin_config_manager.is_dry_mode(options): _move_from_bin(restore_paths, options) # Print info about what was done while operation get_log().info( INFO_MESSAGES['restore'].format('\n '.join(restore_paths)) ) return 0 except Exception as e: get_log().error(e) return 1
def empty_bin(options=None): """Copy Function Function allow to empty bin folder and history too. Parameters: options: list of copy politics. Returns: value: 0 - successful, 1 - fail. """ try: # Check if command run in confirm mod and if it's so, ask # user about activity confirmation. if not confirm_question("Try to empty bin: \n{}\n", "no", options): return 1 # Check if command run in dry mode and if so skip main management # operation and only print info if not bin_config_manager.is_dry_mode(options): history_items = bin_config_manager.get_property('history') # Go through over every single history item and # delete it from history and from actual bin folder for history_item in history_items: bin_config_manager.history_del(history_item['bin_name']) clean_path.delete( os.path.join(user_config_manager.get_property('bin_path'), history_item['bin_name'])) get_log().info(INFO_MESSAGES['progress_del'].format( ascii_bar.get_progress_bar( history_items.index(history_item) + 1, len(history_items)), history_item['bin_name'], )) # Print info about what was done while operation get_log().info(INFO_MESSAGES['bin_empty']) return 0 except Exception as e: get_log().error(e) return 1
def print_bin(options): """Print Bin Function Function print to stdout objects of bin. Parameters: options: list of bin path getting politics. Returns: value: 0 - successful, 1 - fail. """ try: history_list = bin_config_manager.get_property('history') for history_item in history_list: get_log().info(INFO_MESSAGES['list_item'].format( history_item['bin_name'])) get_log().info(INFO_MESSAGES['bin_restore']) return 0 except Exception as e: get_log().error(e) return 1
def get_bin_path(options=None): """Get Bin Path Function Function print to stdout path of bin location or if it's not exists, print error message. Parameters: options: list of bin path getting politics. Returns: value: 0 - successful, 1 - fail. """ try: bin_path = user_config_manager.get_property('bin_path') if bin_path: get_log().info(INFO_MESSAGES['bin_path'].format(bin_path)) else: get_log().warning(ERROR_MESSAGES['bin_not_exists']) return 0 except Exception as e: get_log().error(e) return 1