fs.info

Container for filesystem resource informations.

class fs.info.Info(raw_info, to_datetime=<function epoch_to_datetime>)[source]

Container for Resource Info.

Resource information is returned by the following methods:

Parameters:
  • raw_info (dict) – A dict containing resource info.
  • to_datetime (callable) – A callable that converts an epoch time to a datetime object. The default uses epoch_to_datetime.
__init__(raw_info, to_datetime=<function epoch_to_datetime>)[source]

Create a resource info object from a raw info dict.

accessed

the resource last access time, or None.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the "details" namespace is not in the Info.
Type:datetime
copy(to_datetime=None)[source]

Create a copy of this resource info object.

created

the resource creation time, or None.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the "details" namespace is not in the Info.
Type:datetime
get(namespace, key, default=None)[source]

Get a raw info value.

Parameters:
  • namespace (str) – A namespace identifier.
  • key (str) – A key within the namespace.
  • default (object, optional) – A default value to return if either the namespace or the key within the namespace is not found.

Example

>>> info = my_fs.getinfo("foo.py", namespaces=["details"])
>>> info.get('details', 'type')
2
gid

the group id of the resource, or None.

Requires the "access" namespace.

Raises:MissingInfoNamespace – if the "access" namespace is not in the Info.
Type:int
group

the group of the resource owner, or None.

Requires the "access" namespace.

Raises:MissingInfoNamespace – if the "access" namespace is not in the Info.
Type:str
has_namespace(namespace)[source]

Check if the resource info contains a given namespace.

Parameters:namespace (str) – A namespace identifier.
Returns:True if the namespace was found, False otherwise.
Return type:bool
is_dir

True if the resource references a directory.

Type:bool
is_file

True if the resource references a file.

Type:bool

True if the resource is a symlink.

Type:bool
is_writeable(namespace, key)[source]

Check if a given key in a namespace is writable.

When creating an Info object, you can add a _write key to each raw namespace that lists which keys are writable or not.

Parameters:
  • namespace (str) – A namespace identifier.
  • key (str) – A key within the namespace.
Returns:

True if the key can be modified, False otherwise.

Return type:

bool

Example

Create an Info object that marks only the modified key as writable in the details namespace:

>>> now = time.time()
>>> info = Info({
...     "basic": {"name": "foo", "is_dir": False},
...     "details": {
...         "modified": now,
...         "created": now,
...         "_write": ["modified"],
...     }
... })
>>> info.is_writeable("details", "created")
False
>>> info.is_writeable("details", "modified")
True
make_path(dir_path)[source]

Make a path by joining dir_path with the resource name.

Parameters:dir_path (str) – A path to a directory.
Returns:A path to the resource.
Return type:str
metadata_changed

the resource metadata change time, or None.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the "details" namespace is not in the Info.
Type:datetime
modified

the resource last modification time, or None.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the "details" namespace is not in the Info.
Type:datetime
name

the resource name.

Type:str
permissions

the permissions of the resource, or None.

Requires the "access" namespace.

Raises:MissingInfoNamespace – if the "access" namespace is not in the Info.
Type:Permissions
size

the size of the resource, in bytes.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the "details" namespace is not in the Info.
Type:int
stem

the name minus any suffixes.

Example

>>> info = my_fs.getinfo("foo.tar.gz")
>>> info.stem
'foo'
Type:str
suffix

the last component of the name (with dot).

In case there is no suffix, an empty string is returned.

Example

>>> info = my_fs.getinfo("foo.py")
>>> info.suffix
'.py'
>>> info2 = my_fs.getinfo("bar")
>>> info2.suffix
''
Type:str
suffixes

a list of any suffixes in the name.

Example

>>> info = my_fs.getinfo("foo.tar.gz")
>>> info.suffixes
['.tar', '.gz']
Type:List
target

the link target (if resource is a symlink), or None.

Requires the "link" namespace.

Raises:MissingInfoNamespace – if the "link" namespace is not in the Info.
Type:str
type

the type of the resource.

Requires the "details" namespace.

Raises:MissingInfoNamespace – if the ‘details’ namespace is not in the Info.
Type:ResourceType
uid

the user id of the resource, or None.

Requires the "access" namespace.

Raises:MissingInfoNamespace – if the "access" namespace is not in the Info.
Type:int
user

the owner of the resource, or None.

Requires the "access" namespace.

Raises:MissingInfoNamespace – if the "access" namespace is not in the Info.
Type:str