Ejemplo n.º 1
0
    def execute(self, opt, args):
        tmp = TmpdirFilesystem ()

        if opt.xmlfile:
            ret, prjdir, err = command_out_stderr ('%s control create_project' % (elbe_exe))
            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()
            ret, msg, err = command_out_stderr ('%s control set_xml "%s" "%s"' % (elbe_exe, prjdir, opt.xmlfile))

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

            if opt.writeproject:
                wpf = open (opt.writeproject, "w")
                wpf.write (prjdir)
                wpf.close()

        elif opt.project:
            prjdir = opt.project
        else:
            print ('you need to specify --project option', file=sys.stderr)
            sys.exit(20)


        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 ("")
Ejemplo n.º 2
0
    def __enter__(self):
        self.outxml = NamedTemporaryFile(prefix='elbe', suffix='xml')

        cmd = '%s preprocess %s -o %s %s' % (elbe_exe, self.options,
                                             self.outxml.name, self.xmlfile)
        ret, _, err = command_out_stderr(cmd)
        if ret != 0:
            print("elbe preprocess failed.", file=sys.stderr)
            print(err, file=sys.stderr)
            raise CommandError(cmd, ret)

        return self
Ejemplo n.º 3
0
    def get_command_out(self, cmd, allow_fail=False):

        self.printo("getting output from cmd +%s+" % cmd)

        ret, output, stderr = command_out_stderr(cmd)

        if len(stderr) != 0:
            self.verbatim_start()
            self.print_raw(stderr)
            self.verbatim_end()

        if ret != 0:
            self.printo("Command failed with errorcode %d" % ret)
            if not allow_fail:
                raise CommandError(cmd, ret)

        return output
Ejemplo n.º 4
0
    def get_command_out(self, cmd, allow_fail=False):

        self.printo("getting output from cmd +%s+" % cmd)

        ret, output, stderr = command_out_stderr(cmd)

        if stderr:
            self.verbatim_start()
            self.print_raw(stderr)
            self.verbatim_end()

        if ret != 0:
            self.printo("Command failed with errorcode %d" % ret)
            if not allow_fail:
                raise CommandError(cmd, ret)

        return output
def submit_and_dl_result(xmlfile, cdrom, opt):

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

    try:
        with PreprocessWrapper(xmlfile, opt) as ppw:
            xmlfile = ppw.preproc

            ret, prjdir, err = command_out_stderr('%s control create_project' %
                                                  (elbe_exe))
            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()

            cmd = '%s control set_xml %s %s' % (elbe_exe, prjdir, xmlfile)
            ret, _, err = command_out_stderr(cmd)
            if ret != 0:
                print("elbe control set_xml failed2", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)
    except CommandError:
        # this is the failure from PreprocessWrapper
        # it already printed the error message from
        # elbe preprocess
        print("Giving up", file=sys.stderr)
        sys.exit(20)

    if opt.writeproject:
        with open(opt.writeproject, "w") as wpf:
            wpf.write(prjdir)

    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 '
    if cdrom:
        build_opts += '--skip-pbuilder '

    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('', file=sys.stderr)
        print('The project will not be deleted from the initvm.',
              file=sys.stderr)
        print('The files, that have been built, can be downloaded using:',
              file=sys.stderr)
        print('%s control get_files --output "%s" "%s"' %
              (elbe_exe, opt.outdir, prjdir),
              file=sys.stderr)
        print("", file=sys.stderr)
        print('The project can then be removed using:', file=sys.stderr)
        print('%s control del_project "%s"' % (elbe_exe, prjdir),
              file=sys.stderr)
        print("", file=sys.stderr)
        sys.exit(10)

    print("")
    print("Build finished !")
    print("")

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

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

        try:
            system('%s control wait_busy "%s"' % (elbe_exe, prjdir))
        except CommandError:
            print('elbe control wait_busy Failed, while waiting for the SDK',
                  file=sys.stderr)
            print('', file=sys.stderr)
            print('The project will not be deleted from the initvm.',
                  file=sys.stderr)
            print('The files, that have been built, can be downloaded using:',
                  file=sys.stderr)
            print('%s control get_files --output "%s" "%s"' %
                  (elbe_exe, opt.outdir, prjdir),
                  file=sys.stderr)
            print("", file=sys.stderr)
            print('The project can then be removed using:', file=sys.stderr)
            print('%s control del_project "%s"' % (elbe_exe, prjdir),
                  file=sys.stderr)
            print("", file=sys.stderr)
            sys.exit(10)

        print("")
        print("SDK 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(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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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):
        crossopt = ""
        if opt.cross:
            crossopt = "--cross"
        if opt.noccache:
            ccacheopt = "--no-ccache"
            ccachesize = ""
        else:
            ccacheopt = "--ccache-size"
            ccachesize = opt.ccachesize

        if opt.xmlfile:
            try:
                with PreprocessWrapper(opt.xmlfile, opt) as ppw:
                    ret, prjdir, err = command_out_stderr(
                        '%s control create_project' % (elbe_exe))
                    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()
                    ret, _, err = command_out_stderr(
                        '%s control set_xml "%s" "%s"' %
                        (elbe_exe, prjdir, ppw.preproc))

                    if ret != 0:
                        print("elbe control set_xml failed.", file=sys.stderr)
                        print(err, file=sys.stderr)
                        print("Giving up", file=sys.stderr)
                        sys.exit(20)
            except CommandError:
                # this is the failure from PreprocessWrapper
                # it already printed the error message from
                # elbe preprocess
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.writeproject:
                wpf = open(opt.writeproject, "w")
                wpf.write(prjdir)
                wpf.close()

        elif opt.project:
            prjdir = opt.project
        else:
            print("you need to specify --project option", file=sys.stderr)
            sys.exit(20)

        print("Creating pbuilder")

        try:
            system('%s control build_pbuilder "%s" %s %s %s' %
                   (elbe_exe, prjdir, crossopt, ccacheopt, ccachesize))
        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("")
    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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def execute(self, opt, _args):

        if opt.xmlfile:
            try:
                with PreprocessWrapper(opt.xmlfile, opt) as ppw:
                    ret, prjdir, err = command_out_stderr(
                        '%s control create_project' % (elbe_exe))
                    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()
                    ret, _, err = command_out_stderr(
                        '%s control set_xml "%s" "%s"' %
                        (elbe_exe, prjdir, ppw.preproc))

                    if ret != 0:
                        print("elbe control set_xml failed.", file=sys.stderr)
                        print(err, file=sys.stderr)
                        print("Giving up", file=sys.stderr)
                        sys.exit(20)
            except CommandError:
                # this is the failure from PreprocessWrapper
                # it already printed the error message from
                # elbe preprocess
                print("Giving up", file=sys.stderr)
                sys.exit(20)

            if opt.writeproject:
                wpf = open(opt.writeproject, "w")
                wpf.write(prjdir)
                wpf.close()

        elif opt.project:
            prjdir = opt.project
        else:
            print("you need to specify --project option", file=sys.stderr)
            sys.exit(20)

        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("")
Ejemplo n.º 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)
Ejemplo n.º 13
0
def submit_and_dl_result(xmlfile, cdrom, opt):

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

    try:
        with PreprocessWrapper(xmlfile, opt) as ppw:
            xmlfile = ppw.preproc

            ret, prjdir, err = command_out_stderr(
                '%s control create_project' % (elbe_exe))
            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()

            cmd = '%s control set_xml %s %s' % (elbe_exe, prjdir, xmlfile)
            ret, _, err = command_out_stderr(cmd)
            if ret != 0:
                print("elbe control set_xml failed2", file=sys.stderr)
                print(err, file=sys.stderr)
                print("Giving up", file=sys.stderr)
                sys.exit(20)
    except CommandError:
        # this is the failure from PreprocessWrapper
        # it already printed the error message from
        # elbe preprocess
        print("Giving up", file=sys.stderr)
        sys.exit(20)

    if opt.writeproject:
        with open(opt.writeproject, "w") as wpf:
            wpf.write(prjdir)

    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 '
    if cdrom:
        build_opts += '--skip-pbuilder '

    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(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)
Ejemplo n.º 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 == 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)
Ejemplo n.º 15
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)