Example #1
0
    def status(self):

        shell = Shell()

        path = ""
        joiner = ""

        for index, level_name in enumerate(settings.hierarchy()):
            try:
                path += joiner + shell.getenv("@" + level_name.upper())
            except EnvVarNotFound:
                continue

            joiner = ":"

        sys.stderr.write("%s\n" % path)
Example #2
0
    def set(self, args):
        """ 
        Sets the environment to correspond to this level.
        """
        
        # Get full syntax
        syntax, depth = self.syntax_and_depth(args)

        # Check to see if level exists
        level_list = Level.find_by_syntax(syntax)

        if not level_list:
            pipeline.utils.report("Error - Syntax does not match any levels")
            return

        if len(level_list) > 1:
            pipeline.utils.report("Error - Syntax matches multiple levels")
            return

        # Get the level we've found
        level = level_list[0]

        shell = Shell()

        # Grab settings info for reference
        hierarchy = settings.hierarchy()
        abbr = settings.abbreviations()

        # Clean out the any pipeline paths from PATH so we can reset it
        pattern = shell.getenv("@JOBS_ROOT") + r'/[\w/]*/share/bin'
        shell.clean('PATH', pattern)

        # Clean prod from PATH as well
        pattern = shell.getenv("@JOBS_ROOT") + r'/prod/[\w/]*'
        shell.clean('PATH', pattern)

        aliases = ['', 'bin']

        # Remove all environment variables and aliases
        # associated with levels below this one
        depth = level.depth + 1
        if level.depth < len(hierarchy) - 1:
            for level_name in hierarchy[level.depth + 1:]:
                shell.unset("@" + level_name.upper())
                for alias in aliases:
                    shell.unalias(abbr[depth] + alias)

                depth += 1
                

        bin_path = ""
        # Set environment from level 
        for l in level.branch():
            shell.set("@" + hierarchy[l.depth], l.name)
            bin_path += "%s/share/bin:" % l.file_path()

        # Set aliases
        cd_path = "cd $@JOBS_ROOT"
        for index, level_name in enumerate(hierarchy[:level.depth + 1]):
            # alias current level
            cd_path += os.sep + "$@" + level_name.upper()
            shell.alias(abbr[index], cd_path)

        prod = shell.getenv("@PROD")
        bin_path += "%s/bin" % prod
        shell.insert("PATH", bin_path)

        self.write_last(level)

        shell.commit()
Example #3
0
    def remove(self, args):
        """
        Removes the level and all it's children from 
        the filesystem and the database.
        """

        # Get full syntax
        syntax, depth = self.syntax_and_depth(args)

        # Check to see if level exists
        level_list = Level.find_by_syntax(syntax)

        if not level_list:
            pipeline.utils.report("Error - Syntax does not match any levels")
            return

        if len(level_list) > 1:
            pipeline.utils.report("Error - Syntax matches multiple levels")
            return

        level = level_list[0]

        # Get settings info
        hierarchy = settings.hierarchy()
        abbr = settings.abbreviations()

        aliases = ['', 'bin']

        shell = Shell()

        # If we're removing a level in our current environment
        clean_env = True
        for n in level.branch():
            # Check each level of the env against our level branch
            clean_env = True
            try:
                clean_env = (n.name != shell.getenv("@" + hierarchy[n.depth].upper()))
            except EnvVarNotFound:
                clean_env = False
                break

            # Necessary?
            if not clean_env:
                break

        # If necessary unset all environment variables and aliases
        # associated with this level and those below
        if clean_env:
            depth = level.depth
            for level_name in hierarchy[level.depth:]:
                shell.unset("@" + level_name.upper())
                for alias in aliases:
                    shell.unalias(abbr[depth] + alias)

                depth += 1


        # Write out a syntax file so it is up-to-date with current env
        self.write_last(level.parent)

        shell.commit()

        # Remove the level from disk
        shutil.rmtree(level.file_path())

        # Remove the level and all its children from the database
        level.destroy_children()
        session.delete(level)
        session.flush()