pytmpdir.Directory module¶
-
class
pytmpdir.Directory.
DirSettings
¶ Bases:
object
Directory Settings
User configuration settings.
-
defaultDirChmod
= 448¶
-
tmpDirPath
= '/tmp'¶
-
-
class
pytmpdir.Directory.
Directory
(initWithDir: bool=None, autoDelete: bool=True, inDir: str=None)¶ Bases:
object
Functions as a directory object to extract, archive and pass around code. Auto deletes when the directory falls out of scope.
-
clone
(autoDelete: bool=True) → 'Directory'¶ Clone
Recursively copy a directory tree. Removes the destination directory as the destination directory must not already exist.
@param autoDelete: Used to clean up files on completion. Default as True. @type autoDelete: Boolean @return: The cloned directory.
-
createFile
(path: str='', name: str=None, pathName: str=None) → 'File'¶ Create File
Creates a new file and updates file dictionary.
@param path: File path. Defaults as empty string. @param name: File name to be used if passed. @param pathName: Joined file name and path to be used if passed. @type path: String @type name: String @type pathName: String @return: Created file.
-
createHiddenFolder
() → 'File'¶ Create Hidden Folder
Create a hidden folder. Raise exception if auto delete isn’t True.
@return: Created folder.
-
files
¶ Files
@return: A list of the Directory.File objects.
-
getFile
(path: str='', name: str=None, pathName: str=None) → 'File'¶ Get File
Get File name corresponding to a path name.
@param path: File path. Default as empty string. @param name: File name to be used if passed. @param pathName: Joined file name and path to be used if passed. @type path: String @type name: String @type pathName: String @return: Specific file from dictionary.
-
pathNames
¶ Path Names
@return: A list of path + name of each file, relative to the root directory.
-
paths
¶ Paths
@return: A list of the paths, effectively a list of relative directory names.
-
scan
() → ['File']¶ Scan
Scan the directory for files and folders and update the file dictionary.
@return: List of files
-
-
class
pytmpdir.Directory.
File
(directory: pytmpdir.Directory.Directory, path: str='', name: str=None, pathName: str=None, exists: bool=False)¶ Bases:
object
-
delete
()¶ Delete
Deletes directory and drops the file name from dictionary. File on file system removed on disk.
-
isContentText
¶ Is Content Text
Determine if the file contains text.
@return: True if file contains text.
-
mTime
¶ Return the last modification time of a file, reported by os.stat().
@return: Time as string.
-
name
¶ Name
Determines working directory.
@return: Directory name as string.
-
open
(append: bool=False, write: bool=False)¶ Open
Pass arguments and return open file.
@param append: Open for writing, appending to the end of the file if it exists. Default as False. @param write: Open for writing, truncating the file first. Default as False. @type append: Boolean @type write: Boolean @return: Open file function.
-
path
¶ Path
Determines directory name.
@return: Path as string.
-
pathName
¶ Path Name
Returns stored path name.
@return: Path Name as string.
-
realPath
¶ Real Path
Get path name.
@return: Path Name as string.
-
remove
()¶ Remove
Removes the file from the Directory object, file on file system remains on disk.
-
sanitise
(pathName: str) → str¶ Sanitise
Clean unwanted characters from the pathName string.
@param pathName: Path name variable. @type pathName: String @return: Path name as string.
-
size
¶ Size
Determines size of directory.
@return: Total size, in bytes.
-
-
exception
pytmpdir.Directory.
FileClobberError
¶ Bases:
Exception
File Clobber Error
Raise Exception if path does not exist.
-
exception
pytmpdir.Directory.
FileDisappearedError
¶ Bases:
Exception
File Disappeared Error
Raise Exception if file does not exist .
-
pytmpdir.Directory.
is_binary_string
(bytesVariable)¶ Is Binary String
Determines if the input variable contains specific ASCII characters.
@param bytesVariable: Input variable being checked if string. @return: True if variable is string.