def test_read_shell_config(self): os.environ["ONE"] = "one" config_path = os.path.join(self.temp_dir, "config") with mkfile(config_path) as config: print(dedent("""\ ONE="$ONE two three" TWO=two THREE=three"""), file=config) config_dict = dict( osextras.read_shell_config(config_path, ["ONE", "TWO"])) self.assertEqual("one two three", config_dict["ONE"]) self.assertEqual("two", config_dict["TWO"]) self.assertNotIn("three", config_dict)
def read(self, config_path=None): for key, value in osextras.read_shell_config(config_path, _whitelisted_keys): if key.startswith("CDIMAGE_") or key in _whitelisted_keys: super(Config, self).__setitem__(key, value) # Special entries. if "DIST" in self: super(Config, self).__setitem__("DIST", Series.find_by_name(self["DIST"])) if "ARCHES" not in self: self.set_default_arches() if "CPUARCHES" not in self: self.set_default_cpuarches()
def _anonftpsync_options(config): env = {} path = _anonftpsync_config_path(config) if path: whitelisted_keys = [ "RSYNC_EXCLUDE", "RSYNC_ICONV", "RSYNC_PASSWORD", "RSYNC_PROXY", "RSYNC_RSH", "RSYNC_SRC", ] for key, value in osextras.read_shell_config(path, whitelisted_keys): if key.startswith("RSYNC_"): env[key] = value if "RSYNC_SRC" not in env: raise Exception( "RSYNC_SRC not configured! Edit %s or %s and try again." % ( os.path.join(config.root, "production", "anonftpsync"), os.path.join(config.root, "etc", "anonftpsync"))) return env