text
stringlengths
0
828
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"
1391,"def _inject_config_source(self, source_filename, files_to_inject):
""""""
Inject existing environmental config with namespace sourcing.
Returns a tuple of the first file name and path found.
""""""
# src_path = os.path.join(self.directory.root_dir, source_filename)
# src_exec = ""[ -r %s ] && . %s"" % (src_path, src_path)
src_exec = ""[ -r {0} ] && . {0}"".format(os.path.join(self.directory.root_dir, source_filename))
# The ridiculous construction above is necessary to avoid failing tests(!)
for config_file in files_to_inject:
config_path = os.path.expanduser(os.path.join(""~"", config_file))
if os.path.exists(config_path):
self.injections.inject(config_path, src_exec)
break
else:
config_file = files_to_inject[0]
config_path = os.path.expanduser(os.path.join(""~"", config_file))
self.logger.info(""No config files found to source %s, creating ~/%s!"" % (source_filename, config_file))
self.injections.inject(config_path, src_exec)
return (config_file, config_path)"
1392,"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.directory.finalize()
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 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(""Done!"")
self.logger.info(""NOTE: Please remember to open new shells/terminals to use the modified environment"")"
1393,"def _build_logger(self, level=logging.INFO):
"""""" return a logger. if logger is none, generate a logger from stdout """"""
self._debug_stream = StringIO()
logger = logging.getLogger('sprinter')
# stdout log
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setLevel(level)
logger.addHandler(out_hdlr)
# debug log
debug_hdlr = logging.StreamHandler(self._debug_stream)
debug_hdlr.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
debug_hdlr.setLevel(logging.DEBUG)
logger.addHandler(debug_hdlr)
logger.setLevel(logging.DEBUG)
return logger"
1394,"def run_action(self, feature, action,
run_if_error=False,
raise_exception=True):
"""""" Run an action, and log it's output in case of errors """"""
if len(self._error_dict[feature]) > 0 and not run_if_error:
return
error = None
instance = self.features[feature]
try:
getattr(instance, action)()
# catch a generic exception within a feature
except Exception as e:
e = sys.exc_info()[1]
self.logger.info(""An exception occurred with action %s in feature %s!"" %
(action, feature))
self.logger.debug(""Exception"", exc_info=sys.exc_info())
error = str(e)