-
Notifications
You must be signed in to change notification settings - Fork 19
Python development
libqcow comes with Python-bindings named pyqcow.
Below are examples how use pyqcow. They assume you have a working version of pyqcow on your system. To build pyqcow see Building.
To be able to use pyqcow in your Python scripts add the following import:
import pyqcow
The get_version() module function can be used to retrieve the version of the pyqcow.
pyqcow.get_version()
This will return a textual string (Unicode) that contains the libqcow version. Since pyqcow is a wrapper around libqcow it does not have a separate version.
qcow_file = pyqcow.file()
qcow_file.open("image.qcow2")
...
qcow_file.close()
The explicit call to qcow_file.close() is not required. Close only must be called once all operations on the file have been completed.
file_object = open("image.qcow2", "rb")
qcow_file = pyqcow.file()
qcow_file.open_file_object(file_object)
...
qcow_file.close()
The explicit call to qcow_file.close() is not required. Close only must be called once all operations on the file have been completed and will not close the file-like object itself.
The following additional import is required:
import pytsk3
class qcow_Img_Info(pytsk3.Img_Info):
def __init__(self, qcow_file):
self._qcow_file = qcow_file
super(qcow_Img_Info, self).__init__(
url="", type=pytsk3.TSK_IMG_TYPE_EXTERNAL)
def close(self):
self._qcow_file.close()
def read(self, offset, size):
self._qcow_file.seek(offset)
return self._qcow_file.read(size)
def get_size(self):
return self._qcow_file.get_media_size()
qcow_file = pyqcow.file()
qcow_file.open("image.qcow2")
img_info = qcow_Img_Info(qcow_file)
fs_info = pytsk3.FS_Info(img_info, offset=63 * 512)
import pyqcow
help(pyqcow)
help(pyqcow.file)