legacy/libisofs/trunk/bindings/python/isofs/isofs.py

59 lines
2.0 KiB
Python
Raw Normal View History

# High level interface to the isofs library.
import core
import defines
import os.path
def _wrap_volume_property(var_name, core_setter):
def get(self):
return getattr(self, var_name)
def set(self, value):
setattr(self, var_name, value)
core_setter(self._volume, value)
return property(get, set)
class IsoFS(object):
def __init__(self, volume_id='', publisher_id='',
data_preparer_id=''):
self._volume_id = volume_id
self._publisher_id = publisher_id
self._data_preparer_id = data_preparer_id
self._volume = core.iso_volume_new(
volume_id, publisher_id, data_preparer_id)
self._volset = core.iso_volset_new(self._volume, volume_id)
def __del__(self):
core.iso_volume_free(self._volume)
core.iso_volset_free(self._volset)
volume_id = _wrap_volume_property(
'_volume_id', core.iso_volume_set_volume_id)
publisher_id = _wrap_volume_property(
'_publisher_id', core.iso_volume_set_publisher_id)
data_preparer_id = _wrap_volume_property(
'_data_preparer_id', core.iso_volume_set_data_preparer_id)
def add(self, disc_path, path, exclude=None): #, make_parents=False):
disc_path = os.path.normpath(disc_path)
path = os.path.abspath(os.path.normpath(path))
exclude = exclude or []
# Does the disc parent exist?
disc_parent, _ = os.path.split(disc_path)
if not core.iso_tree_volume_path_to_node(self._volume, disc_parent):
print "No such parent"
return # TODO: Raise exception and/or create all missing
# parents.
# Flush all ignores that may have stayed over.
core.iso_exclude_empty()
for exclude_path in exclude:
core.iso_exclude_add_path(exclude_path)
core.iso_tree_volume_add_path(self._volume, disc_path, path)
def display(self):
root = core.iso_volume_get_root(self._volume)
core.iso_tree_print(root, 0)