# Path: igor/log.py
# def configure(fn):
# def backlog():
# def getLogger(name):
# 
# Path: igor/daemon/main.py
# class UpdateableObject(object):
# class Host(UpdateableObject):
# class Profile(UpdateableObject):
# class Origin(object):
# class Inventory(object):
# class JobSpec(UpdateableObject):
# class Testplan(object):
# class Testsuite(object):
# class Testset(object):
# class Testcase(object):
# class TestSession(UpdateableObject):
#     def __init__(self, **kwargs):
#     def update_props(self, kwargs):
#     def prepare(self):
#     def start(self):
#     def get_name(self):
#     def get_mac_address(self):
#     def purge(self):
#     def __to_dict__(self):
#     def get_name(self):
#     def assign_to(self, host, additional_kargs=""):
#     def enable_pxe(self, enable):
#     def kargs(self, kargs):
#     def revoke_from(self, host):
#     def delete(self):
#     def __repr__(self):
#     def __to_dict__(self):
#     def name(self):
#     def items(self):
#     def lookup(self, name):
#     def create_item(self, **kwargs):
#     def __to_dict__(self):
#     def __init__(self, plans={}, testsuites={}, profiles={}, hosts={}):
#     def _add_origins(self, k, origins):
#     def _items(self, k):
#     def _lookup(self, k, q=None):
#     def plans(self, q=None):
#     def testsuites(self, q=None):
#     def profiles(self, q=None):
#     def hosts(self, q=None):
#     def check(self):
#     def create_profile(self, oname, pname, kernel, initrd, kargs):
#     def __to_dict__(self):
#     def __str__(self):
#     def __init__(self, name, job_layouts, inventory=None):
#     def timeout(self):
#     def job_specs(self):
#     def spec_from_layout(self, layout):
#     def _parse_toplevel_field_value(self, key, value):
#     def __str__(self):
#     def __to_dict__(self):
#     def __hash__(self):
#     def __init__(self, name, testsets=[]):
#     def testcases(self):
#     def libs(self):
#     def timeout(self):
#     def __str__(self):
#     def __to_dict__(self):
#     def get_archive(self, subdir="testcases"):
#     def __add_testcases_to_archive(self, archive, subdir):
#     def __add_testcase_to_archive(self, archive, arcname, testcase):
#     def __add_data_to_archive(self, archive, arcname, data):
#     def __add_libs_to_archive(self, archive, subdir):
#     def validate(self):
#     def __init__(self, name, testcases=[], libs=None):
#     def testcases(self):
#     def libs(self, libs=None):
#     def timeout(self):
#     def add(self, cs):
#     def __str__(self):
#     def __to_dict__(self):
#     def __init__(self, filename=None, name=None):
#     def source(self):
#     def __str__(self):
#     def __to_dict__(self):
#     def __init__(self, cookie, session_path, cleanup=True):
#     def remove(self):
#     def remove_artifacts(self):
#     def __artifacts_path(self, name=""):
#     def add_artifact(self, name, data):
#     def get_artifact(self, name):
#     def artifacts(self, use_abs=False):
#     def get_artifacts_archive(self, selection=None):
#     def __enter__(self):
#     def __exit__(self, _type, value, traceback):
# 
# Path: igor/utils.py
# def run(cmd, with_retval=False):
#     import subprocess
#     logger.debug("Running: %s" % cmd)
#     child = subprocess.Popen(cmd, shell=True,
#                              stdout=subprocess.PIPE,
#                              stderr=subprocess.PIPE)
#     (stdout, stderr) = child.communicate()
#     # pylint: disable-msg=E1101
#     child.wait()
#     if stderr:
#         logger.warning(stderr)
#     r = str(stdout).strip()
#     if with_retval:
#         r = (child.returncode, str(stdout).strip())
#     # pylint: enable-msg=E1101
#     return r


import os
from igor import log
from igor.daemon import main
from igor.utils import run
    size : int-like
        Size in GB
    label : string, optional
        label in ['gpt', 'mbr', 'loop']
    partitions : Array of Partitions
    '''
    label = None
    partitions = None

    def __init__(self, size, partitions, label="gpt", filename=None):
        super(Layout, self).__init__(filename, size or 4, "raw")
        if label not in ["gpt", "mbr"]:
            raise Exception("Disk label must be gpt or mbr")
        self.partitions = partitions or [{}]
        self.label = label

    def create(self, session_dir):
        if self.filename is None:
            self.filename = run("mktemp --tmpdir='%s' 'vmimage-XXXX.img'" %
                                session_dir)
        logger.debug("Creating VM image '%s'" % self.filename)
        self.__truncate()
        self.__partition()
        return self.filename

    def remove(self):
        logger.debug("Removing VM image '%s'" % self.filename)
        os.remove(self.filename)

    def __truncate(self):

# Path: igor/log.py
# def configure(fn):
# def backlog():
# def getLogger(name):
# 
# Path: igor/daemon/main.py
# class UpdateableObject(object):
# class Host(UpdateableObject):
# class Profile(UpdateableObject):
# class Origin(object):
# class Inventory(object):
# class JobSpec(UpdateableObject):
# class Testplan(object):
# class Testsuite(object):
# class Testset(object):
# class Testcase(object):
# class TestSession(UpdateableObject):
#     def __init__(self, **kwargs):
#     def update_props(self, kwargs):
#     def prepare(self):
#     def start(self):
#     def get_name(self):
#     def get_mac_address(self):
#     def purge(self):
#     def __to_dict__(self):
#     def get_name(self):
#     def assign_to(self, host, additional_kargs=""):
#     def enable_pxe(self, enable):
#     def kargs(self, kargs):
#     def revoke_from(self, host):
#     def delete(self):
#     def __repr__(self):
#     def __to_dict__(self):
#     def name(self):
#     def items(self):
#     def lookup(self, name):
#     def create_item(self, **kwargs):
#     def __to_dict__(self):
#     def __init__(self, plans={}, testsuites={}, profiles={}, hosts={}):
#     def _add_origins(self, k, origins):
#     def _items(self, k):
#     def _lookup(self, k, q=None):
#     def plans(self, q=None):
#     def testsuites(self, q=None):
#     def profiles(self, q=None):
#     def hosts(self, q=None):
#     def check(self):
#     def create_profile(self, oname, pname, kernel, initrd, kargs):
#     def __to_dict__(self):
#     def __str__(self):
#     def __init__(self, name, job_layouts, inventory=None):
#     def timeout(self):
#     def job_specs(self):
#     def spec_from_layout(self, layout):
#     def _parse_toplevel_field_value(self, key, value):
#     def __str__(self):
#     def __to_dict__(self):
#     def __hash__(self):
#     def __init__(self, name, testsets=[]):
#     def testcases(self):
#     def libs(self):
#     def timeout(self):
#     def __str__(self):
#     def __to_dict__(self):
#     def get_archive(self, subdir="testcases"):
#     def __add_testcases_to_archive(self, archive, subdir):
#     def __add_testcase_to_archive(self, archive, arcname, testcase):
#     def __add_data_to_archive(self, archive, arcname, data):
#     def __add_libs_to_archive(self, archive, subdir):
#     def validate(self):
#     def __init__(self, name, testcases=[], libs=None):
#     def testcases(self):
#     def libs(self, libs=None):
#     def timeout(self):
#     def add(self, cs):
#     def __str__(self):
#     def __to_dict__(self):
#     def __init__(self, filename=None, name=None):
#     def source(self):
#     def __str__(self):
#     def __to_dict__(self):
#     def __init__(self, cookie, session_path, cleanup=True):
#     def remove(self):
#     def remove_artifacts(self):
#     def __artifacts_path(self, name=""):
#     def add_artifact(self, name, data):
#     def get_artifact(self, name):
#     def artifacts(self, use_abs=False):
#     def get_artifacts_archive(self, selection=None):
#     def __enter__(self):
#     def __exit__(self, _type, value, traceback):
# 
# Path: igor/utils.py
# def run(cmd, with_retval=False):
#     import subprocess
#     logger.debug("Running: %s" % cmd)
#     child = subprocess.Popen(cmd, shell=True,
#                              stdout=subprocess.PIPE,
#                              stderr=subprocess.PIPE)
#     (stdout, stderr) = child.communicate()
#     # pylint: disable-msg=E1101
#     child.wait()
#     if stderr:
#         logger.warning(stderr)
#     r = str(stdout).strip()
#     if with_retval:
#         r = (child.returncode, str(stdout).strip())
#     # pylint: enable-msg=E1101
#     return r


# Path: igor/daemon/partition.py
import os
from igor import log
from igor.daemon import main
from igor.utils import run

    size : int-like
        Size in GB
    label : string, optional
        label in ['gpt', 'mbr', 'loop']
    partitions : Array of Partitions
    '''
    label = None
    partitions = None

    def __init__(self, size, partitions, label="gpt", filename=None):
        super(Layout, self).__init__(filename, size or 4, "raw")
        if label not in ["gpt", "mbr"]:
            raise Exception("Disk label must be gpt or mbr")
        self.partitions = partitions or [{}]
        self.label = label

    def create(self, session_dir):
        if self.filename is None:
            self.filename = run("mktemp --tmpdir='%s' 'vmimage-XXXX.img'" %
                                session_dir)
        logger.debug("Creating VM image '%s'" % self.filename)
        self.__truncate()
        self.__partition()
        return self.filename

    def remove(self):
        logger.debug("Removing VM image '%s'" % self.filename)
        os.remove(self.filename)

    def __truncate(self):

        run("truncate --size=%s '%s'" % (self.size, self.filename))