protonfs.usage.paths module¶
Drive path helpers and du target resolution.
Drive paths are /-separated; a literal / inside a node name is written \/ and a
literal backslash \\. resolve_target() maps a du argument (a Drive path or a
local path inside a protonfs store) to a Drive path.
Added in version 3.4.0.
- protonfs.usage.paths.DU_SECTIONS = frozenset({'devices', 'my-files'})¶
Sections
ducan analyse.
- protonfs.usage.paths.SECTIONS = frozenset({'albums', 'devices', 'my-files', 'photos', 'photos-shared-by-me', 'photos-shared-with-me', 'photos-trash', 'shared-by-me', 'shared-with-me', 'trash'})¶
Top-level Drive sections the CLI knows.
- class protonfs.usage.paths.Target(remote, store_root)[source]¶
Bases:
objectA resolved
dutarget.- Variables:
remote – Normalised Drive path.
store_root – The local store root it was derived from, or
Nonefor a Drive path given directly.
Added in version 3.4.0.
- exception protonfs.usage.paths.TargetError[source]¶
Bases:
ValueErrorA
dutarget could not be resolved to a supported Drive path.Added in version 3.4.0.
- protonfs.usage.paths.child_path(parent, name, uid, decrypted)[source]¶
Return the escaped Drive path of a listed child of
parent.Same as
join(parent, node_segment(name, uid, decrypted)).- Parameters:
- Return type:
- Returns:
the child’s escaped Drive path.
Added in version 3.4.0.
- protonfs.usage.paths.escape_name(name)[source]¶
Return
nameescaped for use as one Drive path segment. :rtype:strAdded in version 3.4.0.
- protonfs.usage.paths.expand_pattern(pattern, children)[source]¶
Return the Drive paths matching a Drive path whose segments may hold glob patterns.
The segments before the first pattern are taken as they are; from there, each level is matched against a listing of the folders matched so far, so only the pattern’s literal parent (and, for a pattern in an earlier segment, the folders it matches) is listed. A pattern segment never crosses
/, as in a shell. Within one listing, a name equal to the segment wins over glob matches, so a folder calledrun[7]is not taken for a pattern; segments before the last match folders only.- Parameters:
- Return type:
- Returns:
the matching escaped Drive paths, sorted; empty when nothing matches. A pattern with no glob character returns itself, normalised, without a listing.
Added in version 3.4.0.
- protonfs.usage.paths.has_glob(text)[source]¶
Return whether
textholds a glob metacharacter (*,?or[). :rtype:boolAdded in version 3.4.0.
- protonfs.usage.paths.is_remote(arg)[source]¶
Return whether
argis a Drive path, i.e. starts with/and, if not/itself, its first segment is a known Drive section. :rtype:boolAdded in version 3.4.0.
- protonfs.usage.paths.is_within(path, base)[source]¶
Return whether
pathequalsbaseor lies below it (whole segments only). :rtype:boolAdded in version 3.4.0.
- protonfs.usage.paths.join(parent, segment)[source]¶
Return the Drive path of the child
segment(an unescaped name) underparent. :rtype:strAdded in version 3.4.0.
- protonfs.usage.paths.node_segment(name, uid, decrypted)[source]¶
Return the plain (unescaped) path segment that addresses a listed node.
That is
name, or the nodeuidwhen the name could not be decrypted (nameitself if the uid is unknown).- Parameters:
- Return type:
- Returns:
the segment, ready for
join().
Added in version 3.4.0.
- protonfs.usage.paths.parent_of(path)[source]¶
Return the Drive path of the parent of
path, orNonefor/. :rtype:str|NoneAdded in version 3.4.0.
- protonfs.usage.paths.relative(path, base)[source]¶
Return
pathrelative tobasewith unescaped segments joined by/.- Parameters:
- Return type:
- Returns:
""whenpath == base.- Raises:
ValueError – If
pathis not withinbase.
Added in version 3.4.0.
- protonfs.usage.paths.resolve_target(arg, cwd)[source]¶
Resolve a
duargument to aTarget.- Parameters:
- Return type:
- Returns:
The target;
store_rootis set only for local arguments. The local path need not exist.- Raises:
TargetError – If a Drive path is outside
/,/my-filesand/devices, or a local path is not inside a protonfs store.
Added in version 3.4.0.