cterasdk.lib.storage.commonfs module#

class cterasdk.lib.storage.commonfs.ResultContext#

Bases: object

Context Manager Result Context

property value#
cterasdk.lib.storage.commonfs.determine_directory_and_filename(p, objects=None, destination=None, archive=False)#

Determine location to save file.

Parameters:
  • p (str) – Path.

  • objects (list[str],optional) – List of files or folders

  • destination (str,optional) – Destination

  • archive (bool,optional) – Compressed archive

Returns:

Directory and file name

Return type:

tuple[str]

cterasdk.lib.storage.commonfs.determine_zip_archive_name(directory, objects)#

Name the zip archive after the folder name, unless the directory contains only one object.

Return type:

str

cterasdk.lib.storage.commonfs.downloads()#

Get downloads directory.

Returns:

Directory path

Return type:

Path object

cterasdk.lib.storage.commonfs.exists(path)#

Check if a file or a directory exists

Parameters:

path (str) – Path

Returns:

True if exists, False otherwise.

Return type:

bool

cterasdk.lib.storage.commonfs.expanduser(path)#

Return a new path with expanded ~ and ~user constructs

Parameters:

path (str) – Path

Returns:

Absolute Path.

Return type:

Path object

cterasdk.lib.storage.commonfs.generate_file_destination(destination=None, default_name=None)#

Compute destination file path.

Parameters:
  • location (str) – Path to a file or a folder

  • default_name (str) – Default file name, unless location already specifies a file path

Returns:

Tuple including the destination directory and file name

Return type:

tuple(str, str)

cterasdk.lib.storage.commonfs.is_dir(path)#

Check is a directory.

Parameters:

path (str) – Path

Returns:

True if a directory, False otherwise.

Return type:

bool

cterasdk.lib.storage.commonfs.join(*paths)#

Join Path objects.

Parameters:

paths (list[Path]) – Path objects

Return type:

Path

cterasdk.lib.storage.commonfs.new_version(filename, version)#

Append version number to file name.

Parameters:
  • filename (str) – File name

  • version (int) – File version

Returns:

File name appended with a version number

Return type:

str

cterasdk.lib.storage.commonfs.properties(path)#

File properties.

Parameters:

path (str) – Path

Returns:

File name, size and type

Return type:

dict

Raises:

FileNotFoundError

cterasdk.lib.storage.commonfs.rename(source, new_name)#

Rename a file or a directory.

Parameters:
  • source (str) – Path

  • new_name (str) – New name

Returns:

Path after rename

Return type:

str

cterasdk.lib.storage.commonfs.split_file_directory(location)#

Split file and directory.

Parameters:

path (str) – Path

Returns: 1. (parent directory, file name), if a file exists 2. (parent directory, file name), if a directory exists 3. (parent directory, file name), if the parent directory exists 4. Raises FileNotFoundError if neither the object nor the parent directory exist

cterasdk.lib.storage.commonfs.write_new_version(directory, name, *, ctx=None)#

Context manager for writing a file without conflicts.

Parameters:
  • directory (str) – Parent directory

  • name (str) – File name

  • ctx (ResultContext,optional) – Result Context

Returns:

Path

Return type:

str

Raises:

FileNotFoundError