def set(self, scopes, argument, value): if self.is_on and self.username and self.current_dir: if self._local_context_file is None: file_path = os.path.join(self.current_dir, self.dir_name, self._get_local_context_file_name()) dir_path = os.path.join(self.current_dir, self.dir_name) self._local_context_file = _ConfigFile(dir_path, file_path, LOCAL_CONTEXT_NOTICE) for scope in scopes: self._local_context_file.set_value(scope.lower(), argument, value)
def _load_local_context_file(self): current_dir = os.getcwd() while current_dir: dir_path = os.path.join(current_dir, self.dir_name) file_path = os.path.join(dir_path, self.file_name) if os.path.isfile(file_path) and os.access( file_path, os.R_OK) and os.access(file_path, os.W_OK): self._local_context_file = _ConfigFile(dir_path, file_path) break # load only one local context # Stop if already in root drive if current_dir == os.path.dirname(current_dir): if self._local_context_file is None: logger.debug( 'local context is not turned on in %s and all its parent directories', current_dir) break current_dir = os.path.dirname(current_dir)
def _load_local_context_files(self, recursive=False): local_context_files = [] if self.username and self.current_dir: current_dir = self.current_dir while current_dir: dir_path = os.path.join(current_dir, self.dir_name) file_path = os.path.join(dir_path, self._get_local_context_file_name()) if os.path.isfile(file_path) and os.access( file_path, os.R_OK) and os.access(file_path, os.W_OK): local_context_files.append( _ConfigFile(dir_path, file_path, LOCAL_CONTEXT_NOTICE)) if not recursive: break # load only one local context # Stop if already in root drive if current_dir == os.path.dirname(current_dir): break current_dir = os.path.dirname(current_dir) return local_context_files