Stash Software API  2.0.0
Public Member Functions | Static Public Member Functions | List of all members
sFileSystem.fileLib.File Class Reference

[ CLASS ] - Operate on files. More...

Inheritance diagram for sFileSystem.fileLib.File:
sFileSystem.jsonFileLib.JSONFile sFileSystem.templateFileLib.TemplateFile sStashApp.stashAppLib.StashAppFile

Public Member Functions

def __init__ (self, absFile=None)
 Constructor. More...
 
def __str__ (self)
 String representation. More...
 
def asStr (self)
 Get string representation. More...
 
def asDict (self)
 Get file information as dict instance. More...
 
def setFile (self, absFile)
 Set file. More...
 
def update (self)
 Update information of the file in case it has been altered. More...
 
def exists (self)
 Check whether the file exists. More...
 
def rename (self, newName)
 Rename the file. More...
 
def copy (self, destinationFile, overwrite=False)
 Copy the file. More...
 
def copyToPath (self, destinationPath, overwrite=False)
 Copy the file to given path. More...
 
def remove (self, raiseException=False)
 Remove the file. More...
 
def write (self, line, append=True)
 Write given line into the file. More...
 
def writeLines (self, lines, append=True)
 Write given lines into the file. More...
 
def read (self)
 Read content of the file. More...
 
def readLines (self)
 Read lines. More...
 
def lineCount (self)
 Get line count of the file. More...
 
def create (cls, absFile, overwrite=False, binary=False)
 Create a file and return a sFileSystem.fileLib.File instance for it. More...
 
Properties
def file (self)
 Absolute path of the file. More...
 
def directory (self)
 Directory where the file is located in. More...
 
def fileName (self)
 Name of the file with it's extension. More...
 
def baseName (self)
 Name of the file without extension, base name. More...
 
def extension (self)
 File's extension. More...
 
def size (self)
 File size in bytes. More...
 
def sizeStr (self)
 File size as human readable string. More...
 
def content (self)
 Content of the file. More...
 

Static Public Member Functions

def fileExists (absFile)
 Check whether the given file exists. More...
 
def getFileSizeStr (size, precision=2)
 Get given byte size in human readable string. More...
 
def replaceExtension (absFile, newExtension)
 Replace given files extension with given extension. More...
 

Detailed Description

[ CLASS ] - Operate on files.

Constructor & Destructor Documentation

◆ __init__()

def sFileSystem.fileLib.File.__init__ (   self,
  absFile = None 
)

Constructor.

Parameters
absFile[ str | None | in ] - Absolute path of a file.
Exceptions
N/A
Returns
None - None.

Member Function Documentation

◆ __str__()

def sFileSystem.fileLib.File.__str__ (   self)

String representation.

Exceptions
N/A
Returns
str - String representation.

◆ file()

def sFileSystem.fileLib.File.file (   self)

Absolute path of the file.

Exceptions
N/A
Returns
str - File.

◆ directory()

def sFileSystem.fileLib.File.directory (   self)

Directory where the file is located in.

Exceptions
N/A
Returns
str - Directory.

◆ fileName()

def sFileSystem.fileLib.File.fileName (   self)

Name of the file with it's extension.

Exceptions
N/A
Returns
str - Value.

◆ baseName()

def sFileSystem.fileLib.File.baseName (   self)

Name of the file without extension, base name.

Exceptions
N/A
Returns
str - Base name.

◆ extension()

def sFileSystem.fileLib.File.extension (   self)

File's extension.

Exceptions
N/A
Returns
str - Extension.

◆ size()

def sFileSystem.fileLib.File.size (   self)

File size in bytes.

Exceptions
N/A
Returns
int - Size.

◆ sizeStr()

def sFileSystem.fileLib.File.sizeStr (   self)

File size as human readable string.

Exceptions
N/A
Returns
str - Human readable size.

◆ content()

def sFileSystem.fileLib.File.content (   self)

Content of the file.

Exceptions
N/A
Returns
str - If read method is used to read the content.
list fo str - If readLines method is used to read the content.

◆ asStr()

def sFileSystem.fileLib.File.asStr (   self)

Get string representation.

Exceptions
N/A
Returns
str - String representation.

◆ asDict()

def sFileSystem.fileLib.File.asDict (   self)

Get file information as dict instance.

Exceptions
N/A
Returns
dict - Keys are; file, directory, fileName, baseName, extension, size, sizeStr.

◆ setFile()

def sFileSystem.fileLib.File.setFile (   self,
  absFile 
)

Set file.

Parameters
absFile[ str | None | in ] - Absolute path of a file.
Exceptions
N/A
Returns
bool - Result, returns False is the file doesn't exist, True otherwise.

◆ update()

def sFileSystem.fileLib.File.update (   self)

Update information of the file in case it has been altered.

Exceptions
N/A
Returns
bool - Result, returns False is the file doesn't exist.

◆ exists()

def sFileSystem.fileLib.File.exists (   self)

Check whether the file exists.

Exceptions
sFileSystem.exceptionLib.FileIsNotSet- If no file is set.
Returns
bool - Result, returns False is the file doesn't exist, True otherwise.

◆ rename()

def sFileSystem.fileLib.File.rename (   self,
  newName 
)

Rename the file.

Parameters
newName[ str | None | in ] - New name of the file without the path.
Exceptions
sFileSystem.exceptionLib.FileAlreadyExists- If a file with given newName already exists.
Returns
bool - Result.

◆ copy()

def sFileSystem.fileLib.File.copy (   self,
  destinationFile,
  overwrite = False 
)

Copy the file.

Method will create the destination path if it doesn't exist.

Parameters
destinationFile[ str | None | in ] - Destination file with absolute path.
overwrite[ bool | False | in ] - Whether to overwrite existing file.
Exceptions
sFileSystem.exceptionLib.FileDoesNotExist- If source file doesn't exist.
sFileSystem.exceptionLib.FileAlreadyExists- If destination file exists and overwrite argument provided False.
Returns
str - Absolute path of copied file.

◆ copyToPath()

def sFileSystem.fileLib.File.copyToPath (   self,
  destinationPath,
  overwrite = False 
)

Copy the file to given path.

File name will be intact.

Method will create the destination path if it doesn't exist.

Parameters
destinationPath[ str | None | in ] - Absolute path.
overwrite[ bool | False | in ] - Whether to overwrite existing file.
Exceptions
sFileSystem.exceptionLib.FileDoesNotExist- If source file doesn't exist.
sFileSystem.exceptionLib.FileAlreadyExists- If destination file exists and overwrite argument provided False.
Returns
str - Absolute path of the copied file.

◆ remove()

def sFileSystem.fileLib.File.remove (   self,
  raiseException = False 
)

Remove the file.

Parameters
raiseException[ bool | False | in ] - Raise exception if the file could not be deleted.
Exceptions
Any- If file could not be deleted and raiseException argument is provided True.
Returns
bool - Result.

◆ write()

def sFileSystem.fileLib.File.write (   self,
  line,
  append = True 
)

Write given line into the file.

Parameters
line[ str | None | in ] - Line to be written.
append[ bool | True | in ] - Whether the line will be appended.
Exceptions
N/A
Returns
bool - Result.

◆ writeLines()

def sFileSystem.fileLib.File.writeLines (   self,
  lines,
  append = True 
)

Write given lines into the file.

Parameters
lines[ list of str | None | in ] - Lines to be written.
append[ bool | True | in ] - Whether the lines will be appended.
Exceptions
N/A
Returns
bool - Result.

◆ read()

def sFileSystem.fileLib.File.read (   self)

Read content of the file.

See also
content
Exceptions
N/A
Returns
str - Content.
None - If file doesn't exist.

◆ readLines()

def sFileSystem.fileLib.File.readLines (   self)

Read lines.

See also
content
Exceptions
N/A
Returns
list of str - Content.
None - If file doesn't exist.

◆ lineCount()

def sFileSystem.fileLib.File.lineCount (   self)

Get line count of the file.

Exceptions
N/A
Returns
int - Line count.

◆ fileExists()

def sFileSystem.fileLib.File.fileExists (   absFile)
static

Check whether the given file exists.

Parameters
absFile[ str | None | in ] - Absolute path of the file.
Exceptions
N/A
Returns
bool - Result.

◆ getFileSizeStr()

def sFileSystem.fileLib.File.getFileSizeStr (   size,
  precision = 2 
)
static

Get given byte size in human readable string.

Parameters
size[ int | None | in ] - Size in bytes.
precision[ int | 2 | in ] - Precision.
Exceptions
N/A
Returns
str - Size.

◆ replaceExtension()

def sFileSystem.fileLib.File.replaceExtension (   absFile,
  newExtension 
)
static

Replace given files extension with given extension.

Absolute or relative path of a file can be provided for absFile argument.

Method doesn't check whether the given absFile exists.

New extension will be added to absFile regardless it already has an extension.

Parameters
absFile[ str | None | in ] - File.
newExtension[ str | None | in ] - New extension.
Exceptions
N/A
Returns
str - File with new extension.

◆ create()

def sFileSystem.fileLib.File.create (   cls,
  absFile,
  overwrite = False,
  binary = False 
)

Create a file and return a sFileSystem.fileLib.File instance for it.

Directory, where the file will be created in, will be created if it doesn't exists.

Parameters
cls[ object | None | in ] - Class object.
absFile[ str | None | in ] - File name with absolute path.
overwrite[ bool | False | in ] - Whether existing file will be overwritten.
binary[ bool | False | in ] - Whether the file will be written in binary format.
Exceptions
IOError- If absFile exists and overwrite argument is provided False.
Returns
sFileSystem.fileLib.File - Instance of sFileSystem.fileLib.File class for created file.

The documentation for this class was generated from the following file: