guibot.fileresolver module

class guibot.fileresolver.FileResolver[source]

Bases: object

Handler for currently used target paths or sources of targets with a desired name.

The methods of this class are shared among all of its instances.

add_path(directory)[source]

Add a path to the list of currently accessible paths if it wasn’t already added.

Parameters:directory (str) – path to add
remove_path(directory)[source]

Remove a path from the list of currently accessible paths.

Parameters:directory (str) – path to add
Returns:whether the removal succeeded
Return type:bool
clear()[source]

Clear all currently accessible paths.

search(filename, restriction='', silent=False)[source]

Search for a filename in the currently accessible paths.

Parameters:
  • filename (str) – filename of the target to search for
  • restriction (str) – simple string to restrict the number of paths
  • silent (bool) – whether to return None instead of error out
Returns:

the full name of the found target file or None if silent and no file was found

Return type:

str or None

Raises:

FileNotFoundError if no such file was found and not silent

__iter__()[source]
__len__()[source]
class guibot.fileresolver.CustomFileResolver(*paths)[source]

Bases: object

Class to be used to search for files inside certain paths.

Inside the context of an instance of this class, the paths in the shared list in FileResolver will be temporarily replaced by the paths passed to the constructor of this class. This means that any call to FileResolver.search() will take only these paths into account.

__init__(*paths)[source]

Create the class with the paths that the search will be restricted to.

Parameters:paths – list of paths that the search will use
__enter__()[source]

Start this context.

Returns:instance of the file resolver that can be used to search files
Return type:py:class:FileResolver

The paths used by the py:class:FileResolver class will be replaced by the paths used to initialize this class during the duration of this context.

__exit__(*args)[source]

Exit this context and restore the original paths.

Parameters:args – default args passed when exiting context