dir_ops package

Submodules

dir_ops.base_dir_ops module

class dir_ops.base_dir_ops.BaseDir(*args, **kwargs)[source]

Bases: ParentClass

INSTANCE_METHOD_ATTS = ['path']
STATIC_METHOD_SUFFIX = '_dir'
ascend(level_to_ascend: int = 1) BaseDir[source]

go up a x number directories -> “levels_to_ascend”

static ascend_dir(dir: str, levels_to_ascend: int = 1) str[source]

go up a x number directories -> “levels_to_ascend”

construct(type, *args, **kwargs)[source]
copy(*args, **kwargs) bool[source]
static copy_dir(*args, **kwargs) bool[source]
create(*args, **kwargs) bool[source]
static create_dir(*args, **kwargs) bool[source]
create_parents(*args, **kwargs)[source]

use recursion to travel all the way up the parent directories until we find one that exists, then unfold and create each directory

dir_construct(path='', **kwargs)[source]
exists(*args, **kwargs) bool[source]
static exists_dir(*args, **kwargs)[source]
get_rel(other_Dir: BaseDir) BaseDir[source]

Given a Dir object, find the relative Dir from Dir to self

static get_rel_dir(dir, other_dir) str[source]
get_size(*args, **kwargs)[source]
static get_size_dir(*args, **kwargs)[source]
get_unique_Path(filename: str, **list_contents_Paths_kwargs) str[source]

finds a unique Path for the proposed filename based on the contents of the Directory if file.txt already exists in the dir, return file1.txt or file2.txt, etc

inherited_kwargs = {}
static is_Dir(Object: Any) bool[source]

returns boolean if Object is a Dir

join(*args, **kwargs)[source]
join_Dir(Dir: BaseDir = None, path: str = '') BaseDir[source]
join_Path(Path: BasePath = None, path: str = '') BasePath[source]
static join_dir(dir: str, *other_dirs, **kwargs)[source]

add more dirs to the Dir path

list_contents(*args, print_off: bool = False, **kwargs)[source]
list_contents_Paths(block_dirs: bool = True, block_paths: bool = False, **kwargs) BasePaths[source]
list_files(*args, **kwargs)[source]
static list_files_dir(*args, **kwargs)[source]
list_subfolders(*args, **kwargs)[source]
static list_subfolders_dir(*args, **kwargs)[source]
lowest()[source]
static lowest_dir(dir: str)[source]
open(*args, **kwargs)[source]
static open_dir(*args, **kwargs)[source]
remove(*args, **kwargs)[source]
static remove_dir(*args, **kwargs)[source]
walk(folders_to_skip: List[str] = ['.git'], **kwargs) BasePaths[source]

Walk through all the contents of the directory

walk_contents_Paths(block_dirs: bool = True, block_paths: bool = False, folders_to_skip: List[str] = ['.git'], **kwargs) BasePaths[source]

get all Paths and/or Dirs underneath the entire directory, optional params for returning paths and/or dirs

class dir_ops.base_dir_ops.BaseDirs(*args, given_Dirs=[], given_Paths=[], **kwargs)[source]

Bases: ParentPluralList

create(*args, **kwargs)[source]
export_strings() List[str][source]

Returns all the paths of each Dir/Path contained

inherited_kwargs = {}
static is_Dirs(Object: Any) bool[source]

returns boolean if Object is a Dir

join_Dir(Dir_inst: BaseDir) BasePaths[source]

Joins Dir_inst to each Dir/Path contained in the Object

merge(other_Dirs: Any) None[source]

add all Dir objects from another Dirs instance to self

remove(*args, **kwargs)[source]
class dir_ops.base_dir_ops.BasePath(*args, **kwargs)[source]

Bases: BaseDir

INSTANCE_METHOD_ATTS = ['path']
STATIC_METHOD_SUFFIX = '_path'
static create_path(*args, **kwargs) bool[source]
static exists_path(*args, **kwargs)[source]
static get_ending(path: str) str[source]

returns the file ending from a path

static get_filename(path: str) str[source]

returns the filename (‘file.txt’) from a long path (‘C:/path/to/file.txt’)

get_mtime(*args, **kwargs)[source]
static get_mtime_path(*args, **kwargs) datetime[source]
get_rel(Dir_inst: BaseDir, path='') BasePath[source]

Given a Dir object, find the relative Path from Dir to self

static get_rel_path(path: str, dir: str) str[source]
static get_root(path: str, allow_dots: bool = False) str[source]

returns the root of the filename from a path Dir/a_file1.txt returns “a_file1”

static is_Path(Object: Any) bool[source]

returns boolean if Object is a Dir

path_construct()[source]

Since the Path is different from a Dir, add the extra attiributes

read(*args, **kwargs)[source]
read_json_to_dict(*args, **kwargs)[source]
static read_json_to_dict_path(path, **kwargs) Any[source]
static read_path(path, **kwargs) Any[source]
static remove_path(*args, **kwargs)[source]
rename(*args, **kwargs)[source]
static rename_path(*args, **kwargs)[source]
smart_format(*args, formatting_dict, write=True, **kwargs) str[source]
write(*args, **kwargs)[source]
static write_path(*args, **kwargs) bool[source]
class dir_ops.base_dir_ops.BasePaths(*args, **kwargs)[source]

Bases: BaseDirs

get_rels(Dir_inst) BasePaths[source]

Given a Dir object, find the relative Paths from Dir to the Paths

static is_Paths(Object: Any) bool[source]

returns boolean if Object is a Dir

dir_ops.decorators module

dir_ops.decorators.base_instance_method(method)[source]

instance methods call the corresponding staticmethod Example: Dir_instance.exists(,*) calls Dir.exists_dir( Dir_instance.path,*,** )

dir_ops.decorators.copy_wrap(method)[source]
dir_ops.decorators.create_wrap(method)[source]
dir_ops.decorators.dirs_wrap(method_name, track_success=False)[source]
dir_ops.decorators.download_wrap(method)[source]
dir_ops.decorators.get_mtime_wrap(method)[source]
dir_ops.decorators.get_size_wrap(method)[source]
dir_ops.decorators.inherited_instance_method(method)[source]

instance methods call the corresponding staticmethod Example: Dir_instance.exists(,*) calls Dir.exists_dir( Dir_instance.path,*,** )

dir_ops.decorators.remove_wrap(method)[source]
dir_ops.decorators.rename_wrap(method)[source]
dir_ops.decorators.to_from_wrapper_factory(method, action_str, self, *args, **kwargs)[source]
dir_ops.decorators.upload_wrap(method)[source]

dir_ops.local_dir_ops module

class dir_ops.local_dir_ops.Dir(*args, **kwargs)[source]

Bases: BaseDir

static copy_dir(dir: str, *args, destination: str = '', **kwargs) None[source]
static create_dir(dir: str, *args, **kwargs) None[source]
static exists_dir(dir: str, *args, **kwargs) bool[source]
static get_size_dir(dir: str, *args, **kwargs) float[source]
static list_files_dir(dir: str) List[str][source]
static list_subfolders_dir(dir: str) List[str][source]
static open_dir(dir) None[source]

Opens the dir in the file explorer

static remove_dir(dir: str, *args, **kwargs) None[source]
class dir_ops.local_dir_ops.Dirs(*args, **kwargs)[source]

Bases: BaseDirs

class dir_ops.local_dir_ops.Path(*args, **kwargs)[source]

Bases: Dir, BasePath

Inherits from the Dir class found in Dir.py Path (uppercase P) is a Path class, path (lowercase P) is a string with file absolute path

static copy_path(path: str, *args, destination: str = '', **kwargs) None[source]
static create_path(path: str, *args, **kwargs) None[source]
static exists_path(path: str, *args, **kwargs) bool[source]
static get_mtime_path(path, *args, **kwargs) datetime[source]

get the time of modification as a datetime object

static get_size_path(path, *args, **kwargs) float[source]
import_module(*args, **kwargs) Callable[source]
static import_module_path(path, *args, **kwargs) Callable[source]
static read_path(path, **kwargs) Any[source]

reads from a text file at path, read py_starter.read_text_file() for kwargs

static remove_path(path: str, *args, **kwargs) None[source]
static rename_path(path, *args, destination: str = '', **kwargs) None[source]
static write_path(path, **kwargs) None[source]

writes to a text file at path, read py_starter.write_text_file() for kwargs

class dir_ops.local_dir_ops.Paths(*args, **kwargs)[source]

Bases: Dirs, BasePaths

dir_ops.remote_dir_ops module

class dir_ops.remote_dir_ops.RemoteDir(*args, **kwargs)[source]

Bases: BaseDir

download(*args, **kwargs)[source]
static download_dir(*args, **kwargs)[source]
upload(*args, **kwargs)[source]
static upload_dir(*args, **kwargs)[source]
class dir_ops.remote_dir_ops.RemoteDirs(*args, **kwargs)[source]

Bases: BaseDirs

class dir_ops.remote_dir_ops.RemotePath(*args, **kwargs)[source]

Bases: RemoteDir, BasePath

static download_path(*args, **kwargs)[source]
static upload_path(*args, **kwargs)[source]
class dir_ops.remote_dir_ops.RemotePaths(*args, **kwargs)[source]

Bases: RemoteDirs, BasePaths

dir_ops.utils module

dir_ops.utils.add_prefix_to_paths(prefix_path, relative_paths)[source]

adds prefix to a list of relaive paths

dir_ops.utils.convert_bytes(bytes: int, conversion: str = 'MB') Tuple[Any, Any][source]
dir_ops.utils.create_shortcut(target_Path, shortcut_Dir) None[source]

places a shortcut from target_Path to shortcut_Dir

dir_ops.utils.get_cwd() str[source]

returns current working directory

dir_ops.utils.get_desktop_dir() Any[source]

get the location of the desktop

dir_ops.utils.get_env_var_path_delim() str[source]

Returns the delimitter for the OS’s path environment variables

dir_ops.utils.get_home_dir()[source]
dir_ops.utils.is_dir(path: str) bool[source]

returns a boolean value to check if the path is a directory

dir_ops.utils.is_file(path: str) bool[source]

returns a boolean value to check if the path is a file

dir_ops.utils.join(*items: str) str[source]

joins a list of dirs into a path

dir_ops.utils.join_env_var_paths(paths: List[str]) str[source]

returns ‘C:/Path1;C:/Path2’

dir_ops.utils.path_to_dirs(path: str) List[str][source]

splits a path into directories

dir_ops.utils.print_to_from(print_off: bool, action_str: str, from_str: str, to_str: str)[source]

Copying C:/Users/path/file.txt -> C:/Users/newfile.txt

dir_ops.utils.remove_hanging_slashes(path)[source]

removes ending slashes from paths turns “asdf/asdf//” into “asdf/sadf”

dir_ops.utils.remove_prefix_from_paths(prefix_path, full_paths)[source]

Removes prefix from full paths

dir_ops.utils.replace_delims(path: str, secondary_delim: str = '\\', delim: str = '/') str[source]

turns datadir ile.txt into data/dir/file.txt

dir_ops.utils.split_env_var_paths(string: str) List[str][source]

returns a list of path strings split on the system delimitter

Module contents