doc updates
This commit is contained in:
parent
889487f914
commit
ee308802f2
@ -20,8 +20,13 @@ import string
|
|||||||
|
|
||||||
|
|
||||||
class Element(object):
|
class Element(object):
|
||||||
|
"""A diskimage-builder element."""
|
||||||
|
|
||||||
def __init__(self, directory):
|
def __init__(self, directory):
|
||||||
|
"""
|
||||||
|
:param directory: The directory that defines the element.
|
||||||
|
:type directory str.
|
||||||
|
"""
|
||||||
logging.debug('initializing element: %s' % directory)
|
logging.debug('initializing element: %s' % directory)
|
||||||
|
|
||||||
if not os.access(directory, os.R_OK):
|
if not os.access(directory, os.R_OK):
|
||||||
|
@ -43,6 +43,8 @@ def load_args():
|
|||||||
|
|
||||||
|
|
||||||
def set_environment():
|
def set_environment():
|
||||||
|
"""Set environment variables that diskimage-builder elements expect."""
|
||||||
|
|
||||||
os.environ['TMP_MOUNT_PATH'] = '/'
|
os.environ['TMP_MOUNT_PATH'] = '/'
|
||||||
os.environ['DIB_OFFLINE'] = ''
|
os.environ['DIB_OFFLINE'] = ''
|
||||||
if platform.processor() == 'x86_64':
|
if platform.processor() == 'x86_64':
|
||||||
|
@ -27,10 +27,22 @@ from diskimage_builder.elements import expand_dependencies
|
|||||||
class ElementManager(object):
|
class ElementManager(object):
|
||||||
|
|
||||||
def __init__(self, elements, hooks, element_paths=None, dry_run=False):
|
def __init__(self, elements, hooks, element_paths=None, dry_run=False):
|
||||||
|
"""
|
||||||
|
:param elements: Element names to apply.
|
||||||
|
:type elements: list.
|
||||||
|
:param hooks: Hooks to run for each element.
|
||||||
|
:type hooks: list.
|
||||||
|
:param element_paths: File system paths to search for elements.
|
||||||
|
:type element_paths: list of strings.
|
||||||
|
:param dry_run: If True, do not actually run the hooks.
|
||||||
|
:type dry_run: bool
|
||||||
|
"""
|
||||||
self.elements = elements
|
self.elements = elements
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
self.hooks = hooks
|
self.hooks = hooks
|
||||||
|
self.loaded_elements = {}
|
||||||
|
|
||||||
|
# the environment variable should override anything passed in
|
||||||
if os.environ.has_key('ELEMENTS_PATH'):
|
if os.environ.has_key('ELEMENTS_PATH'):
|
||||||
self.element_paths = os.environ['ELEMENTS_PATH'].split(':')
|
self.element_paths = os.environ['ELEMENTS_PATH'].split(':')
|
||||||
else:
|
else:
|
||||||
@ -42,7 +54,6 @@ class ElementManager(object):
|
|||||||
logging.debug('manager initialized with elements path: %s' %
|
logging.debug('manager initialized with elements path: %s' %
|
||||||
self.element_paths)
|
self.element_paths)
|
||||||
|
|
||||||
self.loaded_elements = {}
|
|
||||||
self.load_elements()
|
self.load_elements()
|
||||||
self.load_dependencies()
|
self.load_dependencies()
|
||||||
self.copy_elements()
|
self.copy_elements()
|
||||||
@ -52,17 +63,28 @@ class ElementManager(object):
|
|||||||
self.run_hook(hook)
|
self.run_hook(hook)
|
||||||
|
|
||||||
def load_elements(self):
|
def load_elements(self):
|
||||||
|
"""Load all elements from self.element_paths.
|
||||||
|
|
||||||
|
This populates self.loaded_elements.
|
||||||
|
"""
|
||||||
for path in self.element_paths:
|
for path in self.element_paths:
|
||||||
self.process_path(path)
|
self.process_path(path)
|
||||||
|
|
||||||
def copy_elements(self):
|
def copy_elements(self):
|
||||||
|
"""Copy elements to apply to a temporary directory."""
|
||||||
self.tmp_hook_dir = tempfile.mkdtemp()
|
self.tmp_hook_dir = tempfile.mkdtemp()
|
||||||
for element in self.elements:
|
for element in self.elements:
|
||||||
element_dir = self.loaded_elements[element].directory
|
element_dir = self.loaded_elements[element].directory
|
||||||
dir_util.copy_tree(element_dir, self.tmp_hook_dir)
|
dir_util.copy_tree(element_dir, self.tmp_hook_dir)
|
||||||
|
# elements expect this environment variable to be set
|
||||||
os.environ['TMP_HOOKS_PATH'] = self.tmp_hook_dir
|
os.environ['TMP_HOOKS_PATH'] = self.tmp_hook_dir
|
||||||
|
|
||||||
def process_path(self, path):
|
def process_path(self, path):
|
||||||
|
"""Load elements from a given filesystem path.
|
||||||
|
|
||||||
|
:param path: Filesystem path from which to load elements.
|
||||||
|
:type path: str.
|
||||||
|
"""
|
||||||
if not os.access(path, os.R_OK):
|
if not os.access(path, os.R_OK):
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user