COT.file_reference module¶
Wrapper classes to abstract away differences between file sources.
-
class
FileInTAR(tarfile_path, filename)[source]¶ Bases:
objectWrapper for a file inside a TAR archive or OVA.
-
__init__(tarfile_path, filename)[source]¶ Create a reference to a file contained in a TAR archive.
Parameters: Raises: IOError– iftarfile_pathdoesn’t reference a TAR file, or the TAR file does not containfilename.
-
add_to_archive(tarf)[source]¶ Copy this file into the given tarfile object.
Parameters: tarf (tarfile.TarFile) – Add this file to that archive.
-
copy_to(dest_dir)[source]¶ Extract this file to the given destination directory.
Parameters: dest_dir (str) – Destination directory or filename.
-
open(mode)[source]¶ Open the TAR and return a reference to the relevant file object.
Parameters: mode (str) – Only ‘r’ and ‘rb’ modes are supported. Returns: file – File object Raises: ValueError– ifmodeis not valid.
-
exists¶ True if the file exists in the TAR archive, else False.
-
size¶ The size of this file in bytes.
-
-
class
FileOnDisk(file_path, filename=None)[source]¶ Bases:
objectWrapper for a ‘real’ file on disk.
-
__init__(file_path, filename=None)[source]¶ Create a reference to a file on disk.
Parameters: Raises: IOError– if no such file existsExamples
>>> a = FileOnDisk('/etc/resolv.conf') >>> b = FileOnDisk('/etc', 'resolv.conf') >>> a == b True
-
add_to_archive(tarf)[source]¶ Copy this file into the given tarfile object.
Parameters: tarf (tarfile.TarFile) – Add this file to that archive.
-
copy_to(dest_dir)[source]¶ Copy this file to the given destination directory.
Parameters: dest_dir (str) – Destination directory or filename.
-
open(mode)[source]¶ Open the file and return a reference to the file object.
Parameters: mode (str) – Mode such as ‘r’, ‘w’, ‘a’, ‘w+’, etc. Returns: file – File object
-
exists¶ True if the file exists on disk, else False.
-
size¶ The size of this file, in bytes.
-