introduce home_dir as a property

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-11-01 15:17:46 +01:00
parent 69a3844332
commit af24165367
1 changed files with 11 additions and 9 deletions

View File

@ -47,16 +47,20 @@ class Local(object):
self._init_log() self._init_log()
self._init_permissions() self._init_permissions()
self._init_home_dir()
self._init_paths() self._init_paths()
self._init_cache_dir(cache_dir) self._init_cache_dir(cache_dir)
self._init_conf_dirs() self._init_conf_dirs()
def _init_home_dir(self): @property
def dist_conf_dir(self):
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
@property
def home_dir(self):
if 'HOME' in os.environ: if 'HOME' in os.environ:
self.home_dir = os.path.join(os.environ['HOME'], ".cdist") return os.path.join(os.environ['HOME'], ".cdist")
else: else:
self.home_dir = None return = None
def _init_log(self): def _init_log(self):
self.log = logging.getLogger(self.target_host) self.log = logging.getLogger(self.target_host)
@ -81,13 +85,12 @@ class Local(object):
self.conf_dirs = [] self.conf_dirs = []
# Comes with the distribution # Comes with the distribution
system_conf_dir = os.path.join(os.path.dirname(cdist.__file__), "conf") system_conf_dir = os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
self.conf_dirs.append(system_conf_dir) self.conf_dirs.append(system_conf_dir)
# Is the default place for user created explorer, type and manifest # Is the default place for user created explorer, type and manifest
if self.home_dir: if self.home_dir:
user_conf_dir = os.path.join(self.home_dir, ".cdist") self.conf_dirs.append(self.home_dir)
self.conf_dirs.append(user_conf_dir)
# Add user supplied directories # Add user supplied directories
if self._add_conf_dirs: if self._add_conf_dirs:
@ -152,13 +155,12 @@ class Local(object):
def _create_context_dirs(self): def _create_context_dirs(self):
self.mkdir(self.out_path) self.mkdir(self.out_path)
self.mkdir(self.conf_path) self.mkdir(self.conf_path)
self.mkdir(self.global_explorer_out_path) self.mkdir(self.global_explorer_out_path)
self.mkdir(self.bin_path) self.mkdir(self.bin_path)
def _create_conf_path_and_link_conf_dirs(self): def _create_conf_path_and_link_conf_dirs(self):
self.mkdir(self.conf_path)
# Link destination directories # Link destination directories
for sub_dir in [ "explorer", "manifest", "type" ]: for sub_dir in [ "explorer", "manifest", "type" ]:
self.mkdir(os.path.join(self.conf_path, sub_dir)) self.mkdir(os.path.join(self.conf_path, sub_dir))