Exemple #1
0
    def warmup(self):
        """ initialize variables necessary to perform a sprinter action """
        self.logger.debug("Warming up...")

        try:
            if not isinstance(self.source, Manifest) and self.source:
                self.source = load_manifest(self.source)
            if not isinstance(self.target, Manifest) and self.target:
                self.target = load_manifest(self.target)
            self.main_manifest = self.target or self.source
        except lib.BadCredentialsException:
            e = sys.exc_info()[1]
            self.logger.error(str(e))
            raise SprinterException(
                "Fatal error! Bad credentials to grab manifest!")

        if not getattr(self, 'namespace', None):
            if self.target:
                self.namespace = self.target.namespace
            elif not self.namespace and self.source:
                self.namespace = self.source.namespace
            else:
                raise SprinterException(
                    "No environment name has been specified!")

        self.directory_root = self.custom_directory_root

        if not self.directory:
            if not self.directory_root:
                self.directory_root = os.path.join(self.root, self.namespace)

            self.directory = Directory(self.directory_root,
                                       shell_util_path=self.shell_util_path)

        if not self.injections:
            self.injections = Injections(
                wrapper="%s_%s" %
                (self.sprinter_namespace.upper(), self.namespace),
                override="SPRINTER_OVERRIDES")
        if not self.global_injections:
            self.global_injections = Injections(
                wrapper="%s" % self.sprinter_namespace.upper() + "GLOBALS",
                override="SPRINTER_OVERRIDES")
        # append the bin, in the case sandboxes are necessary to
        # execute commands further down the sprinter lifecycle
        os.environ['PATH'] = self.directory.bin_path(
        ) + ":" + os.environ['PATH']
        self.warmed_up = True
Exemple #2
0
 def _get_formula_class(self, formula):
     """
     get a formula class object if it exists, else
     create one, add it to the dict, and pass return it.
     """
     # recursive import otherwise
     from sprinter.formula.base import FormulaBase
     if formula in LEGACY_MAPPINGS:
         formula = LEGACY_MAPPINGS[formula]
     formula_class, formula_url = formula, None
     if ':' in formula:
         formula_class, formula_url = formula.split(":", 1)
     if formula_class not in self._formula_dict:
         try:
             self._formula_dict[
                 formula_class] = lib.get_subclass_from_module(
                     formula_class, FormulaBase)
         except (SprinterException, ImportError):
             logger.info("Downloading %s..." % formula_class)
             try:
                 self._pip.install_egg(formula_url or formula_class)
                 try:
                     self._formula_dict[
                         formula_class] = lib.get_subclass_from_module(
                             formula_class, FormulaBase)
                 except ImportError:
                     logger.debug("FeatureDict import Error",
                                  exc_info=sys.exc_info())
                     raise SprinterException(
                         "Error: Unable to retrieve formula %s!" %
                         formula_class)
             except PipException:
                 logger.error("ERROR: Unable to download %s!" %
                              formula_class)
     return self._formula_dict[formula_class]
Exemple #3
0
    def _finalize(self):
        """ command to run at the end of sprinter's run """
        self.logger.info("Finalizing...")
        self.write_manifest()

        if self.directory.rewrite_config:
            # always ensure .rc is written (sourcing .env)
            self.directory.add_to_rc('')
            # prepend brew for global installs
            if system.is_osx() and self.main_manifest.is_affirmative(
                    'config', 'use_global_packagemanagers'):
                self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' %
                                          '/usr/local/bin')
            self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' %
                                      self.directory.bin_path())
            self.directory.add_to_env(
                '__sprinter_prepend_path "%s" LIBRARY_PATH' %
                self.directory.lib_path())
            self.directory.add_to_env(
                '__sprinter_prepend_path "%s" C_INCLUDE_PATH' %
                self.directory.include_path())

        self.injections.commit()
        self.global_injections.commit()

        if not os.path.exists(os.path.join(self.root, ".global")):
            self.logger.debug("Global directory doesn't exist! creating...")
            os.makedirs(os.path.join(self.root, ".global"))

        self.logger.debug("Writing global config...")
        self.global_config.write(open(self.global_config_path, 'w+'))

        self.logger.debug("Writing shell util file...")
        with open(self.shell_util_path, 'w+') as fh:
            fh.write(shell_utils_template)

        if self.error_occured:
            raise SprinterException("Error occured!")

        if self.message_success():
            self.logger.info(self.message_success())

        self.logger.info(
            "NOTE: Please remember to open new shells/terminals to use the modified environment"
        )
Exemple #4
0
 def wrapped(self, *args, **kwargs):
     if self.directory.new:
         raise SprinterException("Namespace %s is not yet installed!" %
                                 self.namespace)
     return f(self, *args, **kwargs)