Welcome to pytmpdir’s documentation!¶
Read Me¶
pytmpdir¶
A class representing a file system directory, that deletes on garbage collect.
Requirements¶
- Python 3.5
The Directory object can be¶
- Initialised on an existing directory
- Scan that directory
- Be interrogated for the file list
- Create new files
- Open files
It can also be used when a temporary directory of files is needed, that will be garbage collected when it falls out of scope.
This is especially use full when using the tarfile, etc packages.
Usage¶
Creating a directory, that will auto delete when it falls out of scope. For other options, see the documentation.
pytmpdir¶
pytmpdir package¶
Submodules¶
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.
Module contents¶
MIT License¶
Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.