Exemplo n.º 1
0
    def grab_base_flat(self, top):
        """Method that collects all the files from EPICS base into a debian package like format

        Parameters
        ----------
        top : str
            Path to the staging area for the tarring process, usually __temp__
        """

        base_path = self.install_config.base_path
        LOG.debug('Grabbing flat epics base files')
        for arch in self.arch_list:
            self.grab_folder(base_path + '/bin/' + arch, top + '/bin/' + arch)
            self.grab_folder(base_path + '/lib/' + arch, top + '/lib/' + arch)
        self.grab_folder(base_path + '/cfg', top + '/cfg')
        self.grab_folder(base_path + '/lib/perl', top + '/lib/perl')
        self.grab_folder(base_path + '/configure', top + '/configure')

        LOG.debug(
            'Creating rules.d directory to allow for additional rule sets')
        os.mkdir(top + '/configure/rules.d')
        os.mkdir(top + '/req')

        self.grab_folder(base_path + '/include', top + '/include')
        self.grab_folder(base_path + '/startup', top + '/startup')
        self.grab_folder(base_path + '/db', top + '/db')
        self.grab_folder(base_path + '/dbd', top + '/dbd')
        self.grab_folder(base_path + '/templates', top + '/templates')
    def cleanup_tar_staging(self, filename, module=None):
        """Function that cleans up tar staging point, and closes readme file.

        Parameters
        ----------
        filename : str
            file path string
        module : InstallModule
            Optional install module to create single module add-on package
        
        Returns
        -------
        int
            Return code of tar creation call.
        """
        
        LOG.debug('Generating README file with module version and append instructions...')
        shutil.copy(installSynApps.join_path(self.output_location, 'README_{}.txt'.format(filename)), installSynApps.join_path('__temp__', 'README_{}.txt'.format(filename)))

        LOG.write('Tarring...')
        out = subprocess.call(['tar', 'czf', filename + '.tgz', '-C', '__temp__', '.'])
        if out < 0:
            return out
        os.rename(filename + '.tgz', installSynApps.join_path(self.output_location, filename + '.tgz'))
        LOG.write('Done. Wrote tarball to {}.'.format(self.output_location))
        LOG.write('Name of tarball: {}'.format(installSynApps.join_path(self.output_location, filename + '.tgz')))
        shutil.rmtree('__temp__')
        return out
Exemplo n.º 3
0
    def acquire_dependecies(self, dependency_script_path):
        """Method that runs dependency install shell/batch script

        Parameters
        ----------
        dependency_script_path : str
            path to dependency shell/batch script
        """

        LOG.debug('Grabbing dependencies via script {}'.format(
            dependency_script_path))
        if os.path.exists(dependency_script_path) and os.path.isfile(
                dependency_script_path):
            if dependency_script_path.endswith('.bat'):
                exec = dependency_script_path
            else:
                exec = 'bash {}'.format(dependency_script_path)
            LOG.print_command(exec)
            proc = Popen(exec.split(' '))
            proc.wait()
            ret = proc.returncode
            if ret != 0:
                LOG.write(
                    'Dependency script exited with non-zero exit code: {}'.
                    format(ret))
Exemplo n.º 4
0
    def grab_base(self, top, include_src=False, flat_grab=False):
        """Function that copies all of the required folders from EPICS_BASE

        Parameters
        ----------
        top : str
            resulting location - __temp__
        """

        if flat_grab:
            self.grab_base_flat(top)
            return

        base_path = self.install_config.base_path
        if not include_src:
            LOG.debug('Grabbing lean epics base files')
            for arch in self.arch_list:
                self.grab_folder(base_path + '/bin/' + arch,
                                 top + '/base/bin/' + arch)
                self.grab_folder(base_path + '/lib/' + arch,
                                 top + '/base/lib/' + arch)
            self.grab_folder(base_path + '/lib/perl', top + '/base/lib/perl')
            self.grab_folder(base_path + '/cfg', top + '/base/cfg')
            self.grab_folder(base_path + '/configure', top + '/base/configure')
            self.grab_folder(base_path + '/include', top + '/base/include')
            self.grab_folder(base_path + '/startup', top + '/base/startup')
            self.grab_folder(base_path + '/db', top + '/base/db')
            self.grab_folder(base_path + '/dbd', top + '/base/dbd')
        else:
            LOG.debug('Grabbing full epics base files')
            self.grab_folder(base_path, top + '/base')
Exemplo n.º 5
0
    def add_missing_support_macros(self):
        """Function that appends any paths to the support/configure/RELEASE file that were not in it originally
        """

        to_append_commented = []
        to_append = []
        for module in self.install_config.get_module_list():
            if module.clone == "YES":
                was_found = False
                rel_file = open(installSynApps.join_path(self.install_config.support_path, "configure/RELEASE"), "r")
                line = rel_file.readline()
                while line:
                    if line.startswith(module.name + "="):
                        was_found = True
                    line = rel_file.readline()
                if not was_found and not module.name in self.add_to_release_blacklist and not module.name.startswith("AD"):
                    if module.build == "YES":
                        to_append.append([module.name, module.rel_path])
                    else:
                        to_append_commented.append([module.name, module.rel_path])
                rel_file.close()
        app_file = open(self.install_config.support_path + "/configure/RELEASE", "a")
        for mod in to_append:
            LOG.debug('Adding {} path to support/configure/RELEASE'.format(mod[0]))
            app_file.write("{}={}\n".format(mod[0], mod[1]))
        for mod in to_append_commented:
            LOG.debug('Adding commented {} path to support/configure/RELEASE'.format(mod[0]))
            app_file.write("#{}={}\n".format(mod[0], mod[1]))
        app_file.close()
Exemplo n.º 6
0
    def generate_unique_cmd(self, action):

        LOG.debug('Generating template unique.cmd from ioc environment...')
        ioc_path = installSynApps.join_path(self.ioc_template_dir,
                                            action.ioc_name)
        unique_fp = open(installSynApps.join_path(ioc_path, 'unique.cmd'), 'w')

        unique_fp.write(
            '###############################################################\n'
        )
        unique_fp.write(
            '# installSynApps Auto-Generated IOC Template{:<19}#\n'.format(''))
        unique_fp.write(
            '# Meant for use with bundles running ADCore {:<19} #\n'.format(
                self.install_config.get_core_version()))
        unique_fp.write('# Generated: {:<53}#\n'.format(
            str(datetime.datetime.now())))
        unique_fp.write(
            '###############################################################\n\n\n'
        )

        for env_var in action.epics_environment.keys():
            unique_fp.write('epicsEnvSet("{}",{}"{}")\n'.format(
                env_var, ' ' * (32 - len(env_var)),
                action.epics_environment[env_var]))

        unique_fp.close()
Exemplo n.º 7
0
    def generate_uninstall(self):
        """Function that generates an uninstall file based on currently loaded install_config
        """

        LOG.debug('Autogenerating bash uninstall script')
        uninstall_fp = open(installSynApps.join_path(self.install_config.install_location, "/autogenerated/uninstall.sh"), "w+")
        uninstall_fp.write("#!/bin/bash\n")

        uninstall_fp.write(self.message)

        modules = self.install_config.get_module_list()
        modules.reverse()

        for module in modules:
            if module.build == "YES":
                uninstall_fp.write("{}={}\n".format(module.name, module.abs_path))

        for module in modules:
            if module.build == "YES":
                uninstall_fp.write("cd ${}\n".format(module.name))
                uninstall_fp.write("make clean uninstall\n")
                uninstall_fp.write("make clean uninstall\n")
    
        modules.reverse()
        uninstall_fp.close()
Exemplo n.º 8
0
    def update_macros_dir(self,
                          macro_replace_list,
                          target_dir,
                          force_override_comments=False):
        """Function that updates the macros for all files in a target location, given a list of macro-value pairs

        Parameters
        ----------
        macro_replace_list : List
            list containting macro-value pairs
        target_dir : str
            path of target dir for which all macros will be edited.
        """

        LOG.debug('Updating macros in directory {}'.format(target_dir))
        if os.path.exists(target_dir) and os.path.isdir(target_dir):
            for file in os.listdir(target_dir):
                if os.path.isfile(
                        target_dir + "/" + file) and not file.endswith(
                            ".pl"
                        ) and file != "Makefile" and not file.endswith(".ioc"):
                    self.update_macros_file(macro_replace_list,
                                            target_dir,
                                            file,
                                            force=force_override_comments)
Exemplo n.º 9
0
    def create_config_file(self, action):

        LOG.debug('Generating config file for use with procServ...')
        ioc_path = installSynApps.join_path(self.ioc_template_dir,
                                            action.ioc_name)
        config_fp = open(installSynApps.join_path(ioc_path, 'config'), 'w')
        config_fp.write('NAME={}\nPORT={}\nUSER=softioc\nHOST={}\n'.format(
            action.ioc_name, '4000', 'localhost'))
        config_fp.close()
Exemplo n.º 10
0
    def cleanup_modules(self):
        """Function responsible for cleaning up directories that were not selected to clone
        """

        if self.install_config != None and isinstance(self.install_config, IC.InstallConfiguration):
            for module in self.install_config.modules:
                if isinstance(module, IM.InstallModule):
                    if module.clone == "NO" and os.path.exists(module.abs_path):
                        LOG.debug('Removing unused repo {}'.format(module.name))
                        shutil.rmtree(module.abs_path)
Exemplo n.º 11
0
    def initialize_dir(self):
        """Function that creates an autogenerated directory
        """

        autogenerated_dir = installSynApps.join_path(self.install_config.install_location, "autogenerated")
        if os.path.exists(autogenerated_dir):
            LOG.debug('Removing existing autogenerated script directory')
            shutil.rmtree(autogenerated_dir)
        
        LOG.debug('Creating autogenerated script directory')
        os.mkdir(autogenerated_dir)
Exemplo n.º 12
0
    def generate_env_paths(self, ioc_top_path, ioc_boot_path, target, action):

        LOG.debug('Generating template envPaths based on compiled binaries...')
        ioc_path = installSynApps.join_path(self.ioc_template_dir,
                                            action.ioc_name)
        envPaths_fp = open(installSynApps.join_path(ioc_path, 'envPaths'), 'w')

        arch = 'linux-x86_64'
        if platform == 'win32':
            arch = 'windows-x64-static'

        envPaths_fp.write(
            '# Relative envPaths file auto-generated by installSynApps\n#\n')
        envPaths_fp.write(
            '# The BUNDLE_LOC env variable is set in st.cmd. Please edit to top bundle location\n#\n'
        )
        envPaths_fp.write('epicsEnvSet("ARCH", "{}")\n'.format(arch))
        envPaths_fp.write('epicsEnvSet("TOP", "{}")\n'.format(ioc_top_path))

        base_path = installSynApps.join_path('$(BUNDLE_LOC)', 'base')
        envPaths_fp.write('epicsEnvSet("EPICS_BASE",{}"{}")\n'.format(
            (' ' * 14), base_path))

        support_path = "$(BUNDLE_LOC)"
        support_path = installSynApps.join_path(support_path, "support")
        envPaths_fp.write('epicsEnvSet("SUPPORT",{}"{}")\n\n'.format(
            (' ' * 17), support_path))

        for dir in os.listdir(self.install_config.support_path):
            mod_path = installSynApps.join_path(
                self.install_config.support_path, dir)
            if os.path.isdir(mod_path) and dir not in [
                    'base', 'configure', 'utils', 'documentation', '.git',
                    'lib', 'bin'
            ]:
                mod_path = installSynApps.join_path('$(SUPPORT)', dir)
                envPaths_fp.write('epicsEnvSet("{}",{}"{}")\n'.format(
                    self.get_env_paths_name(dir),
                    ' ' * (24 - len(self.get_env_paths_name(dir))), mod_path))

        envPaths_fp.write('\n')

        for dir in os.listdir(self.install_config.ad_path):
            mod_path = installSynApps.join_path(self.install_config.ad_path,
                                                dir)
            if os.path.isdir(mod_path) and dir not in [
                    'configure', 'docs', 'documentation', 'ci', '.git', ''
            ]:
                mod_path = installSynApps.join_path('$(AREA_DETECTOR)', dir)
                envPaths_fp.write('epicsEnvSet("{}",{}"{}")\n'.format(
                    self.get_env_paths_name(dir),
                    ' ' * (24 - len(self.get_env_paths_name(dir))), mod_path))

        envPaths_fp.close()
Exemplo n.º 13
0
    def grab_dependencies_from_bundle(self, ioc_path, iocBoot_path):

        LOG.debug('Collecting additional iocBoot files from bundle...')
        for file in os.listdir(iocBoot_path):
            target = installSynApps.join_path(iocBoot_path, file)
            if os.path.isfile(target):
                if not file.startswith(
                    ('Makefile', 'st', 'test', 'READ', 'dll',
                     'envPaths')) and not file.endswith(('.xml', '.txt')):
                    shutil.copyfile(target,
                                    installSynApps.join_path(ioc_path, file))
Exemplo n.º 14
0
 def add_to_environment(self, line):
     try:
         line_s = line.strip()
         line_s = re.sub('"', '', line_s)
         line_s = re.sub('\t', '', line_s)
         line_s = re.sub(' +', '', line_s)
         line_s = re.sub('epicsEnvSet', '', line_s)
         temp = line_s.split(',')
         self.epics_environment[temp[0][1:]] = temp[1][:-1]
     except IndexError:
         LOG.debug('Error, failed to parse epics environment variable.')
Exemplo n.º 15
0
def find_isa_version():
    """Function that attempts to get the version of installSynApps used.

    Returns
    -------
    isa_version : str
        The version string for installSynApps. Either hardcoded version, or git tag description
    commit_hash : str
        None if git status not available, otherwise hash of current installSynApps commit.
    """

    isa_version = __version__
    commit_hash = None

    try:
        LOG.debug('git describe --tags')
        FNULL = open(os.devnull, 'w')
        out = subprocess.check_output(['git', 'describe', '--tags'], stderr=FNULL)
        isa_version = out.decode('utf-8').strip()
        LOG.debug('git rev-parse HEAD')
        out = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=FNULL)
        commit_hash = out.decode('utf-8')
        FNULL.close()
    except PermissionError:
        LOG.debug('Could not find git information for installSynApps versions, defaulting to internal version.')
    except subprocess.CalledProcessError:
        LOG.debug('Running from non-git version of installSynApps, default to internal version number.')

    return isa_version, commit_hash
    def grab_module(self, top, module, include_src=False):
        """Function that grabs all of the required folders from each individual module.

        Parameters
        ----------
        top : str
            resulting location - __temp__
        module_name : str
            folder name for the module
        module_location : str
            path to dir of location of module
        """

        module_name = os.path.basename(module.abs_path)

        target_folder = module.abs_path
        if not os.path.exists(target_folder):
            LOG.debug('Module {} not found, skipping...'.format(module.name))
            return

        # In a release version we don't need any support helper utilities, so skip it.
        if not include_src and not module.name == 'SUPPORT':
            LOG.debug('Grabbing lean files for module {}.'.format(module.name))
            self.grab_folder(target_folder + '/opi',                top + '/' + module_name + '/opi')
            self.grab_folder(target_folder + '/db',                 top + '/' + module_name + '/db')
            self.grab_folder(target_folder + '/dbd',                top + '/' + module_name + '/dbd')
            self.grab_folder(target_folder + '/include',            top + '/' + module_name + '/include')
            self.grab_folder(target_folder + '/bin/' + self.arch,   top + '/' + module_name + '/bin/' + self.arch)
            self.grab_folder(target_folder + '/lib/' + self.arch,   top + '/' + module_name + '/lib/' + self.arch)
            self.grab_folder(target_folder + '/configure',          top + '/' + module_name + '/configure')
            self.grab_folder(target_folder + '/iocBoot',            top + '/' + module_name + '/iocBoot')
            self.grab_folder(target_folder + '/modules',            top + '/' + module_name + '/modules')
            self.grab_folder(target_folder + '/ADViewers/ImageJ',   top + '/' + module_name + '/ADViewers/ImageJ')
            for dir in os.listdir(target_folder):
                if 'App' in dir and not dir.startswith('test'):
                    self.grab_folder(target_folder + '/' + dir + '/Db', top + '/' + module_name +'/' + dir + '/Db')
                    self.grab_folder(target_folder + '/' + dir + '/op', top + '/' + module_name +'/' + dir + '/op')
            if os.path.exists(target_folder + '/iocs'):
                for dir in os.listdir(target_folder + '/iocs'):
                    ioc_folder = '/iocs/' + dir
                    if 'IOC' in dir:
                        LOG.debug('Grabbing IOC files for module {} ioc: {}'.format(module.name, dir))
                        self.grab_folder(target_folder + ioc_folder + '/bin/' + self.arch,  top + '/' + module_name + ioc_folder + '/bin/' + self.arch)
                        self.grab_folder(target_folder + ioc_folder + '/lib/' + self.arch,  top + '/' + module_name + ioc_folder + '/lib/' + self.arch)
                        self.grab_folder(target_folder + ioc_folder + '/dbd',               top + '/' + module_name + ioc_folder + '/dbd')
                        self.grab_folder(target_folder + ioc_folder + '/iocBoot',           top + '/' + module_name + ioc_folder + '/iocBoot')
        else:
            LOG.debug('Grabbing full files for module {}.'.format(module.name))

            # Grab some necessary non-module folders and files
            if module.name == 'AREA_DETECTOR':
                self.grab_folder(target_folder + '/configure', top + '/' + module_name + '/configure')
            elif module.name == 'SUPPORT':
                self.grab_folder(target_folder + '/configure', top + '/' + '/configure')
                self.grab_folder(target_folder + '/utils', top + '/' + '/utils')
                self.grab_file(target_folder + '/Makefile', top + '/' + '/Makefile')
            else:
                # Otherwise grab the entire module
                self.grab_folder(target_folder, top + '/' + module_name)
Exemplo n.º 17
0
    def create_opi_tarball(self):
        """Function that collects autoconverted .opi files from epics_dir.

        OPI screens are saved  in output_location/ad_opis and creats a tarball.

        Returns
        -------
        int
            0 if suceeded, nonzero otherwise
        """

        opi_base_dir = installSynApps.join_path(self.output_location,
                                                '__opis_temp__')
        opi_dir = installSynApps.join_path(opi_base_dir, 'opis')
        try:
            os.mkdir(opi_base_dir)
            os.mkdir(opi_dir)
        except OSError:
            LOG.write('Error creating ' + opi_dir + ' directory', )

        for (root, _, files) in os.walk(self.install_config.install_location,
                                        topdown=True):
            for name in files:
                if '.opi' in name and 'autoconvert' in root:
                    file_name = installSynApps.join_path(root, name)
                    try:
                        shutil.copy(file_name, opi_dir)
                    except OSError:
                        LOG.debug("Can't copy {} to {}".format(
                            file_name, opi_dir))

        opi_tarball_basename = 'opis_{}'.format(
            self.install_config.get_core_version())
        opi_tarball = opi_tarball_basename
        counter = 1
        while os.path.exists(
                installSynApps.join_path(self.output_location,
                                         opi_tarball + '.tgz')):
            opi_tarball = opi_tarball_basename + '_({})'.format(counter)
            counter = counter + 1

        out = subprocess.call(
            ['tar', 'czf', opi_tarball + '.tgz', '-C', opi_base_dir, '.'])
        shutil.rmtree(opi_base_dir)
        os.rename(
            opi_tarball + '.tgz',
            installSynApps.join_path(self.output_location,
                                     opi_tarball + '.tgz'))
        return out
Exemplo n.º 18
0
    def write_build_flags(self, filepath):
        """Helper Function for writing build flags from install config

        Parameters
        ----------
        filepath : str
            Path into which we wish to save configuration
        """

        new_build_flag = open(filepath + "/macroFiles/BUILD_FLAG_CONFIG", 'w')
        new_build_flag.write('# Saved by installSynApps on {}\n\n'.format(datetime.datetime.now()))
        for macro_pair in self.install_config.build_flags:
            LOG.debug('Writing build flag {}={}'.format(macro_pair[0], macro_pair[1]))
            new_build_flag.write('{}={}\n'.format(macro_pair[0], macro_pair[1]))
        new_build_flag.close()
Exemplo n.º 19
0
    def generate_remake_sources(self):
        """Function that creates a bash/batch script for regenerating binaries from sources
        """

        LOG.debug('Autogenerating regenerateSources bash script')
        regenerate_fp = open(installSynApps.join_path(self.install_config.install_location, 'autogenerated', 'regenerateSources.sh'), 'w+')
        regenerate_fp.write('#!/bin/bash\n\ngit clone https://github.com/NSLS-II/installSynApps\n')
        isa_version, isa_commit_hash = installSynApps.find_isa_version()
        regenerate_fp.write('cd installSynApps\n')
        if isa_commit_hash is not None:
            regenerate_fp.write('git checkout {}\n'.format(isa_commit_hash))
        else:
            regenerate_fp.write('git checkout -q {}\n'.format(isa_version))
        abs_loc = os.path.abspath(self.install_config.install_location)
        regenerate_fp.write('./installCLI.py -i {} -c {} -p -y\n\n'.format(installSynApps.join_path(abs_loc, 'regenerated'), installSynApps.join_path(abs_loc, 'build-config')))
        regenerate_fp.close()
Exemplo n.º 20
0
    def generate_st_cmd(self, action, executable_path, st_base_path):

        LOG.debug(
            'Generating st.cmd using base file:\n{}'.format(st_base_path))
        ioc_path = installSynApps.join_path(self.ioc_template_dir,
                                            action.ioc_name)

        lib_path = self.get_lib_path_str(action)

        # Create base st.cmd, add call to executable
        st = self.initialize_st_base_file(ioc_path, lib_path, executable_path)

        LOG.debug('Writing base st.cmd file')

        # Define envPaths
        st.write('< envPaths\n\n')

        # Open existing st.cmd base file
        st_base_fp = open(st_base_path, 'r')

        # Read through the lines, add a 'unique.cmd' call after all env sets, and add envSet calls to action environment
        lines = st_base_fp.readlines()
        wrote_unique = False
        for line in lines:
            if line.startswith(
                    '#!') or 'unique.cmd' in line or 'envPaths' in line:
                pass
            elif line.startswith('#'):
                st.write(line)
            elif 'Config(' in line and not wrote_unique:
                st.write('\n< unique.cmd\n\n')
                st.write(line)
                wrote_unique = True
            elif line.startswith('epicsEnvSet'):
                action.add_to_environment(line)
                st.write(line)
            else:
                st.write(line)

        st_base_fp.close()
        st.close()

        # Collect environment variables set in any other files
        self.grab_additional_env(action, st_base_path)
        # Make st.cmd executable.
        os.chmod(installSynApps.join_path(ioc_path, "st.cmd"), 0o755)
Exemplo n.º 21
0
    def checkout_module(self, module, recursive=False):
        """Function responsible for checking out selected tagged versions of modules.

        Parameters
        ----------
        module : InstallModule
            Module that is being checked out
        recursive : bool
            Specifies whether there are git submodules that need to be initialized
        
        Returns
        -------
        int
            -3 if input was not an InstallModule, -2 if the absolute path is not known, -1 if checkout fails, 0 if success
        """

        ret = -1
        LOG.debug('Checking out version for module {}'.format(module.name))
        if isinstance(module, IM.InstallModule):
            if module.abs_path != None:
                ret = 0
                if module.version != "master" and module.url_type == "GIT_URL":
                    current_loc = os.getcwd()
                    os.chdir(module.abs_path)
                    command = "git checkout -q {}".format(module.version)
                    LOG.print_command(command)
                    proc = Popen(command.split(' '))
                    proc.wait()
                    ret = proc.returncode

                    if recursive and ret == 0:
                        command = 'git submodule update'
                        LOG.print_command(command)
                        proc = Popen(command.split(' '))
                        proc.wait()
                        ret = proc.returncode

                    os.chdir(current_loc)
                    if ret == 0:
                        LOG.write('Checked out version {}'.format(
                            module.version))
                    else:
                        LOG.write(
                            'Checkout of version {} failed for module {}.'.
                            format(module.version, module.name))
        return ret
Exemplo n.º 22
0
    def write_injector_files(self, filepath):
        """Helper Function for writing injector files from install config

        Parameters
        ----------
        filepath : str
            Path into which we wish to save configuration
        """

        # for each injector file write it with its target location
        for injector_file in self.install_config.injector_files:
            LOG.debug('Saving injector file {} with target {}'.format(injector_file.name, injector_file.target))
            new_fp = open(filepath + "/injectionFiles/" + injector_file.name, 'w')
            new_fp.write('# Saved by installSynApps on {}\n'.format(datetime.datetime.now()))
            new_fp.write('__TARGET_LOC__={}\n\n'.format(injector_file.target))
            new_fp.write(injector_file.contents)
            new_fp.close()
Exemplo n.º 23
0
    def parse_line_to_module(self, line, current_url, current_url_type):
        """Function that parses a line in the INSTALL_CONFIG file into an InstallModule object

        Parameters
        ----------
        line : str
            line from table in file
        current_url : str
            url at which module is located
        current_url_type : str
            either GIT_URL or WGET_URL
        
        Returns
        -------
        InstallModule
            module parsed from the table line
        """

        # Remove extra whitespace
        line = re.sub('\t', ' ', line)
        line = re.sub(' +', ' ', line)
        module_components = line.split(' ')
        # If a line is read that isn't in the correct format return None
        if len(module_components) < 6:
            return None
        # line will be in format:
        # NAME   VERSION   RELATIVE_PATH   REPOSITORY   CLONE   BUILD   PACKAGE
        name        = module_components[0]
        version     = module_components[1]
        rel_path    = module_components[2]
        repository  = module_components[3]
        clone       = module_components[4]
        build       = module_components[5]
        if name in self.required_in_package:
            package = "YES"
        # Add length check for compatibility with older configure directories - default package to NO
        elif len(module_components) == 7:
            package = module_components[6]
        else:
            package = "NO"
        # create object from line and return it
        LOG.debug('Parsed install module: {}'.format(name))
        install_module = IM.InstallModule(name, version, rel_path, current_url_type, current_url, repository, clone, build, package)
        return install_module
Exemplo n.º 24
0
    def autogenerate_all(self, create_simple_readme=True):
        """Top level function that calls all autogeneration functions

        Parameters
        ----------
        create_simple_readme : bool
            If true, generate simplified README file based on install config
        """

        if platform == 'win32':
            LOG.debug('Windows machine detected, skipping script generation.')
        else:
            LOG.debug('Generating auto-(un)install helper scripts')
            self.initialize_dir()
            self.generate_install()
            self.generate_uninstall()
            self.generate_remake_sources()
        if create_simple_readme:
            self.generate_readme_simple()
Exemplo n.º 25
0
    def grab_configuration_used(self, top_location, module, readme_fp):
        """Function that includes the install configuration into the bundle for reuse.
        
        Parameters
        ----------
        top : str
            resulting location - __temp__
        """

        try:
            isa_version, isa_commit_hash = installSynApps.find_isa_version()
            self.generate_build_config(top_location, module, readme_fp)
            readme_fp.write('Build configuration:\n\n')
            readme_fp.write(
                'installSynApps Version: {}\n\n'.format(isa_version))
            readme_fp.write(
                'To grab this version:\n\n    git clone https://github.com/epicsNSLS2-deploy/installSynApps\n'
            )
            if isa_commit_hash is not None:
                readme_fp.write(
                    '    git checkout {}\n'.format(isa_commit_hash))
            else:
                readme_fp.write('    git checkout -q {}\n'.format(isa_version))
            readme_fp.write(
                'To regenerate sources for this bundle, grab installSynApps, and run:\n\n'
            )
            readme_fp.write(
                '    ./installCLI.py -c $BUILD_CONFIG -i $INSTALL_LOCATION -p\n\n'
            )
            readme_fp.write(
                'where $BUILD_CONFIG is the path to the build-config directory,\n'
            )
            readme_fp.write(
                'and $INSTALL_LOCATION is your target install path.\n\n{}\n'.
                format('-' * 64))
            readme_fp.write('{:<20}{}\n'.format('Python 3 Version:',
                                                sys.version.split()[0]))
            readme_fp.write('{:<20}{}\n'.format('OS Class:', self.OS))
            readme_fp.write('{:<20}{}\n'.format('Build Date:',
                                                datetime.datetime.now()))
        except:
            LOG.debug('Failed to copy install configuration into bundle.')
Exemplo n.º 26
0
    def generate_install(self):
        """Function that generates an install file based on currently loaded install_config
        """

        LOG.debug('Autogenerating bash install script')
        install_fp = open(self.install_config.install_location + "/autogenerated/install.sh", "w+")
        install_fp.write("#!/bin/bash\n")
        
        install_fp.write(self.message)

        for module in self.install_config.get_module_list():
            if module.build == "YES":
                install_fp.write("{}={}\n".format(module.name, module.abs_path))

        for module in self.install_config.get_module_list():
            if module.build == "YES":
                install_fp.write("cd ${}\n".format(module.name))
                install_fp.write("make -sj\n")

        install_fp.close()
Exemplo n.º 27
0
 def grab_ioc_files(self, top, target_loc, module_name, flat_grab):
     for dir in os.listdir(target_loc + '/iocs'):
         ioc_folder = '/iocs/' + dir
         if 'IOC' in dir:
             if not flat_grab:
                 LOG.debug(
                     'Grabbing IOC files for module {} ioc: {}'.format(
                         module_name, dir))
                 module_base_folder = os.path.basename(target_loc)
                 for arch in self.arch_list:
                     self.grab_folder(
                         target_loc + ioc_folder + '/bin/' + arch,
                         top + '/' + module_base_folder + ioc_folder +
                         '/bin/' + arch)
                     self.grab_folder(
                         target_loc + ioc_folder + '/lib/' + arch,
                         top + '/' + module_base_folder + ioc_folder +
                         '/lib/' + arch)
                 self.grab_folder(
                     target_loc + ioc_folder + '/dbd',
                     top + '/' + module_base_folder + ioc_folder + '/dbd')
                 self.grab_folder(
                     target_loc + ioc_folder + '/iocBoot', top + '/' +
                     module_base_folder + ioc_folder + '/iocBoot')
             else:
                 LOG.debug(
                     'Grabbing IOC files for module {} ioc: {}'.format(
                         module_name, dir))
                 for arch in self.arch_list:
                     self.grab_all_files_in_dir(
                         target_loc + ioc_folder + '/bin/' + arch,
                         top + '/bin/' + arch)
                     self.grab_all_files_in_dir(
                         target_loc + ioc_folder + '/lib/' + arch,
                         top + '/lib/' + arch)
                 self.grab_all_files_in_dir(
                     target_loc + ioc_folder + '/dbd', top + '/dbd')
                 self.grab_all_files_in_dir(
                     target_loc + ioc_folder + '/protocol',
                     top + '/protocol')
Exemplo n.º 28
0
    def inject_to_file(self, injector_file):
        """Function that injects contents of specified file into target

        First, convert to absolute path given the install config. Then open it in append mode, then
        write all uncommented lines in the injector file into the target, and then close both

        Parameters
        ----------
        injector_file_path : InjectorFile
            object representing injector file
        """

        target_path = injector_file.target
        if target_path is None or len(target_path) == 0:
            return
        target_path = self.install_config.convert_path_abs(target_path)
        target_file = os.path.basename(target_path)
        if (not os.path.exists(target_path)):
            return
        if target_file.startswith("EXAMPLE_"):
            target_path_no_example = installSynApps.join_path(os.path.dirname(target_path), target_file[8:])
            if os.path.exists(target_path):
                os.rename(target_path, target_path_no_example)
            target_path = target_path_no_example
        target_fp = open(target_path, "a")
        target_fp.write("\n# ------------The following was auto-generated by installSynApps-------\n\n")
        if injector_file.contents is not None:
            LOG.debug('Injecting into {}'.format(target_path))
            target_fp.write(injector_file.contents)
            LOG.debug(injector_file.contents, force_no_timestamp=True)
            LOG.debug('Injection Done.')
        target_fp.write("\n# --------------------------Auto-generated end----------------------\n")
        target_fp.close()
    def create_bundle_name(self, module_name=None, source_bundle=False):
        """Helper function for creating output filename

        Returns
        -------
        str
            An output filename describing architecture and ADCore version
        """

        if module_name is not None:
            module = self.install_config.get_module_by_name(module_name)
            if module is None:
                return None

        bundle_type = 'Prod'
        if source_bundle:
            bundle_type = 'Debug'

        date_str = datetime.date.today()
        try:
            core_version = self.install_config.get_core_version()
            if module_name is None:
                output_filename = '{}_AD_{}_{}_{}_{}'.format(self.institution, core_version, bundle_type, self.OS, date_str)
            else:
                output_filename = '{}_AD_{}_{}_{}_{}_addon'.format(self.institution, core_version, bundle_type, self.OS, module.name)
        except:
            LOG.debug('Error generating custom tarball name.')
            output_filename = 'EPICS_Binary_Bundle_{}'.format(self.OS)

        temp = output_filename
        counter = 1
        while os.path.exists(self.output_location + '/' + temp + '.tgz'):
            temp = output_filename
            temp = temp + '_({})'.format(counter)
            counter = counter + 1
        output_filename = temp

        LOG.debug('Generated potential output tarball name as: {}'.format(output_filename))
        return output_filename
Exemplo n.º 30
0
    def initialize_st_base_file(self, ioc_path, lib_path, executable_path):
        """Function responsible for handling executable path injection, and base file creation
        """

        # Setup st.cmd to be executable, rest will be in st_base.cmd
        LOG.debug('Setting up executable st.cmd with library path')
        st_exe = open(installSynApps.join_path(ioc_path, 'st.cmd'), 'w+')

        executable_path_rel = '$BUNDLE_LOC/support/{}'.format(
            executable_path.split('support/')[1])

        if platform == 'win32':
            st_exe.write('@echo OFF\n\n{}\n\n{} st_base.cmd\n'.format(
                lib_path, executable_path_rel))
        else:
            st_exe.write('#!/bin/bash\n\n{}\n\n{} st_base.cmd\n'.format(
                lib_path, executable_path_rel))

        st_exe.close()
        st = open(installSynApps.join_path(ioc_path, "st_base.cmd"), "w+")

        return st