fileio_interface#
- tools.fileio_interface.concatenate(filelist, concatfile, sepfiles=False)[source]#
DESCRIPTION:
This function concatenates a list of files (filelist) into a single file (concatfile); the respective files are opened in binary mode to increase the applicability of the function.
- Parameters:
- filelist:
List A Python list of file paths to compose the concatenated file path.
- concatfile:
str A Python string specifying the path of the concatenated file created from the input file list.
- filelist:
- Keywords:
- sepfiles:
bool, optional A Python boolean valued variable specifying whether to include a blank line seperator between the contents of the respective files to be concatenated.
- sepfiles:
- Return type:
None
- tools.fileio_interface.copyfile(srcfile, dstfile)[source]#
DESCRIPTION:
This function will create a local copy of a specified source file to user specified destination file location; if the destination file already exists, it will be removed prior to the creation of the destination file.
- Parameters:
- srcfile:
str A Python string defining the path to the source file to be copied.
- dstfile:
str A Python string defining the path to the destination file from which the source file is copied.
- srcfile:
- Return type:
None
- tools.fileio_interface.dircontents(path)[source]#
DESCRIPTION:
This function compiles a content list of the specified directory.
- Parameters:
- path:
str A Python string defining the path to the directory to be parsed.
- path:
- Returns:
- contents:
List A Python list containing the directory contents.
- contents:
- Return type:
List
- tools.fileio_interface.dirpath_tree(path)[source]#
DESCRIPTION:
This function checks whether the directory tree (path) exists; if not an attempt will be made to build it.
- Parameters:
- path:
str A Python string specifying the directory tree path to be created if it does not (yet) exist.
- path:
- Return type:
None
- tools.fileio_interface.fileexist(path)[source]#
DESCRIPTION:
This function will ingest a file-path and check whether the respective file-path exists; this function is a wrapper around os.path.isfile.
- Parameters:
- path:
str A Python string defining the path to a respective file.
- path:
- Returns:
- exist:
bool A Python boolean variable specifying whether the respective file-path (path) exists.
- exist:
- Return type:
bool
- tools.fileio_interface.filepermission(path, permission)[source]#
DESCRIPTION:
This function defines the permissions for a specified file-path.
- Parameters:
- path:
str A Python string defining the path to a respective file.
- permission:
int A Python integer specifying the UNIX file permissions.
- path:
- Return type:
None
- tools.fileio_interface.filesize(path)[source]#
DESCRIPTION:
This function ingests a file-path and obtains the size of the file, in bytes; the respective ‘typical’ file size descriptions, namely mega-bytes (MB), giga-bytes (GB), and tera-bytes (TB), are computed and returned.
- Parameters:
- path:
str A Python string defining the path to a respective file.
- path:
- Returns:
- bytes_path:
int A Python integer specifying the file size in bytes.
- megabytes_path:
int A Python integer specifying the file size in mega-bytes (MB).
- gigabytes_path:
int A Python integer specifying the file size in giga-bytes (GB).
- terabytes_path:
int A Python integer specifying the file size in tera-bytes (TB).
- bytes_path:
- Return type:
Tuple[int,int,int,int]
- tools.fileio_interface.makedirs(path, force=False)[source]#
DESCRIPTION:
This function is a wrapper around os.makedirs and will build the directory tree (if necessary).
- Parameters:
- path:
str A Python string defining the path to the directory to be constructed.
- path:
- Keywords:
- force:
bool, optional A Python boolean variable indicating whether any previous directories should be forcibly removed prior to constucting the directory tree.
- force:
- Return type:
None
- tools.fileio_interface.removefiles(filelist)[source]#
DESCRIPTION:
This function ingests a list of filenames; the function then checks whether the respective filename exists and if so it removes it.
- Parameters:
- filelist:
List A Python list containing a list of files to be removed.
- filelist:
- Return type:
None
- tools.fileio_interface.rename(srcfile, dstfile)[source]#
DESCRIPTION:
This function will rename a file in accordance with the specifications; this function may also be used to move and rename files between different file paths.
- Parameters:
- srcfile:
str A Python string defining the path to the source file to be renamed/moved.
- dstfile:
str A Python string defining the path to the destination file from which the source file is to be renamed/moved.
- srcfile:
- Return type:
None
- tools.fileio_interface.rmdir(path)[source]#
DESCRIPTION:
This function will attempt to remove the specified path. the path does not exist, this function does nothing.
- Parameters:
- path:
str A Python string containing the path to the directory to be removed.
- path:
- Return type:
None
- tools.fileio_interface.symlink(srcfile, dstfile)[source]#
DESCRIPTION:
This function will create a symbolic link from a specified source file to a specified destination file; if the destination file already exists, it will be removed prior to the creation of the symbolic link.
- Parameters:
- srcfile:
str A Python string defining the path to the source file to be symbolically linked.
- dstfile:
str A Python string defining the path to the destination file from which the source file is to be symbolically linked.
- srcfile:
- Return type:
None
- tools.fileio_interface.touch(path)[source]#
DESCRIPTION:
This function emulates the POSIX UNIX touch application.
- Parameters:
- path:
str A Python string specifying the file path for which to apply the UNIX touch application.
- path:
- Return type:
None
- tools.fileio_interface.virtual_file(delete=True)[source]#
DESCRIPTION:
This function opens (i.e., creates) a temporary (e.g., virtual) file beneath /tmp to be utilized by the respective calling application; the open virtual file path may be closed in the calling script using os.unlink().
- Keywords:
- delete:
bool, optional A Python boolean valued variable specifying whether to maintain the respective virtual file path beneath /tmp; if False the downstream application should call close_virtual_file (see above) following the respective application.
- delete:
- Returns:
- file_obj:
NamedTemporaryFile A Python NamedTemporaryFile object containing the virtual file path attributes.
- file_obj:
- Return type:
NamedTemporaryFile