Muscat.Helpers.IO.PathController module

CheckIntegrity(GUI: bool = False)[source]
class PathController[source]

Bases: object

Class to do operation on path and filename. The idea is to store 2 path (for an application). This are class attributes (not instance attributes).

the currentDirectory, defined initially with value of os.getcwd()+os.sep. intended to store the path from where the user execute the application

the workingDirectory, defined initially with value of os.getcwd()+os.sep. intended to store the path of the treated file,

The user can set the currentDirectory with SetCurrentDirectory or SetCurrentDirectoryUsingFile The user can set the workingDirectory with SetWorkingDirectory or SetWorkingDirectoryUsingFile

Then different function are available to recover path, and full path filename on current/working directories.

Note

This class DOES NOT change the working directory of python( value returned by os.getcwd()), this class is intender only for path manipulation.

static GetCurrentDirectory() str[source]

Return the current directory

static GetFullFilenameCurrentDirectory(filename: str) str[source]

Return a absolution path of a filename in the currentDirectory

Parameters:

filename (str) – Path to a file relative to Current Directory

Returns:

the absolute path of filename

Return type:

str

static GetFullFilenameWorkingDirectory(filename: str) str[source]

Return a absolution path of a filename in the workingDirectory

Parameters:

filename (str) – Path to a file relative to Working Directory

Returns:

the absolute path of filename

Return type:

str

static GetFullPathCurrentDirectoryUsingFile(filename: str) str[source]

Return the absolute path of a filename relative to the current directory

If current directory is “/my/current/directory”, and filename is “./test1/output.toto” then: GetFullPathInCurrentDirectoryUsingFile(filename) -> “/my/current/directory/test1”

if filename is an absolute path then this function return path

Parameters:

filename (str) – filename with a relative or absolute path

Returns:

an absolute path

Return type:

str

static GetFullPathWorkingDirectory(pathname: str) str[source]
Return the absolute path of a path relative to the working directory

if pathname is an absolute path then this function return path

Parameters:

pathname (str) – relative (to working directory) or absolute path

Returns:

an absolute path

Return type:

str

static GetWorkingDirectory() str[source]

Return the working directory

static SetCurrentDirectory(folder: str) None[source]

Set the current directory using a path.

Parameters:

folder (str) – path to a folder

static SetCurrentDirectoryUsingFile(folder: str) None[source]

set the current directory using a file os.path

Parameters:

folder (str) – path to a file

static SetWorkingDirectory(folder: str) None[source]

Set the working directory using a path.

Parameters:

folder (str) – path to a folder

static SetWorkingDirectoryUsingFile(file) None[source]

set the working directory using a file path

Parameters:

folder (str) – path to a file

currentDirectory: str = '/home/docs/checkouts/readthedocs.org/user_builds/muscat/checkouts/latest/docs/'
workingDirectory: str = '/home/docs/checkouts/readthedocs.org/user_builds/muscat/checkouts/latest/docs/'
class TemporalChdir(targetPath: str)[source]

Bases: object

class to change directory for a local context. This function use os.chdir to change the current path. The user is responsible of ensuring the path exists and il has the correct permissions At exit the install will restore the path at the creation of the instance.

with TemporalChdir(“c:/my/local/working/path”) :

#do something