def cwd(self, value): """ Change the working directory that processes should be executed in. :param value: The new path to change to. If relative, will be interpreted relative to the current working directory. """ self._cwd = utils.canonicalize_path(self._cwd, value)
def __call__(self, ctxt): """ Invoke the action. This updates the appropriate ``SensitiveDict`` instance from the context as specified in the configuration. :param ctxt: The context object. :returns: A ``StepResult`` object. """ # First, select the correct context attribute sensitive_dict = getattr(ctxt, self.context_attr) # Next, read in the files in order for ftmpl in self.files: fpath = utils.canonicalize_path(self.dirname, ftmpl(ctxt)) try: with open(fpath) as f: var_data = yaml.load(f) except Exception as exc: # Ignore missing variable files continue # Make sure the contents are a dictionary if not isinstance(var_data, collections.Mapping): continue # Update the dictionary sensitive_dict.update(var_data) # Now, apply the sensitive and unset changes for var in self.sensitive_vars: sensitive_dict.declare_sensitive(var) for var in self.unset_vars: sensitive_dict.pop(var, None) # Finally, apply the sets for var, tmpl in self.set_vars.items(): sensitive_dict[var] = tmpl(ctxt) # We're done! return StepResult(state=SUCCESS)
def __call__(self, ctxt): """ Invoke the action. This reads and interprets the referenced steps file. :param ctxt: The context object. :returns: A list of zero or more ``Step`` objects. """ # Interpret the path path = utils.canonicalize_path(self.dirname, self.path(ctxt)) # Import the desired steps steps = Step.parse_file( ctxt, path, self.key(ctxt), self.step_addr) # Narrow the steps, if desired if self.start is not None or self.stop is not None: return steps[self.start:self.stop] return steps
def __init__(self, environ=None, sensitive=None, cwd=None): """ Initialize a new ``Environment`` instance. :param environ: An optional dictionary containing the initial set of environment variables. If omitted, ``os.environ`` will be used. :param sensitive: An optional set of "sensitive" variables, environment variables whose values should not be printed out. :param cwd: The working directory processes should be executed in. If not given, the current working directory will be used. If a relative path, it will be interpreted relative to the current working directory. """ # Select the starting environment environ = environ or os.environ.copy() # Build the 'sensitive' set sensitive_var = SetVariable(self, 'TIMID_SENSITIVE', value=environ.get('TIMID_SENSITIVE')) if sensitive: sensitive_var |= sensitive # Initialize the SensitiveDict super(Environment, self).__init__(environ, sensitive_var) # Track special variables self._special = { 'PATH': ListVariable(self, 'PATH'), 'TIMID_SENSITIVE': sensitive_var, } # Initialize the working directory self._cwd = utils.canonicalize_path(os.getcwd(), cwd or os.curdir)
def test_relative(self, mock_abspath): result = utils.canonicalize_path('/foo/bar', 'bar/baz') self.assertEqual(result, '/absolute/path') mock_abspath.assert_called_once_with('/foo/bar/bar/baz')