cellpy.internals package

Submodules

cellpy.internals.core module

This module contains div classes etc that are not really connected to cellpy.

class cellpy.internals.core.ExternalStatResult(st_size: int = 0, st_mtime: int = 0, st_atime: int = 0, st_ctime: Optional[int] = None)[source]

Bases: object

Mock of os.stat_result.

st_atime: int = 0
st_ctime: Optional[int] = None
st_mtime: int = 0
st_size: int = 0
class cellpy.internals.core.OtherPath(*args, **kwargs)[source]

Bases: Path

A pathlib.Path subclass that can handle external paths.

Additional attributes:

is_external (bool): is True if the path is external. location (str): the location of the external path (e.g. a server name). uri_prefix (str): the prefix of the external path (e.g. scp:// or sftp://). raw_path (str): the path without any uri_prefix or location. original (str): the original path string. full_path (str): the full path (including uri_prefix and location).

Additional methods:

copy (method): a method for copying the file to a local path.

Overrides (only if is_external is True):

glob (method): a method for globbing external paths. rglob (method): a method for ‘recursive’ globbing external paths (max one extra level deep).

absolute() S[source]

Return an absolute version of this path. This function works even if the path doesn’t point to anything.

No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.

property anchor

The concatenation of the drive and root, or ‘’.

as_posix()

Return the string representation of the path with forward (/) slashes.

as_uri() str[source]

Return the path as a uri (e.g. scp://user@server.com/home/data/my_file.txt).

chmod(mode)

Change the permissions of the path, like os.chmod().

copy(destination: Optional[Path] = None, testing=False) Path[source]

Copy the file to a destination.

cwd()[source]

Return a new path pointing to the current working directory (as returned by os.getcwd()).

property drive

The drive prefix (letter or UNC path), if any.

exists(*args, **kwargs) bool[source]

Check if path exists.

expanduser()

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

property full_path: str
glob(glob_str: str, *args, **kwargs) Generator[source]

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

group()[source]

Return the group name of the file gid.

classmethod home()

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

is_absolute()

True if the path is absolute (has both a root and, if applicable, a drive).

is_block_device()

Whether this path is a block device.

is_char_device()

Whether this path is a character device.

is_dir(*args, **kwargs) bool[source]

Check if path is a directory.

property is_external: bool
is_fifo()

Whether this path is a FIFO.

is_file(*args, **kwargs) bool[source]

Check if path is a file.

is_mount()

Check if this path is a POSIX mount point

is_relative_to(*other)

Return True if the path is relative to another path or False.

is_reserved()

Return True if the path contains one of the special names reserved by the system, if any.

is_socket()

Whether this path is a socket.

Whether this path is a symbolic link.

iterdir(*args, **kwargs)[source]

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

joinpath(*args, **kwargs)[source]

Combine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments is anchored).

lchmod(*args, **kwargs)[source]

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Make the target path a hard link pointing to this path.

Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.

listdir(levels: int = 1, **kwargs) Generator[source]

List the contents of the directory.

Parameters

levels (int, optional) – How many sublevels to list. Defaults to 1. If you want to list all sublevels, use listdir(levels=-1). If you want to list only the current level (no subdirectories), use listdir(levels=0).

Returns

Generator of OtherPath objects.

Return type

Generator

property location: str

Return the location of the external path (e.g user@server.com).

lstat()

Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

match(*args, **kwargs)[source]

Return True if this path matches the given pattern.

mkdir(mode=511, parents=False, exist_ok=False)

Create a new directory at this given path.

property name

Return the parent directory of the path.

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)

Open the file pointed by this path and return a file object, as the built-in open() function does.

property original: str
property owner

Return the login name of the file owner.

property parent: S

Return the parent directory of the path.

property parents

A sequence of this path’s logical parents.

property parts

An object providing sequence-like access to the components in the filesystem path.

property pathlike_location: S

Return the location of the external path as a pathlike object.

property raw_path: str
read_bytes()

Open the file in bytes mode, read it, and close the file.

read_text(encoding=None, errors=None)

Open the file in text mode, read it, and close the file.

Return the path to which the symbolic link points.

relative_to(*other)

Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.

rename(target)

Rename this path to the target path.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

replace(target)

Rename this path to the target path, overwriting if that path exists.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

resolve(*args, **kwargs) S[source]

Resolve the path.

rglob(glob_str: str, *args, **kwargs) Generator[source]

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

rmdir()

Remove this directory. The directory must be empty.

property root

The root of the path, if any.

samefile(other_path: Union[str, Path, S]) bool[source]

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

stat(*args, **kwargs)[source]

Return the result of the stat() system call on this path, like os.stat() does.

property stem: str

Return the stem of the path.

property suffix: str

Return the suffix of the path.

property suffixes: List[str]

Return the suffixes of the path.

Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.

touch(mode=438, exist_ok=True)

Create this file with the given access mode, if it doesn’t exist.

Remove this file or link. If the path is a directory, use rmdir() instead.

property uri_prefix: str

Return the uri prefix for the external path (e.g ssh://).

with_name(name: str) S[source]

Return a new path with the name changed.

with_stem(stem: str) S[source]

Return a new path with the stem changed.

with_suffix(suffix: str) S[source]

Return a new path with the suffix changed.

write_bytes(data)

Open the file in bytes mode, write to it, and close the file.

write_text(data, encoding=None, errors=None)

Open the file in text mode, write to it, and close the file.

Module contents