Example #1
0
    def build(self):
        logger.info('Build started, ID: %s, Target: %s' % (self.Id, self.Target) )
        if builder.createdirectories():
            if not self.Noconf == True:
                builder.createconfig()
            
            #write summary to output directory
            builder.summary_json()

            #handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                cptree(mkfilesdir, self.FilesDir) 
                logger.info('Copied files from %s to %s.' % (mkfilesdir, self.FilesDir) )


            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(config.buildroots_dir, self.Target, "files")
            if os.path.exists(ibfilesdir):
                cptree(ibfilesdir, self.FilesDir) 
            
            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
                cfilesdir = os.path.join(config.communityfiles_dir, self.Community, "files")
                logger.info('Copied files from %s to %s' % (cfilesdir, self.FilesDir) )
                if os.path.exists(cfilesdir):
                    cptree(cfilesdir, self.FilesDir)
                    if self.Community == 'weimar':
                        with open(self.FilesDir + "/etc/init.d/apply_profile.code", "r+") as source:
                            data = source.read()
                            data1 = data.replace("#SIM_ARG1=\"olympia\"", "SIM_ARG1=\"ffweimar\"")
                            data2 = data1.replace("#SIM_ARG2=\"adhoc\"", "SIM_ARG2=\"hybrid\"")
                            logger.info("node number: " + self.nodenumber)
                            data3 = data2.replace ("#SIM_ARG3=2", "SIM_ARG3=" + self.nodenumber)
			    source.seek(0)
			    source.write(data3)
			    source.close()
            
            # Handle certs
            p = subprocess.Popen("sudo /etc/openvpn/ffvpn/make-cert-for-website.sh 'ffvpn-"+self.Hostname+"' '"+self.Email+"'", stdout=subprocess.PIPE, shell=True)
            (name, err) = p.communicate()
            filename = "/var/www/vhosts/freifunk-halle/website/htdocs/vpn/dl/" + name
            if p.returncode == 0 and os.access(filename, os.R_OK):
                logger.info('extracting %s' % filename)
                pu_ret = processupload.extract(filename, self.FilesDir)
                if pu_ret:
                    logger.warning(str(pu_ret))
                    # delete certificate tar file
                    try:
                        os.remove(filename)
                        logger.debug('Deleted %s' % filename)
                    except:
                        logger.warning('Could not delete %s' % filename)

            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(request.folder, "uploads", self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info('extracting %s' % uploaded_file)
                    pu_ret = processupload.extract(uploaded_file, self.FilesDir)
                    if pu_ret:
                        logger.warning(str(pu_ret))
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug('Deleted %s' % uploaded_file)
                    except:
                        logger.warning('Could not delete %s' % uploaded_file)

            out = open(self.BinDir + "/build.log", "w")
            if self.Profile:
                option_profile = "PROFILE='" + self.Profile + "'"
            else:
                option_profile = ""

            # Copy community profile
            if config.communitysupport and self.Community:
                communityprofile = os.path.join(config.profiles, 'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning('The communityfile %s does not exist!' % communityprofile)
                else:
                    logger.debug('Copied %s to %s' % (communityprofile, self.FilesDirConfig) )
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # check if there are any files to include in the image
            if len(os.listdir(self.FilesDir)) > 0:
                option_files = " FILES='" + self.FilesDir + "'"
            else:
                option_files=""

            if self.Pkgs:
                option_pkgs = " PACKAGES='" + self.Pkgs + "'"
            else:
                option_pkgs = " "

            cmd = "cd " + config.buildroots_dir + "/" + self.Target + "; make image " + option_profile + option_pkgs + " BIN_DIR='" + self.BinDir + "' " + option_files
            ret = subprocess.call([cmd, ""], stdout=out, stderr=subprocess.STDOUT, shell=True)
            builder.build_links_json()
            if ret != 0:
                if ret < 0:
                    logger.critical('make was killed by signal %s', str(ret))
                else:
                    logger.critical('make failed with return code %s', str(ret))
                return 2
            else:
                return 0
        else:
            return 3
Example #2
0
    def build(self):
        logger.info('Build started, ID: %s, Target: %s' %
                    (self.Id, self.Target))
        if builder.createdirectories():
            if not self.Noconf == True:
                builder.createconfig()

            #write summary to output directory
            builder.summary_json()

            #handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                cptree(mkfilesdir, self.FilesDir)
                logger.info('Copied files from %s to %s.' %
                            (mkfilesdir, self.FilesDir))

            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(config.buildroots_dir, self.Target,
                                      "files")
            if os.path.exists(ibfilesdir):
                cptree(ibfilesdir, self.FilesDir)

            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
                cfilesdir = os.path.join(config.communityfiles_dir,
                                         self.Community, "files")
                logger.info('Copied files from %s to %s' %
                            (cfilesdir, self.FilesDir))
                if os.path.exists(cfilesdir):
                    cptree(cfilesdir, self.FilesDir)
                    if self.Community == 'weimar':
                        with open(
                                self.FilesDir +
                                "/etc/init.d/apply_profile.code",
                                "r+") as source:
                            data = source.read()
                            data1 = data.replace("#SIM_ARG1=\"olympia\"",
                                                 "SIM_ARG1=\"ffweimar\"")
                            data2 = data1.replace("#SIM_ARG2=\"adhoc\"",
                                                  "SIM_ARG2=\"hybrid\"")
                            logger.info("node number: " + self.nodenumber)
                            data3 = data2.replace(
                                "#SIM_ARG3=2", "SIM_ARG3=" + self.nodenumber)
                            source.seek(0)
                            source.write(data3)
                            source.close()

            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(request.folder, "uploads",
                                             self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info('extracting %s' % uploaded_file)
                    pu_ret = processupload.extract(uploaded_file,
                                                   self.FilesDir)
                    if pu_ret:
                        logger.warning(str(pu_ret))
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug('Deleted %s' % uploaded_file)
                    except:
                        logger.warning('Could not delete %s' % uploaded_file)

            out = open(self.BinDir + "/build.log", "w")
            if self.Profile:
                option_profile = "PROFILE='" + self.Profile + "'"
            else:
                option_profile = ""

            # Copy community profile
            if self.Community:
                communityprofile = os.path.join(config.profiles,
                                                'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning('The communityfile %s does not exist!' %
                                   communityprofile)
                else:
                    logger.debug('Copied %s to %s' %
                                 (communityprofile, self.FilesDirConfig))
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # check if there are any files to include in the image
            if len(os.listdir(self.FilesDir)) > 0:
                option_files = " FILES='" + self.FilesDir + "'"
            else:
                option_files = ""

            if self.Pkgs:
                option_pkgs = " PACKAGES='" + self.Pkgs + "'"
            else:
                option_pkgs = " "

            cmd = "cd " + config.buildroots_dir + "/" + self.Target + "; make image " + option_profile + option_pkgs + " BIN_DIR='" + self.BinDir + "' " + option_files
            ret = subprocess.call([cmd, ""],
                                  stdout=out,
                                  stderr=subprocess.STDOUT,
                                  shell=True)
            builder.build_links_json()
            if ret != 0:
                if ret < 0:
                    logger.critical('make was killed by signal %s', str(ret))
                else:
                    logger.critical('make failed with return code %s',
                                    str(ret))
                return 2
            else:
                return 0
        else:
            return 3
Example #3
0
    def _build(self):
        status = 3
        out = ''
        settings_summary_json = {}
        logger.info('Build started, ID: %s, Target: %s' %
                    (self.Id, self.Target))
        if self._createdirectories():
            if not self.Noconf:
                self._createconfig()

            # write summary to output directory
            settings_summary_json = self._summary_json()
            self._summary_json_write(settings_summary_json)

            # handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                mkutils.cptree(mkfilesdir, self.FilesDir)
                logger.info('Copied files from %s to %s.' %
                            (mkfilesdir, self.FilesDir))

            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(config.buildroots_dir, self.Target,
                                      "files")
            if os.path.exists(ibfilesdir):
                mkutils.cptree(ibfilesdir, self.FilesDir)

            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
                cfilesdir = os.path.join(config.communityfiles_dir,
                                         self.Community, "files")
                logger.info('Copied files from %s to %s' %
                            (cfilesdir, self.FilesDir))
                if os.path.exists(cfilesdir):
                    mkutils.cptree(cfilesdir, self.FilesDir)
                    if self.Community == 'weimar':
                        filesdir = "%s/etc/init.d/apply_profile.code" % \
                            self.FilesDir
                        with open(filesdir) as source:
                            data = source.read()
                            data1 = data.replace("#SIM_ARG1=\"olympia\"",
                                                 "SIM_ARG1=\"ffweimar\"")
                            data2 = data1.replace("#SIM_ARG2=\"adhoc\"",
                                                  "SIM_ARG2=\"hybrid\"")
                            logger.info("node number: " + self.Nodenumber)
                            data3 = data2.replace(
                                "#SIM_ARG3=2", "SIM_ARG3=" + self.Nodenumber)
                            source.seek(0)
                            source.write(data3)
                            source.close()

            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(request.folder, "uploads",
                                             self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info('extracting %s' % uploaded_file)
                    pu_ret = processupload.extract(uploaded_file,
                                                   self.FilesDir)
                    if pu_ret:
                        logger.warning(str(pu_ret))
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug('Deleted %s' % uploaded_file)
                    except:
                        logger.warning('Could not delete %s' % uploaded_file)

            # Copy community profile
            if config.communitysupport and self.Community:
                communityprofile = os.path.join(config.profiles,
                                                'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning('The communityfile %s does not exist!' %
                                   communityprofile)
                else:
                    logger.debug('Copied %s to %s' %
                                 (communityprofile, self.FilesDirConfig))
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # construct the commandline
            path = os.path.join(config.buildroots_dir, self.Target)
            cmdline = ["make", "image"]
            if len(self.Profile) > 0:
                cmdline.append("PROFILE=%s" % self.Profile)
            if self.Pkgs:
                cmdline.append("PACKAGES=%s" % self.Pkgs)
            if len(os.listdir(self.FilesDir)) > 0:
                cmdline.append("FILES=%s" % self.FilesDir)
            if len(self.BinDir) > 0:
                cmdline.append("BIN_DIR=%s" % self.BinDir)

            proc = subprocess.Popen(cmdline,
                                    cwd=path,
                                    stdout=subprocess.PIPE,
                                    shell=False,
                                    stderr=subprocess.STDOUT)

            out, _ = proc.communicate()
            ret = proc.returncode

            self._download_links_write()
            if ret != 0:
                if ret < 0:
                    logger.critical('make was killed by signal %s', str(ret))
                else:
                    logger.critical('make failed with return code %s',
                                    str(ret))
                status = 2
            else:
                status = 0

            # write build log
            build_log_file = os.path.join(self.BinDir, "build.log")
            mkutils.write_file(build_log_file, out)

        return status, out, settings_summary_json
Example #4
0
    def build(self):
        logger.info("Build started, ID: " + self.Id + ", target: " +
                    self.Target)
        if builder.createdirectories():
            if not self.Noconf == True:
                builder.createconfig()

            #handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                cptree(mkfilesdir, self.FilesDir)
                logger.info("Copied files from " + mkfilesdir)

            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(config.buildroots_dir, self.Target,
                                      "files")
            if os.path.exists(ibfilesdir):
                cptree(ibfilesdir, self.FilesDir)

            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
                cfilesdir = os.path.join(config.communityfiles_dir,
                                         self.Community, "files")
                if os.path.exists(cfilesdir):
                    cptree(cfilesdir, self.FilesDir)

            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(request.folder, "uploads",
                                             self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info("extracting " + uploaded_file)
                    pu_ret = processupload.extract(uploaded_file,
                                                   self.FilesDir)
                    if pu_ret:
                        logger.warning(pu_ret)
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug("Deleted " + uploaded_file)
                    except:
                        logger.warning("Could not delete " + uploaded_file)

            out = open(self.BinDir + "/build.log", "w")
            if self.Profile:
                option_profile = "PROFILE='" + self.Profile + "'"
            else:
                option_profile = ""

            # Copy community profile
            if self.Community:
                communityprofile = os.path.join(config.profiles,
                                                'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning('The communityfile %s does not exist!' %
                                   communityprofile)
                else:
                    logger.debug('Copied %s to %s' %
                                 (communityprofile, self.FilesDirConfig))
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # check if there are any files to include in the image
            if len(os.listdir(self.FilesDir)) > 0:
                option_files = " FILES='" + self.FilesDir + "'"
            else:
                option_files = ""

            if self.Pkgs:
                option_pkgs = " PACKAGES='" + self.Pkgs + "'"
            else:
                option_pkgs = " "

            cmd = "cd " + config.buildroots_dir + "/" + self.Target + "; make image " + option_profile + option_pkgs + " BIN_DIR='" + self.BinDir + "' " + option_files
            ret = subprocess.call([cmd, ""],
                                  stdout=out,
                                  stderr=subprocess.STDOUT,
                                  shell=True)
            builder.build_links_json()
            if ret != 0:
                if ret < 0:
                    logger.critical("make was killed by signal", -ret)
                else:
                    logger.critical("make failed with return code", ret)
                return 2
            else:
                return 0
        else:
            return 3
Example #5
0
    def build(self):
        logger.info("Build started, ID: " + self.Id + ", target: " + self.Target)
        if builder.createdirectories():
            if not self.Noconf == True:
                builder.createconfig()

            #handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                cptree(mkfilesdir, self.FilesDir) 
                logger.info("Copied files from " + mkfilesdir)


            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(config.buildroots_dir, self.Target, "files")
            if os.path.exists(ibfilesdir):
                cptree(ibfilesdir, self.FilesDir) 

            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
		cfilesdir = os.path.join(config.communityfiles_dir, self.Community, "files")
                if os.path.exists(cfilesdir):
                    cptree(cfilesdir, self.FilesDir)
                    
            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(request.folder, "uploads", self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info("extracting " + uploaded_file)
                    pu_ret = processupload.extract(uploaded_file, self.FilesDir)
                    if pu_ret:
                        logger.warning(pu_ret)
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug("Deleted " + uploaded_file)
                    except:
                        logger.warning("Could not delete " + uploaded_file)

            out = open(self.BinDir + "/build.log", "w")
            if self.Profile:
                option_profile = "PROFILE='" + self.Profile + "'"
            else:
                option_profile = ""

            # Copy community profile
            if self.Community:
                communityprofile = os.path.join(config.profiles, 'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning('The communityfile %s does not exist!' % communityprofile)
                else:
                    logger.debug('Copied %s to %s' % (communityprofile, self.FilesDirConfig))
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # check if there are any files to include in the image
            if len(os.listdir(self.FilesDir)) > 0:
                option_files = " FILES='" + self.FilesDir + "'"
            else:
                option_files=""

            if self.Pkgs:
                option_pkgs = " PACKAGES='" + self.Pkgs + "'"
            else:
                option_pkgs = " "

            cmd = "cd " + config.buildroots_dir + "/" + self.Target + "; make image " + option_profile + option_pkgs + " BIN_DIR='" + self.BinDir + "' " + option_files
            ret = subprocess.call([cmd, ""], stdout=out, stderr=subprocess.STDOUT, shell=True)
            builder.build_links_json()
            if ret != 0:
                if ret < 0:
                    logger.critical("make was killed by signal", -ret)
                else:
                    logger.critical("make failed with return code", ret)
                return 2
            else:
                return 0
        else:
            return 3
Example #6
0
    def _build(self):
        status = 3
        out = ''
        settings_summary_json = {}
        logger.info(
            'Build started, ID: %s, Target: %s' %
            (self.Id, self.Target))
        if self._createdirectories():
            if not self.Noconf:
                self._createconfig()

            # write summary to output directory
            settings_summary_json = self._summary_json()
            self._summary_json_write(settings_summary_json)

            # handle files in <meshkit>/files
            mkfilesdir = os.path.join(request.folder, "files")
            if os.path.exists(mkfilesdir):
                mkutils.cptree(mkfilesdir, self.FilesDir)
                logger.info(
                    'Copied files from %s to %s.' %
                    (mkfilesdir, self.FilesDir))

            # handle files/ in imagebuilder
            ibfilesdir = os.path.join(
                config.buildroots_dir,
                self.Target,
                "files")
            if os.path.exists(ibfilesdir):
                mkutils.cptree(ibfilesdir, self.FilesDir)

            # handle community files (custom files uploaded by community)
            if config.communitysupport and config.communityfiles_dir:
                cfilesdir = os.path.join(
                    config.communityfiles_dir,
                    self.Community,
                    "files")
                logger.info(
                    'Copied files from %s to %s' %
                    (cfilesdir, self.FilesDir))
                if os.path.exists(cfilesdir):
                    mkutils.cptree(cfilesdir, self.FilesDir)
                    if self.Community == 'weimar':
                        filesdir = "%s/etc/init.d/apply_profile.code" % \
                            self.FilesDir
                        with open(filesdir) as source:
                            data = source.read()
                            data1 = data.replace(
                                "#SIM_ARG1=\"olympia\"",
                                "SIM_ARG1=\"ffweimar\"")
                            data2 = data1.replace(
                                "#SIM_ARG2=\"adhoc\"",
                                "SIM_ARG2=\"hybrid\"")
                            logger.info("node number: " + self.Nodenumber)
                            data3 = data2.replace(
                                "#SIM_ARG3=2",
                                "SIM_ARG3=" +
                                self.Nodenumber)
                            source.seek(0)
                            source.write(data3)
                            source.close()

            # Handle uploaded archive
            if self.Upload:
                uploaded_file = os.path.join(
                    request.folder,
                    "uploads",
                    self.Upload)
                if os.access(uploaded_file, os.R_OK):
                    logger.info('extracting %s' % uploaded_file)
                    pu_ret = processupload.extract(
                        uploaded_file, self.FilesDir)
                    if pu_ret:
                        logger.warning(str(pu_ret))
                    # delete uploaded file
                    try:
                        os.remove(uploaded_file)
                        logger.debug('Deleted %s' % uploaded_file)
                    except:
                        logger.warning('Could not delete %s' % uploaded_file)

            # Copy community profile
            if config.communitysupport and self.Community:
                communityprofile = os.path.join(
                    config.profiles,
                    'profile_' + self.Community)
                if not os.path.exists(communityprofile):
                    logger.warning(
                        'The communityfile %s does not exist!' %
                        communityprofile)
                else:
                    logger.debug(
                        'Copied %s to %s' %
                        (communityprofile, self.FilesDirConfig))
                    shutil.copy(communityprofile, self.FilesDirConfig)

            # construct the commandline
            path = os.path.join(config.buildroots_dir, self.Target)
            cmdline = ["make", "image"]
            if len(self.Profile) > 0:
                cmdline.append("PROFILE=%s" % self.Profile)
            if self.Pkgs:
                cmdline.append("PACKAGES=%s" % self.Pkgs)
            if len(os.listdir(self.FilesDir)) > 0:
                cmdline.append("FILES=%s" % self.FilesDir)
            if len(self.BinDir) > 0:
                cmdline.append("BIN_DIR=%s" % self.BinDir)

            proc = subprocess.Popen(
                cmdline,
                cwd=path,
                stdout=subprocess.PIPE,
                shell=False,
                stderr=subprocess.STDOUT
            )

            out, _ = proc.communicate()
            ret = proc.returncode

            self._download_links_write()
            if ret != 0:
                if ret < 0:
                    logger.critical('make was killed by signal %s', str(ret))
                else:
                    logger.critical(
                        'make failed with return code %s',
                        str(ret))
                status = 2
            else:
                status = 0

            # write build log
            build_log_file = os.path.join(self.BinDir, "build.log")
            mkutils.write_file(build_log_file, out)

        return status, out, settings_summary_json