예제 #1
0
def copy_kinitrd(prj, target_dir):

    suite = prj.text("suite")

    try:
        tmp = TmpdirFilesystem()
        if prj.has("mirror/cdrom"):
            system('7z x -o%s "%s" initrd-cdrom.gz vmlinuz' %
                   (tmp.fname('/'), prj.text("mirror/cdrom")))

            # initrd.gz needs to be cdrom version !
            copyfile(tmp.fname("initrd-cdrom.gz"),
                     os.path.join(target_dir, "initrd.gz"))
        else:
            mirror = get_primary_mirror(prj)
            download_kinitrd(tmp, suite, mirror)

            copyfile(tmp.fname("initrd.gz"),
                     os.path.join(target_dir, "initrd.gz"))

        copyfile(tmp.fname("initrd-cdrom.gz"),
                 os.path.join(target_dir, "initrd-cdrom.gz"))

        copyfile(tmp.fname("vmlinuz"), os.path.join(target_dir, "vmlinuz"))

    except IOError as e:
        raise NoKinitrdException('IoError %s' % str(e))
    except InvalidSignature as e:
        raise NoKinitrdException('InvalidSignature %s' % str(e))
    except HashValidationFailed as e:
        raise NoKinitrdException('HashValidationFailed %s' % str(e))
예제 #2
0
def copy_kinitrd(prj, target_dir):

    suite = prj.text("suite")

    try:
        tmp = TmpdirFilesystem()
        if prj.has("mirror/cdrom"):
            system('7z x -o%s "%s" initrd-cdrom.gz vmlinuz' %
                   (tmp.fname('/'), prj.text("mirror/cdrom")))

            # initrd.gz needs to be cdrom version !
            copyfile(tmp.fname("initrd-cdrom.gz"),
                     os.path.join(target_dir, "initrd.gz"))
        else:
            mirror = get_primary_mirror(prj)
            download_kinitrd(tmp, suite, mirror)

            copyfile(tmp.fname("initrd.gz"),
                     os.path.join(target_dir, "initrd.gz"))

        copyfile(tmp.fname("initrd-cdrom.gz"),
                 os.path.join(target_dir, "initrd-cdrom.gz"))

        copyfile(tmp.fname("vmlinuz"),
                 os.path.join(target_dir, "vmlinuz"))

    except IOError as e:
        raise NoKinitrdException('IoError %s' % e.message)
    except InvalidSignature as e:
        raise NoKinitrdException('InvalidSignature %s' % e.message)
    except HashValidationFailed as e:
        raise NoKinitrdException('HashValidationFailed %s' % e.message)
def extract_cdrom(cdrom):
    """ Extract cdrom iso image
        returns a TmpdirFilesystem() object containing
        the source.xml, which is also validated.
    """

    tmp = TmpdirFilesystem()
    system('7z x -o%s "%s" source.xml' % (tmp.path, cdrom))

    print("", file=sys.stderr)

    if not tmp.isfile('source.xml'):
        print("Iso image does not contain a source.xml file", file=sys.stderr)
        print("This is not supported by 'elbe initvm'", file=sys.stderr)
        print("", file=sys.stderr)
        print("Exiting !!!", file=sys.stderr)
        sys.exit(20)

    try:
        exml = ElbeXML(tmp.fname('source.xml'),
                       url_validation=ValidationMode.NO_CHECK)
    except ValidationError as e:
        print("Iso image does contain a source.xml file.", file=sys.stderr)
        print("But that xml does not validate correctly", file=sys.stderr)
        print("", file=sys.stderr)
        print("Exiting !!!", file=sys.stderr)
        print(e)
        sys.exit(20)

    print("Iso Image with valid source.xml detected !")
    print("Image was generated using Elbe Version %s" %
          exml.get_elbe_version())

    return tmp
예제 #4
0
def extract_pkg_changelog(fname, extra_pkg=None):
    pkgname = os.path.basename(fname)
    m = re.match(re_pkgfilename, pkgname)

    pkgname = m.group('name')
    # pkgver = m.group('ver')
    pkgarch = m.group('arch')

    print('pkg: %s, arch: %s' % (pkgname, pkgarch))

    fs = TmpdirFilesystem(debug=True)

    if extra_pkg:
        print('with extra ' + extra_pkg)
        system('dpkg -x "%s" "%s"' % (extra_pkg, fs.fname('/')))

    system('dpkg -x "%s" "%s"' % (fname, fs.fname('/')))

    dch_dir = '/usr/share/doc/%s' % pkgname

    if fs.islink(dch_dir) and not extra_pkg:
        l = fs.readlink(dch_dir)
        print(dch_dir, l)
        raise ChangelogNeedsDependency(l)

    dch_bin = '/usr/share/doc/%s/changelog.Debian.%s.gz' % (pkgname, pkgarch)
    dch_src = '/usr/share/doc/%s/changelog.Debian.gz' % pkgname

    print(fs.listdir('/usr/share/doc/'))
    print(fs.listdir('/usr/share/doc/%s' % pkgname))

    ret = ""

    if fs.exists(dch_bin):
        ret += fs.read_file(dch_bin, gz=True)
    else:
        print("no bin")

    if fs.exists(dch_src):
        ret += fs.read_file(dch_src, gz=True)
    else:
        print("no source")

    return ret
예제 #5
0
def extract_cdrom(cdrom):
    """ Extract cdrom iso image
        returns a TmpdirFilesystem() object containing
        the source.xml, which is also validated.
    """

    tmp = TmpdirFilesystem()
    os.system('7z x -o%s "%s" source.xml' % (tmp.path, cdrom))

    print("", file=sys.stderr)

    if not tmp.isfile('source.xml'):
        print(
            "Iso image does not contain a source.xml file",
            file=sys.stderr)
        print(
            "This is not supported by 'elbe initvm'",
            file=sys.stderr)
        print("", file=sys.stderr)
        print("Exiting !!!", file=sys.stderr)
        sys.exit(20)

    try:
        exml = ElbeXML(
            tmp.fname('source.xml'),
            url_validation=ValidationMode.NO_CHECK)
    except ValidationError as e:
        print(
            "Iso image does contain a source.xml file.",
            file=sys.stderr)
        print(
            "But that xml does not validate correctly",
            file=sys.stderr)
        print("", file=sys.stderr)
        print("Exiting !!!", file=sys.stderr)
        print(e)
        sys.exit(20)

    print("Iso Image with valid source.xml detected !")
    print(
        "Image was generated using Elbe Version %s" %
        exml.get_elbe_version())

    return tmp
예제 #6
0
def _combinearchivedir(xml, xpath, use_volume):
    elbexml = etree(None)
    elbexml.et = xml

    tmp = TmpdirFilesystem()
    for archivedir in elbexml.all(xpath):

        try:
            archiveurl = urljoin(archivedir.et.base, archivedir.et.text)
            keep = archivedir.bool_attr("keep-attributes")
            parent = archivedir.get_parent()

            if use_volume:
                volume_attr = archivedir.et.get('volume', default='all')
                fname_suffix = volume_attr

                arch = parent.node("archive[@volume='%s']" % volume_attr)

                if arch is None:
                    arch = parent.append("archive")
                    arch.et.set("volume", volume_attr)

            else:
                arch = parent.ensure_child("archive")
                fname_suffix = ''


            get_and_append = get_and_append_method(archiveurl)

            archname = tmp.fname('archive%s.tar.bz2' % fname_suffix)
            get_and_append(archiveurl, archname, keep)
            arch.set_text(enbase(archname, True))

            parent.remove_child(archivedir)
        except (CalledProcessError, OSError):
            msg = "Failure while processing \"" + archivedir.text + "\":\n"
            msg += str(sys.exc_info()[1])
            raise ArchivedirError(msg)
예제 #7
0
class VirtApt(object):
    def __init__(self, xml):

        # pylint: disable=too-many-statements
        self.xml = xml

        arch = xml.text("project/buildimage/arch", key="arch")
        suite = xml.text("project/suite")

        self.basefs = TmpdirFilesystem()
        self.initialize_dirs()

        create_apt_prefs(self.xml, self.basefs)

        mirror = self.xml.create_apt_sources_list(build_sources=True,
                                                  initvm=False)
        self.basefs.write_file("etc/apt/sources.list", 0o644, mirror)

        self.setup_gpg()
        self.import_keys()

        apt_pkg.config.set("APT::Architecture", arch)
        apt_pkg.config.set("APT::Architectures", arch)
        apt_pkg.config.set("Acquire::http::Proxy::127.0.0.1", "DIRECT")
        apt_pkg.config.set("APT::Install-Recommends", "0")
        apt_pkg.config.set("Dir::Etc", self.basefs.fname('/'))
        apt_pkg.config.set("Dir::Etc::Trusted",
                           self.basefs.fname('/etc/apt/trusted.gpg'))
        apt_pkg.config.set("Dir::Etc::TrustedParts",
                           self.basefs.fname('/etc/apt/trusted.gpg.d'))
        apt_pkg.config.set("APT::Cache-Limit", "0")
        apt_pkg.config.set("APT::Cache-Start", "32505856")
        apt_pkg.config.set("APT::Cache-Grow", "2097152")
        apt_pkg.config.set("Dir::State", self.basefs.fname("state"))
        apt_pkg.config.set("Dir::State::status",
                           self.basefs.fname("state/status"))
        apt_pkg.config.set("Dir::Cache", self.basefs.fname("cache"))
        apt_pkg.config.set("Dir::Cache::archives",
                           self.basefs.fname("cache/archives"))
        apt_pkg.config.set("Dir::Etc", self.basefs.fname("etc/apt"))
        apt_pkg.config.set("Dir::Log", self.basefs.fname("log"))
        if self.xml.has('project/noauth'):
            apt_pkg.config.set("APT::Get::AllowUnauthenticated", "1")
            apt_pkg.config.set("Acquire::AllowInsecureRepositories", "1")
        else:
            apt_pkg.config.set("APT::Get::AllowUnauthenticated", "0")
            apt_pkg.config.set("Acquire::AllowInsecureRepositories", "0")

        apt_pkg.init_system()

        self.source = apt_pkg.SourceList()
        self.source.read_main_list()
        self.cache = apt_pkg.Cache()
        try:
            self.cache.update(self, self.source)
        except BaseException as e:
            print(e)

        apt_pkg.config.set("APT::Default-Release", suite)

        self.cache = apt_pkg.Cache()
        try:
            self.cache.update(self, self.source)
        except BaseException as e:
            print(e)

        try:
            self.depcache = apt_pkg.DepCache(self.cache)
            prefs_name = self.basefs.fname("/etc/apt/preferences")
            self.depcache.read_pinfile(prefs_name)
        except BaseException as e:
            print(e)

        self.downloads = {}
        self.acquire = apt_pkg.Acquire(self)

    def add_key(self, key):
        cmd = 'echo "%s" > %s' % (key, self.basefs.fname("tmp/key.pub"))
        clean = 'rm -f %s' % self.basefs.fname("tmp/key.pub")
        system(cmd)
        system('fakeroot apt-key --keyring "%s" add "%s"' %
               (self.basefs.fname('/etc/apt/trusted.gpg'),
                self.basefs.fname("tmp/key.pub")))
        system(clean)

    def import_keys(self):
        if self.xml.has('project/mirror/url-list'):
            # Should we use self.xml.prj.has("noauth")???
            #
            # If so, this is related to issue #220 -
            # https://github.com/Linutronix/elbe/issues/220
            #
            # I could make a none global 'noauth' flag for mirrors
            for url in self.xml.node('project/mirror/url-list'):
                if url.has('raw-key'):
                    key = "\n".join(
                        line.strip(" \t")
                        for line in url.text('raw-key').splitlines()[1:-1])
                    self.add_key(key)

    def start(self):
        pass

    def stop(self):
        pass

    @staticmethod
    def pulse(_obj):
        return True

    def initialize_dirs(self):
        self.basefs.mkdir_p("cache/archives/partial")
        self.basefs.mkdir_p("etc/apt/preferences.d")
        self.basefs.mkdir_p("etc/apt/trusted.gpg.d")
        self.basefs.mkdir_p("db")
        self.basefs.mkdir_p("log")
        self.basefs.mkdir_p("state/lists/partial")
        self.basefs.mkdir_p("tmp")
        self.basefs.touch_file("state/status")

    def setup_gpg(self):
        ring_path = self.basefs.fname("etc/apt/trusted.gpg")
        if not os.path.isdir("/etc/apt/trusted.gpg.d"):
            print("/etc/apt/trusted.gpg.d doesn't exist")
            print("apt-get install debian-archive-keyring may "
                  "fix this problem")
            sys.exit(20)

        if os.path.exists("/etc/apt/trusted.gpg"):
            system('cp /etc/apt/trusted.gpg "%s"' % ring_path)

        trustkeys = os.listdir("/etc/apt/trusted.gpg.d")
        for key in trustkeys:
            system('cp "/etc/apt/trusted.gpg.d/%s" "%s"' %
                   (key, ring_path + '.d'))

    def mark_install(self, pkgname):
        self.depcache.mark_install(self.cache[pkgname])

    def marked_install(self, pkgname):
        return self.depcache.marked_install(self.cache[pkgname])

    def get_candidate_ver(self, pkgname):
        return self.depcache.get_candidate_ver(self.cache[pkgname]).ver_str

    def has_pkg(self, pkgname):
        return pkgname in self.cache

    def mark_pkg_download(self, pkgname):
        pkg = self.cache[pkgname]
        c = self.depcache.get_candidate_ver(pkg)

        r = apt_pkg.PackageRecords(self.cache)
        r.lookup(c.file_list[0])

        x = self.source.find_index(c.file_list[0][0])
        uri = x.archive_uri(r.filename)
        hashval = str(r.hashes.find('SHA256'))

        acq = apt_pkg.AcquireFile(self.acquire,
                                  uri,
                                  hash=hashval,
                                  size=c.size,
                                  descr=r.long_desc,
                                  short_descr=r.short_desc,
                                  destdir=self.basefs.fname('/cache/archives'))
        self.downloads[pkgname] = acq

    def do_downloads(self):
        res = self.acquire.run()
        print(res)

    def get_downloaded_files(self):
        ret = []
        for _, d in self.downloads.items():
            if d.complete:
                ret.append(d.destfile)
            else:
                print('incomplete download "%s"' % d.desc_uri)

        return ret

    def get_downloaded_pkg(self, pkgname):
        d = self.downloads[pkgname]

        if not d.complete:
            print('incomplete download "%s"' % d.desc_uri)
            raise KeyError

        return d.destfile

    def get_uri(self, target_pkg, incl_deps=False):

        d = apt_pkg.DepCache(self.cache)

        if not incl_deps:
            return [lookup_uri(self, d, target_pkg)]

        deps = [lookup_uri(self, d, target_pkg)]
        togo = [target_pkg]
        while togo:
            pp = togo.pop()
            try:
                pkg = self.cache[pp]
                c = d.get_candidate_ver(pkg)
            except KeyError:
                pkg = None
                c = None
            if not c:
                # pylint: disable=E1133
                for p in self.cache.packages:
                    for x in p.provides_list:
                        if pp == x[0]:
                            pkg = self.cache[x[2].parent_pkg.name]
                            c = d.get_candidate_ver(pkg)
            if not c:
                print("couldnt get candidate: %s" % pkg)
            else:
                for p in getdeps(c):
                    if [y for y in deps if y[0] == p]:
                        continue
                    if p != target_pkg and p == pp:
                        continue
                    deps.append(lookup_uri(self, d, p))
                    togo.append(p)

        return list(set(deps))
예제 #8
0
    def execute(self, initvmdir, opt, args):
        try:
            have_session = os.system(
                "tmux has-session -t ElbeInitVMSession >/dev/null 2>&1")
        except CommandError as e:
            print(
                "tmux execution failed, tmux version 1.9 or higher is required"
            )
            sys.exit(20)
        if have_session == 256:
            print("ElbeInitVMSession does not exist in tmux.", file=sys.stderr)
            print("Try 'elbe initvm start' to start the session.",
                  file=sys.stderr)
            sys.exit(20)

        try:
            system('%s initvm ensure --directory "%s"' % (elbe_exe, initvmdir))
        except CommandError:
            print("Starting the initvm Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        # Init cdrom to None, if we detect it, we set it
        cdrom = None

        if len(args) == 1:
            if args[0].endswith('.xml'):
                # We have an xml file, use that for elbe init
                xmlfile = args[0]
            elif args[0].endswith('.iso'):
                # We have an iso image, extract xml from there.
                tmp = TmpdirFilesystem()
                os.system('7z x -o%s "%s" source.xml' % (tmp.path, args[0]))

                print('', file=sys.stderr)

                if not tmp.isfile('source.xml'):
                    print('Iso image does not contain a source.xml file',
                          file=sys.stderr)
                    print('This is not supported by "elbe initvm"',
                          file=sys.stderr)
                    print('', file=sys.stderr)
                    print('Exiting !!!', file=sys.stderr)
                    sys.exit(20)

                try:
                    exml = ElbeXML(tmp.fname('source.xml'), skip_urlcheck=True)
                except ValidationError as e:
                    print('Iso image does contain a source.xml file.',
                          file=sys.stderr)
                    print('But that xml does not validate correctly',
                          file=sys.stderr)
                    print('', file=sys.stderr)
                    print('Exiting !!!', file=sys.stderr)
                    sys.exit(20)

                print('Iso Image with valid source.xml detected !')
                print('Image was generated using Elbe Version %s' %
                      exml.get_elbe_version())

                xmlfile = tmp.fname('source.xml')
                cdrom = args[0]
            else:
                print('Unknown file ending (use either xml or iso)',
                      file=sys.stderr)
                sys.exit(20)

            ret, prjdir, err = command_out_stderr(
                '%s control create_project --retries 60 "%s"' %
                (elbe_exe, xmlfile))
            if ret != 0:
                print("elbe control create_project failed.", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            if cdrom is not None:
                print("Uploading CDROM. This might take a while")
                try:
                    system('%s control set_cdrom "%s" "%s"' %
                           (elbe_exe, prjdir, cdrom))
                except CommandError:
                    print("elbe control set_cdrom Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)

                print("Upload finished")

            build_opts = ''
            if opt.build_bin:
                build_opts += '--build-bin '
            if opt.build_sources:
                build_opts += '--build-sources '

            try:
                system('%s control build "%s" %s' %
                       (elbe_exe, prjdir, build_opts))
            except CommandError:
                print("elbe control build Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            print("Build started, waiting till it finishes")

            try:
                system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control wait_busy Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            print("")
            print("Build finished !")
            print("")
            try:
                system('%s control dump_file "%s" validation.txt' %
                       (elbe_exe, prjdir))
            except CommandError:
                print("Project failed to generate validation.txt",
                      file=sys.stderr)
                print("Getting log.txt", file=sys.stderr)
                try:
                    system('%s control dump_file "%s" log.txt' %
                           (elbe_exe, prjdir))
                except CommandError:

                    print("Failed to dump log.txt", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.skip_download:
                print("")
                print("Listing available files:")
                print("")
                try:
                    system('%s control get_files "%s"' % (elbe_exe, prjdir))
                except CommandError:
                    print("elbe control get_files Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)

                print("")
                print('Get Files with: elbe control get_file "%s" <filename>' %
                      prjdir)
            else:
                print("")
                print("Getting generated Files")
                print("")

                ensure_outdir(wdfs, opt)

                try:
                    system('%s control get_files --output "%s" "%s"' %
                           (elbe_exe, opt.outdir, prjdir))
                except CommandError:
                    print("elbe control get_files Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)

                if not opt.keep_files:
                    try:
                        system('%s control del_project "%s"' %
                               (elbe_exe, prjdir))
                    except CommandError:
                        print("remove project from initvm failed",
                              file=sys.stderr)
                        sys.exit(20)
예제 #9
0
    def execute(self, initvmdir, opt, args):
        try:
            have_session = os.system(
                "tmux has-session -t ElbeInitVMSession >/dev/null 2>&1")
        except CommandError as e:
            print(
                "tmux execution failed, tmux version 1.9 or higher is required"
            )
            sys.exit(20)
        if have_session == 0:
            print("ElbeInitVMSession already exists in tmux.", file=sys.stderr)
            print("", file=sys.stderr)
            print(
                "There can only exist a single ElbeInitVMSession, and this session",
                file=sys.stderr)
            print("can also be used to make your build.", file=sys.stderr)
            print(
                "See 'elbe initvm submit', 'elbe initvm attach' and 'elbe control'",
                file=sys.stderr)
            sys.exit(20)

        # Init cdrom to None, if we detect it, we set it
        cdrom = None

        if len(args) == 1:
            if args[0].endswith('.xml'):
                # We have an xml file, use that for elbe init
                exampl = args[0]
                try:
                    xml = etree(exampl)
                except ValidationError as e:
                    print('XML file is inavlid: ' + str(e))
                # Use default XML if no initvm was specified
                if not xml.has("initvm"):
                    exampl = os.path.join(elbepack.__path__[0],
                                          "init/default-init.xml")

            elif args[0].endswith('.iso'):
                # We have an iso image, extract xml from there.
                tmp = TmpdirFilesystem()
                os.system('7z x -o%s "%s" source.xml' % (tmp.path, args[0]))

                if not tmp.isfile('source.xml'):
                    print('Iso image does not contain a source.xml file',
                          file=sys.stderr)
                    print('This is not supported by "elbe initvm"',
                          file=sys.stderr)
                    print('', file=sys.stderr)
                    print('Exiting !!!', file=sys.stderr)
                    sys.exit(20)

                try:
                    exml = ElbeXML(tmp.fname('source.xml'), skip_urlcheck=True)
                except ValidationError as e:
                    print('Iso image does contain a source.xml file.',
                          file=sys.stderr)
                    print('But that xml does not validate correctly',
                          file=sys.stderr)
                    print('', file=sys.stderr)
                    print('Exiting !!!', file=sys.stderr)
                    sys.exit(20)

                print('Iso Image with valid source.xml detected !')
                print('Image was generated using Elbe Version %s' %
                      exml.get_elbe_version())

                exampl = tmp.fname('source.xml')
                cdrom = args[0]
            else:
                print('Unknown file ending (use either xml or iso)',
                      file=sys.stderr)
                sys.exit(20)
        else:
            # No xml File was specified, build the default elbe-init-with-ssh
            exampl = os.path.join(elbepack.__path__[0],
                                  "init/default-init.xml")

        try:
            if opt.devel:
                devel = ' --devel'
            else:
                devel = ''

            if cdrom:
                system('%s init %s --directory "%s" --cdrom "%s" "%s"' %
                       (elbe_exe, devel, initvmdir, cdrom, exampl))
            else:
                system('%s init %s --directory "%s" "%s"' %
                       (elbe_exe, devel, initvmdir, exampl))

        except CommandError:
            print("'elbe init' Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        try:
            system('cd "%s"; make' % (initvmdir))
        except CommandError:
            print("Building the initvm Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        try:
            system('%s initvm start --directory "%s"' % (elbe_exe, initvmdir))
        except CommandError:
            print("Starting the initvm Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        if len(args) == 1:
            # if provided xml file has no initvm section exampl is set to a
            # default initvm XML file. But we need the original file here
            if args[0].endswith('.xml'):
                # stop here if no project node was specified
                try:
                    x = ElbeXML(args[0])
                except ValidationError as e:
                    print('XML file is inavlid: ' + str(e))
                    sys.exit(20)
                if not x.has('project'):
                    print(
                        'elbe initvm ready: use "elbe initvm submit myproject.xml" to build a project'
                    )
                    sys.exit(0)

                ret, prjdir, err = command_out_stderr(
                    '%s control create_project "%s"' % (elbe_exe, args[0]))
            else:
                ret, prjdir, err = command_out_stderr(
                    '%s control create_project "%s"' % (elbe_exe, exampl))

            if ret != 0:
                print("elbe control create_project failed.", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            if cdrom is not None:
                print("Uploading CDROM. This might take a while")
                try:
                    system('%s control set_cdrom "%s" "%s"' %
                           (elbe_exe, prjdir, cdrom))
                except CommandError:
                    print("elbe control set_cdrom Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)

                print("Upload finished")

            build_opts = ''
            if opt.build_bin:
                build_opts += '--build-bin '
            if opt.build_sources:
                build_opts += '--build-sources '

            try:
                system('%s control build "%s" %s' %
                       (elbe_exe, prjdir, build_opts))
            except CommandError:
                print("elbe control build Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            try:
                system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control wait_busy Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            print("")
            print("Build finished !")
            print("")
            try:
                system('%s control dump_file "%s" validation.txt' %
                       (elbe_exe, prjdir))
            except CommandError:
                print("Project failed to generate validation.txt",
                      file=sys.stderr)
                print("Getting log.txt", file=sys.stderr)
                try:
                    system('%s control dump_file "%s" log.txt' %
                           (elbe_exe, prjdir))
                except CommandError:

                    print("Failed to dump log.txt", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.skip_download:
                print("")
                print("Listing available files:")
                print("")
                try:
                    system('%s control get_files "%s"' % (elbe_exe, prjdir))
                except CommandError:
                    print("elbe control Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)

                print("")
                print('Get Files with: elbe control get_file "%s" <filename>' %
                      prjdir)
            else:
                ensure_outdir(wdfs, opt)

                try:
                    system('%s control get_files --output "%s" "%s"' %
                           (elbe_exe, opt.outdir, prjdir))
                except CommandError:
                    print("elbe control get_files Failed", file=sys.stderr)
                    print("Giving up", file=sys.stderr)
                    sys.exit(20)
    def execute(self, opt, _args):

        # pylint: disable=too-many-statements
        # pylint: disable=too-many-branches

        crossopt = ""
        if opt.cross:
            crossopt = "--cross"
        tmp = TmpdirFilesystem()

        if opt.xmlfile:
            ret, prjdir, err = command_out_stderr(
                '%s control create_project --retries 60 "%s"' %
                (elbe_exe, opt.xmlfile))
            if ret != 0:
                print("elbe control create_project failed.", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            try:
                system('%s control build_pbuilder "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control build_pbuilder Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            try:
                system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control wait_busy Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            print("")
            print("Building Pbuilder finished !")
            print("")
        elif opt.project:
            prjdir = opt.project
            system('%s control rm_log %s' % (elbe_exe, prjdir))
        else:
            print("you need to specify --project or --xmlfile option",
                  file=sys.stderr)
            sys.exit(20)

        print("")
        print("Packing Source into tmp archive")
        print("")
        try:
            system('tar cfz "%s" .' % (tmp.fname("pdebuild.tar.gz")))
        except CommandError:
            print("tar Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        for of in opt.origfile:
            print("")
            print("Pushing orig file '%s' into pbuilder" % of)
            print("")
            try:
                system('%s control set_orig "%s" "%s"' %
                       (elbe_exe, prjdir, of))
            except CommandError:
                print("elbe control set_orig Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

        print("")
        print("Pushing source into pbuilder")
        print("")

        try:
            system('%s control set_pdebuild --cpuset "%d" --profile "%s" %s '
                   '"%s" "%s"' % (elbe_exe, opt.cpuset, opt.profile, crossopt,
                                  prjdir, tmp.fname("pdebuild.tar.gz")))
        except CommandError:
            print("elbe control set_pdebuild Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)
        try:
            system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
        except CommandError:
            print("elbe control wait_busy Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)
        print("")
        print("Pdebuild finished !")
        print("")

        if opt.skip_download:
            print("")
            print("Listing available files:")
            print("")
            try:
                system('%s control --pbuilder-only get_files "%s"' %
                       (elbe_exe, prjdir))
            except CommandError:
                print("elbe control get_files Failed", file=sys.stderr)
                print("", file=sys.stderr)
                print("dumping logfile", file=sys.stderr)

                try:
                    system('%s control dump_file "%s" log.txt' %
                           (elbe_exe, prjdir))
                except CommandError:
                    print("elbe control dump_file Failed", file=sys.stderr)
                    print("", file=sys.stderr)
                    print("Giving up", file=sys.stderr)

                sys.exit(20)

            print("")
            print("Get Files with: 'elbe control get_file %s <filename>'" %
                  prjdir)
        else:
            print("")
            print("Getting generated Files")
            print("")

            ensure_outdir(opt)

            try:
                system(
                    '%s control --pbuilder-only get_files --output "%s" "%s"' %
                    (elbe_exe, opt.outdir, prjdir))
            except CommandError:
                print("elbe control get_files Failed", file=sys.stderr)
                print("", file=sys.stderr)
                print("dumping logfile", file=sys.stderr)

                try:
                    system('%s control dump_file "%s" log.txt' %
                           (elbe_exe, prjdir))
                except CommandError:
                    print("elbe control dump_file Failed", file=sys.stderr)
                    print("", file=sys.stderr)
                    print("Giving up", file=sys.stderr)

                sys.exit(20)
예제 #11
0
    def execute(self, opt, args):
        tmp = TmpdirFilesystem ()

        if opt.xmlfile:
            ret, prjdir, err = command_out_stderr ('%s control create_project --retries 60 "%s"' % (elbe_exe, opt.xmlfile))
            if ret != 0:
                print ("elbe control create_project failed.", file=sys.stderr)
                print (err, file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            try:
                system ('%s control build "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control build Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("Build started, waiting till it finishes")

            try:
                system ('%s control wait_busy "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control wait_busy Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("")
            print ("Build finished !")
            print ("")
            print ("Creating pbuilder")

            try:
                system ('%s control build_pbuilder "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print ("elbe control build_pbuilder Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            try:
                system ('%s control wait_busy "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control wait_busy Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("")
            print ("Building Pbuilder finished !")
            print ("")
        elif opt.project:
            prjdir = opt.project
        else:
            print ('you need to specify --project or --xmlfile option', file=sys.stderr)
            sys.exit(20)

        print ("")
        print ("Packing Source into tmp archive")
        print ("")
        try:
            system ('tar cvfz "%s" .' % (tmp.fname ("pdebuild.tar.gz")))
        except CommandError:
            print ("tar Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)

        print ("")
        print ("Pushing source into pbuilder")
        print ("")

        try:
            system ('%s control set_pdebuild "%s" "%s"' % (elbe_exe, prjdir, tmp.fname ("pdebuild.tar.gz")))
        except CommandError:
            print ("elbe control set_pdebuild Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)
        try:
            system ('%s control wait_busy "%s"' % (elbe_exe, prjdir) )
        except CommandError:
            print ("elbe control wait_busy Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)
        print ("")
        print ("Pdebuild finished !")
        print ("")

        if opt.skip_download:
            print ("")
            print ("Listing available files:")
            print ("")
            try:
                system ('%s control --pbuilder-only get_files "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control get_files Failed", file=sys.stderr)
                print ("", file=sys.stderr)
                print ("dumping logfile", file=sys.stderr)

                try:
                    system ('%s control dump_file "%s" log.txt' % (
                            elbe_exe, prjdir ))
                except CommandError:
                    print ("elbe control dump_file Failed", file=sys.stderr)
                    print ("", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)

                sys.exit(20)

            print ("")
            print ('Get Files with: elbe control get_file "%s" <filename>' % prjdir)
        else:
            print ("")
            print ("Getting generated Files")
            print ("")

            ensure_outdir (wdfs, opt)

            try:
                system ('%s control --pbuilder-only get_files --output "%s" "%s"' % (
                        elbe_exe, opt.outdir, prjdir ))
            except CommandError:
                print ("elbe control get_files Failed", file=sys.stderr)
                print ("", file=sys.stderr)
                print ("dumping logfile", file=sys.stderr)

                try:
                    system ('%s control dump_file "%s" log.txt' % (
                            elbe_exe, prjdir ))
                except CommandError:
                    print ("elbe control dump_file Failed", file=sys.stderr)
                    print ("", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)

                sys.exit(20)
예제 #12
0
    def execute(self, opt, _args):

        # pylint: disable=too-many-statements
        # pylint: disable=too-many-branches

        tmp = TmpdirFilesystem()

        if opt.xmlfile:
            ret, prjdir, err = command_out_stderr(
                '%s control create_project --retries 60 "%s"' %
                (elbe_exe, opt.xmlfile))
            if ret != 0:
                print("elbe control create_project failed.", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            try:
                system('%s control build_pbuilder "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control build_pbuilder Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            try:
                system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
            except CommandError:
                print("elbe control wait_busy Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            print("")
            print("Building Pbuilder finished !")
            print("")
        elif opt.project:
            prjdir = opt.project
            system('%s control rm_log %s' % (elbe_exe, prjdir))
        else:
            print(
                "you need to specify --project or --xmlfile option",
                file=sys.stderr)
            sys.exit(20)

        print("")
        print("Packing Source into tmp archive")
        print("")
        try:
            system('tar cfz "%s" .' % (tmp.fname("pdebuild.tar.gz")))
        except CommandError:
            print("tar Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)

        for of in opt.origfile:
            print("")
            print("Pushing orig file '%s' into pbuilder" % of)
            print("")
            try:
                system(
                    '%s control set_orig "%s" "%s"' %
                    (elbe_exe, prjdir, of))
            except CommandError:
                print("elbe control set_orig Failed", file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)

        print("")
        print("Pushing source into pbuilder")
        print("")

        try:
            system('%s control set_pdebuild --cpuset "%d" --profile "%s" '
                   '"%s" "%s"' %
                   (elbe_exe, opt.cpuset, opt.profile,
                    prjdir, tmp.fname("pdebuild.tar.gz")))
        except CommandError:
            print("elbe control set_pdebuild Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)
        try:
            system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
        except CommandError:
            print("elbe control wait_busy Failed", file=sys.stderr)
            print("Giving up", file=sys.stderr)
            sys.exit(20)
        print("")
        print("Pdebuild finished !")
        print("")

        if opt.skip_download:
            print("")
            print("Listing available files:")
            print("")
            try:
                system(
                    '%s control --pbuilder-only get_files "%s"' %
                    (elbe_exe, prjdir))
            except CommandError:
                print("elbe control get_files Failed", file=sys.stderr)
                print("", file=sys.stderr)
                print("dumping logfile", file=sys.stderr)

                try:
                    system('%s control dump_file "%s" log.txt' % (
                        elbe_exe, prjdir))
                except CommandError:
                    print("elbe control dump_file Failed", file=sys.stderr)
                    print("", file=sys.stderr)
                    print("Giving up", file=sys.stderr)

                sys.exit(20)

            print("")
            print(
                "Get Files with: 'elbe control get_file %s <filename>'" %
                prjdir)
        else:
            print("")
            print("Getting generated Files")
            print("")

            ensure_outdir(opt)

            try:
                system(
                    '%s control --pbuilder-only get_files --output "%s" "%s"' %
                    (elbe_exe, opt.outdir, prjdir))
            except CommandError:
                print("elbe control get_files Failed", file=sys.stderr)
                print("", file=sys.stderr)
                print("dumping logfile", file=sys.stderr)

                try:
                    system('%s control dump_file "%s" log.txt' % (
                        elbe_exe, prjdir))
                except CommandError:
                    print("elbe control dump_file Failed", file=sys.stderr)
                    print("", file=sys.stderr)
                    print("Giving up", file=sys.stderr)

                sys.exit(20)
예제 #13
0
    def execute(self, initvmdir, opt, args):
        try:
            have_session = os.system( "tmux has-session -t ElbeInitVMSession >/dev/null 2>&1" )
        except CommandError as e:
            print ("tmux execution failed, tmux version 1.9 or higher is required")
            sys.exit(20)
        if have_session == 256:
            print ("ElbeInitVMSession does not exist in tmux.", file=sys.stderr)
            print ("Try 'elbe initvm start' to start the session.", file=sys.stderr)
            sys.exit(20)

        try:
            system ('%s initvm ensure --directory "%s"' % (elbe_exe, initvmdir))
        except CommandError:
            print ("Starting the initvm Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)

        # Init cdrom to None, if we detect it, we set it
        cdrom = None

        if len(args) == 1:
            if args[0].endswith ('.xml'):
                # We have an xml file, use that for elbe init
                xmlfile = args[0]
            elif args[0].endswith ('.iso'):
                # We have an iso image, extract xml from there.
                tmp = TmpdirFilesystem ()
                os.system ('7z x -o%s "%s" source.xml' % (tmp.path, args[0]))

                print ('', file=sys.stderr)

                if not tmp.isfile ('source.xml'):
                    print ('Iso image does not contain a source.xml file', file=sys.stderr)
                    print ('This is not supported by "elbe initvm"', file=sys.stderr)
                    print ('', file=sys.stderr)
                    print ('Exiting !!!', file=sys.stderr)
                    sys.exit (20)

                try:
                    exml = ElbeXML (tmp.fname ('source.xml'), skip_urlcheck=True)
                except ValidationError as e:
                    print ('Iso image does contain a source.xml file.', file=sys.stderr)
                    print ('But that xml does not validate correctly', file=sys.stderr)
                    print ('', file=sys.stderr)
                    print ('Exiting !!!', file=sys.stderr)
                    sys.exit (20)

                print ('Iso Image with valid source.xml detected !')
                print ('Image was generated using Elbe Version %s' % exml.get_elbe_version ())

                xmlfile = tmp.fname ('source.xml')
                cdrom = args[0]
            else:
                print ('Unknown file ending (use either xml or iso)', file=sys.stderr)
                sys.exit (20)

            ret, prjdir, err = command_out_stderr ('%s control create_project --retries 60 "%s"' % (elbe_exe, xmlfile))
            if ret != 0:
                print ("elbe control create_project failed.", file=sys.stderr)
                print (err, file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            if cdrom is not None:
                print ("Uploading CDROM. This might take a while")
                try:
                    system ('%s control set_cdrom "%s" "%s"' % (elbe_exe, prjdir, cdrom) )
                except CommandError:
                    print ("elbe control set_cdrom Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)

                print ("Upload finished")

            build_opts = ''
            if opt.build_bin:
                build_opts += '--build-bin '
            if opt.build_sources:
                build_opts += '--build-sources '

            try:
                system ('%s control build "%s" %s' % (elbe_exe, prjdir, build_opts) )
            except CommandError:
                print ("elbe control build Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("Build started, waiting till it finishes")

            try:
                system ('%s control wait_busy "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control wait_busy Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("")
            print ("Build finished !")
            print ("")
            try:
                system ('%s control dump_file "%s" validation.txt' % (elbe_exe, prjdir) )
            except CommandError:
                print ("Project failed to generate validation.txt", file=sys.stderr)
                print ("Getting log.txt", file=sys.stderr)
                try:
                    system ('%s control dump_file "%s" log.txt' % (elbe_exe, prjdir) )
                except CommandError:

                    print ("Failed to dump log.txt", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.skip_download:
                print ("")
                print ("Listing available files:")
                print ("")
                try:
                    system ('%s control get_files "%s"' % (elbe_exe, prjdir) )
                except CommandError:
                    print ("elbe control get_files Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)

                print ("")
                print ('Get Files with: elbe control get_file "%s" <filename>' % prjdir)
            else:
                print ("")
                print ("Getting generated Files")
                print ("")

                ensure_outdir (wdfs, opt)

                try:
                    system ('%s control get_files --output "%s" "%s"' % (
                            elbe_exe, opt.outdir, prjdir ))
                except CommandError:
                    print ("elbe control get_files Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)

                if not opt.keep_files:
                    try:
                        system ('%s control del_project "%s"' % (
                            elbe_exe, prjdir))
                    except CommandError:
                        print ("remove project from initvm failed",
                                file=sys.stderr)
                        sys.exit(20)
예제 #14
0
    def execute(self, initvmdir, opt, args):
        try:
            have_session = os.system( "tmux has-session -t ElbeInitVMSession >/dev/null 2>&1" )
        except CommandError as e:
            print ("tmux execution failed, tmux version 1.9 or higher is required")
            sys.exit(20)
        if have_session == 0:
            print ("ElbeInitVMSession already exists in tmux.", file=sys.stderr)
            print ("", file=sys.stderr)
            print ("There can only exist a single ElbeInitVMSession, and this session", file=sys.stderr)
            print ("can also be used to make your build.", file=sys.stderr)
            print ("See 'elbe initvm submit', 'elbe initvm attach' and 'elbe control'", file=sys.stderr)
            sys.exit(20)

        # Init cdrom to None, if we detect it, we set it
        cdrom = None

        if len(args) == 1:
            if args[0].endswith ('.xml'):
                # We have an xml file, use that for elbe init
                exampl = args[0]
                try:
                    xml = etree( exampl )
                except ValidationError as e:
                    print ('XML file is inavlid: ' + str(e))
                # Use default XML if no initvm was specified
                if not xml.has( "initvm" ):
                    exampl = os.path.join (elbepack.__path__[0], "init/default-init.xml")

            elif args[0].endswith ('.iso'):
                # We have an iso image, extract xml from there.
                tmp = TmpdirFilesystem ()
                os.system ('7z x -o%s "%s" source.xml' % (tmp.path, args[0]))

                if not tmp.isfile ('source.xml'):
                    print ('Iso image does not contain a source.xml file', file=sys.stderr)
                    print ('This is not supported by "elbe initvm"', file=sys.stderr)
                    print ('', file=sys.stderr)
                    print ('Exiting !!!', file=sys.stderr)
                    sys.exit (20)

                try:
                    exml = ElbeXML (tmp.fname ('source.xml'), skip_urlcheck=True)
                except ValidationError as e:
                    print ('Iso image does contain a source.xml file.', file=sys.stderr)
                    print ('But that xml does not validate correctly', file=sys.stderr)
                    print ('', file=sys.stderr)
                    print ('Exiting !!!', file=sys.stderr)
                    sys.exit (20)


                print ('Iso Image with valid source.xml detected !')
                print ('Image was generated using Elbe Version %s' % exml.get_elbe_version ())

                exampl = tmp.fname ('source.xml')
                cdrom = args[0]
            else:
                print ('Unknown file ending (use either xml or iso)', file=sys.stderr)
                sys.exit (20)
        else:
            # No xml File was specified, build the default elbe-init-with-ssh
            exampl = os.path.join (elbepack.__path__[0], "init/default-init.xml")

        try:
            if opt.devel:
                devel = ' --devel'
            else:
                devel = ''

            if cdrom:
                system ('%s init %s --directory "%s" --cdrom "%s" "%s"' % (elbe_exe, devel, initvmdir, cdrom, exampl))
            else:
                system ('%s init %s --directory "%s" "%s"' % (elbe_exe, devel, initvmdir, exampl))

        except CommandError:
            print ("'elbe init' Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)

        try:
            system ('cd "%s"; make' % (initvmdir))
        except CommandError:
            print ("Building the initvm Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)

        try:
            system ('%s initvm start --directory "%s"' % (elbe_exe, initvmdir))
        except CommandError:
            print ("Starting the initvm Failed", file=sys.stderr)
            print ("Giving up", file=sys.stderr)
            sys.exit(20)

        if len(args) == 1:
            # if provided xml file has no initvm section exampl is set to a
            # default initvm XML file. But we need the original file here
            if args[0].endswith ('.xml'):
                # stop here if no project node was specified
                try:
                    x = ElbeXML (args[0])
                except ValidationError as e:
                    print ('XML file is inavlid: ' + str(e))
                    sys.exit(20)
                if not x.has('project'):
                    print ('elbe initvm ready: use "elbe initvm submit myproject.xml" to build a project');
                    sys.exit(0)

                ret, prjdir, err = command_out_stderr ('%s control create_project "%s"' % (elbe_exe, args[0]))
            else:
                ret, prjdir, err = command_out_stderr ('%s control create_project "%s"' % (elbe_exe, exampl))

            if ret != 0:
                print ("elbe control create_project failed.", file=sys.stderr)
                print (err, file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            prjdir = prjdir.strip()

            if cdrom is not None:
                print ("Uploading CDROM. This might take a while")
                try:
                    system ('%s control set_cdrom "%s" "%s"' % (elbe_exe, prjdir, cdrom) )
                except CommandError:
                    print ("elbe control set_cdrom Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)

                print ("Upload finished")

            build_opts = ''
            if opt.build_bin:
                build_opts += '--build-bin '
            if opt.build_sources:
                build_opts += '--build-sources '

            try:
                system ('%s control build "%s" %s' % (elbe_exe, prjdir, build_opts) )
            except CommandError:
                print ("elbe control build Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            try:
                system ('%s control wait_busy "%s"' % (elbe_exe, prjdir) )
            except CommandError:
                print ("elbe control wait_busy Failed", file=sys.stderr)
                print ("Giving up", file=sys.stderr)
                sys.exit(20)

            print ("")
            print ("Build finished !")
            print ("")
            try:
                system ('%s control dump_file "%s" validation.txt' % (elbe_exe, prjdir) )
            except CommandError:
                print ("Project failed to generate validation.txt", file=sys.stderr)
                print ("Getting log.txt", file=sys.stderr)
                try:
                    system ('%s control dump_file "%s" log.txt' % (elbe_exe, prjdir) )
                except CommandError:

                    print ("Failed to dump log.txt", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.skip_download:
                print ("")
                print ("Listing available files:")
                print ("")
                try:
                    system ('%s control get_files "%s"' % (elbe_exe, prjdir) )
                except CommandError:
                    print ("elbe control Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)

                print ("")
                print ('Get Files with: elbe control get_file "%s" <filename>' % prjdir)
            else:
                ensure_outdir (wdfs, opt)

                try:
                    system ('%s control get_files --output "%s" "%s"' % (elbe_exe, opt.outdir, prjdir) )
                except CommandError:
                    print ("elbe control get_files Failed", file=sys.stderr)
                    print ("Giving up", file=sys.stderr)
                    sys.exit(20)