Skip to main content

Collection of utility functions and classes to manage temporary data.

Project description

jk_temporary

Introduction

This python module is a collection of utility functions and classes to manage temporary data.

Information about this module can be found here:

The functions this module provides

This module provides the following functions:

#
# Create a path for a temporary file or directory.
#
# @param		string baseDirPath		The base directory the file should reside in.
# @param		string prefix			A prefix to prepend the random file (or directory) name part.
# @param		int randomNameLength	The length in characters of the random file (or directory) name part to create.
# @param		string postfix			A postfix to append the random file (or directory) name part.
# @return		string					Returns a file (or directory) path. No checking is performed if this file or directory already exists.
# 										This method just creates the path.
#
def createRandomFilePath(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '')
#
# Create a unique new temporary directory.
#
# @param		string baseDirPath		The directory that serves as a parent for the new directory to create.
# @param		string prefix			A prefix to prepend the random directory name part.
# @param		int randomNameLength	The length in characters of the random directory name part to create.
# @param		string postfix			A postfix to append the random directory name part.
# @param		int dirMode				The UNIX/Linux mode the directory should have on creation.
#										This is 0700 by default to ensure that other users can not read or write to the new directory.
# @return		string					Returns a unique path to a directory that just has been created.
#
def createTempDir(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '', dirMode = 0o700)
#
# Create a unique new temporary file ready for later writing.
# Please note that temporary file names are generated using a RNG. That implies that if you do not write
# to that file after a call to this function an additional call to <c>createTempFilePath()</c> could produce the same
# file name again. If <c>randomNameLength</c>
# is large enough this is quite unlikely and not a real problem, but you should recognize that at least in
# theory this phenomenon can occur.
#
# @param		string baseDirPath		The directory that serves as a parent for the new directory to create.
# @param		int randomNameLength	The length in characters of the random file name part to create.
# @param		string prefix			A prefix to prepend the random file name part.
# @param		string postfix			A postfix to append the random file name part.
# @param		int fileMode			The UNIX/Linux mode the file should have on creation.
#										This is 0600 by default to ensure that other users can not read or write to the new file.
# @return		string					Returns  the unique path to a file that just has been created.
#
def createTempFilePath(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '', fileMode = 0o600)
#
# Create a unique new temporary file ready for later writing.
#
# @param		string baseDirPath		The directory that serves as a parent for the new directory to create.
# @param		int randomNameLength	The length in characters of the random file name part to create.
# @param		string prefix			A prefix to prepend the random file name part.
# @param		string postfix			A postfix to append the random file name part.
# @param		int fileMode			The UNIX/Linux mode the file should have on creation.
#										This is 0600 by default to ensure that other users can not read or write to the new file.
# @return		string					Returns  the unique path to a file that just has been created.
#
def createTempFile(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '', fileMode = 0o600)
#
# Create a unique new temporary file ready for immediate writing.
#
# @param		string baseDirPath		The directory that serves as a parent for the new directory to create.
# @param		int randomNameLength	The length in characters of the random file name part to create.
# @param		string prefix			A prefix to prepend the random file name part.
# @param		string postfix			A postfix to append the random file name part.
# @param		int fileMode			The UNIX/Linux mode the file should have on creation.
#										This is 0600 by default to ensure that other users can not read or write to the new file.
# @return		tuple					Returns a tuple consisting of two elements:
#										- the unique path to a file that just has been created
#										- the open file handle
#
def createTempFileUTF8(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '', fileMode = 0o600)
#
# Create a unique new temporary file ready for immediate writing.
#
# @param		string baseDirPath		The directory that serves as a parent for the new directory to create.
# @param		int randomNameLength	The length in characters of the random file name part to create.
# @param		string prefix			A prefix to prepend the random file name part.
# @param		string postfix			A postfix to append the random file name part.
# @param		int fileMode			The UNIX/Linux mode the file should have on creation.
#										This is 0600 by default to ensure that other users can not read or write to the new file.
# @return		tuple					Returns a tuple consisting of two elements:
#										- the unique path to a file that just has been created
#										- the open file handle
#
def createTempFileBinary(baseDirPath = "/tmp", prefix = 'tmp_', randomNameLength = 32, postfix = '', fileMode = 0o600)

The object TempDir this module provides

This module provides the class TempDir that contains the following methods:

#
# Constructor method.
#
# @param		string	baseDirPath					The directory that serves as a parent for the new files and directories to create.
# @param		string	namePrefix					A prefix to prepend the random file name part. The default is: "<c>tmp-</c>".
# @param		string	namePostfix					A postfix to append the random file name part. The default is: <c>None</c>.
# @param		string	defaultExtension			A file extension to append the random file name part
#													after the postfix). This applies to file names only. the default is: <c>None</c>.
# @param		int	randomNameLength				The length in characters of the random file name part to create.
# @param		int	defaultAccessModeFiles			The UNIX/Linux mode files should have on creation. This is 0600 by default to
#													ensure that other users can not read or write to the new file.
# @param		int	defaultAccessModeDirectories	The UNIX/Linux mode directories should have on creation. This is 0700 by default
#													to ensure that other users can not read or write to the new directory.
#
def __init__(self,
	baseDirPath = '/tmp', namePrefix = 'tmp-', namePostfix = None, defaultExtension = None,
	randomNameLength = 32, defaultAccessModeFiles = 0o600, defaultAccessModeDirectories = 0o700)
#
# Remove all files in the temporary directory. Please note that temporary directories remain untouched!
#
def clear(self)
#
# Create a new file path.
# Please note that temporary file names are generated using a RNG. That implies that if you do not write
# to that file after a call to this method an additional call to <c>createFilePath()</c> could produce the same
# file name again. If <c>randomNameLength</c>
# is large enough this is quite unlikely and not a real problem, but you should recognize that at least in
# theory this phenomenon can occur.
#
# @param		string extension		An optional file name extension. If you do not specify anything here the default
#										extension will be used as specified during construction.
# @return		string					Returns the full qualified file path that furtheron can be used for writing.
#
def createFilePath(self, extension = None)
#
# Create a new directory path.
# Please note that temporary directory names are generated using a RNG. That implies that if you do not create
# that directory after a call to this method an additional call to <c>createFilePath()</c> could produce the same
# directory name again. If <c>randomNameLength</c>
# is large enough this is quite unlikely and not a real problem, but you should recognize that at least in
# theory this phenomenon can occur.
#
# @return		string					Returns the full qualified file path that furtheron can be used for writing.
#
def createDirPath(self)
#
# Create a new temporary file.
#
# @param		string extension		An optional file name extension. If you do not specify anything here the default
#										extension will be used as specified during construction.
# @param		int accessMode			An optional mode value that defines basic access rights for the file.
# @return		string					Returns  the unique path to a file that just has been created.
#
def createFile(self, extension = None, accessMode = None)
#
# Create a new temporary file.
#
# @param		string extension		An optional file name extension. If you do not specify anything here the default
#										extension will be used as specified during construction.
# @param		int accessMode			An optional mode value that defines basic access rights for the file.
# @return		(string, handle)		Returns a tuple: The full qualified file path and the file handle that can be used for writing.
#
def createFileBinary(self, extension = None, accessMode = None)
#
# Create a new temporary file.
#
# @param		string extension		An optional file name extension. If you do not specify anything here the default
#										extension will be used as specified during construction.
# @param		int accessMode			An optional mode value that defines basic access rights for the file.
# @return		(string, handle)		Returns a tuple: The full qualified file path and the file handle that can be used for writing.
#
def createFileUTF8(self, extension = None, accessMode = None)

Contact information

This is Open Source code. That not only gives you the possibility of freely using this code it also allows you to contribute. Feel free to contact the author(s) of this software listed below, either for comments, collaboration requests, suggestions for improvement or reporting bugs:

License

This software is provided under the following license:

  • Apache Software License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jk_temporary-0.2021.12.6.tar.gz (10.2 kB view details)

Uploaded Source

File details

Details for the file jk_temporary-0.2021.12.6.tar.gz.

File metadata

  • Download URL: jk_temporary-0.2021.12.6.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.10

File hashes

Hashes for jk_temporary-0.2021.12.6.tar.gz
Algorithm Hash digest
SHA256 cb23e9ead37656aa1b9f4413845ce141858a3e04b57505775d55adec8fd232a5
MD5 ff6737515fc1491ff20b0ca4711bee7e
BLAKE2b-256 9c61e1411fa736cb39700511d8597e2f34a7852c225f3725d04735433dccee67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page