def running_instances(): """Get run dir and container name of every project.""" for container_name in self.get_containers_in_run_dir(): run_fp = self.path_of_runfile(container_name) lines = safe_read_from_file( run_fp, self.logger.error, lines=True) or [""] yield lines[0]
def _read_config(self, config_file): """Read project configuration file striping out comment lines.""" content_file = safe_read_from_file( config_file, self.logger.error ) or "" project_lines = self.there_are_comments.sub("", content_file) return project_lines.split("\n") if project_lines else []
def uuid_from_cernvm(): lines = safe_read_from_file( self.local_cernvm_config, self.logger.warning, lines=True) for line in lines or []: key, value = line.split("=") if key == "CERNVM_UUID": return value
def get_run_hours(): """Get run hours of DumbQ.""" runhours_fp = self.config["dumbq_runhours"] hours = safe_read_from_file(runhours_fp, self.logger.warning, lines=True) return hours[0] if hours else 0
def running_instances(): """Get run dir and container name of every project.""" for container_name in self.get_containers_in_run_dir(): run_fp = self.path_of_runfile(container_name) lines = safe_read_from_file( run_fp, self.logger.error, lines=True ) or [""] yield lines[0]
def uuid_from_cernvm(): lines = safe_read_from_file(self.local_cernvm_config, self.logger.warning, lines=True) for line in lines or []: key, value = line.split("=") if key == "CERNVM_UUID": return value
def read_environment_variables(self): """Read environment variables from floppy or default file.""" def get_envvars(lines): # Return lines with 'key=value' format for line in lines: match = self.get_vars_regexp.match(line) yield match.groups() if match else None floppy_reader = self.config["floppy_reader_bin"] envvar_file = self.config["envvar_file"] # Update envars from floppy drive contents if os.path.exists(floppy_reader): floppy_out = check_output(floppy_reader, stderr=DEVNULL) floppy_vars = floppy_out.split("\n") self.envvars.extend(filter(None, get_envvars(floppy_vars))) # Update envars from standard file with ignored(OSError): envvars = safe_read_from_file(envvar_file, self.logger.warning, lines=True) self.envvars.extend(filter(None, get_envvars(envvars)))
def get_run_hours(): """Get run hours of DumbQ.""" runhours_fp = self.config["dumbq_runhours"] hours = safe_read_from_file( runhours_fp, self.logger.warning, lines=True) return hours[0] if hours else 0
def get_uptime(): """Read uptime and replace spaces by commas.""" seconds = safe_read_from_file("/proc/uptime", self.logger.error)[0] return seconds.translate(string.maketrans(' ', ',')) or None
def read_pid(tty_filepath): """Read PID from the tty info file.""" return safe_read_from_file( tty_filepath, self.logger.warning ).split("\n")
def uuid_from_file(): return safe_read_from_file(self.uuid_file, self.logger.warning)
def read_pid(tty_filepath): """Read PID from the tty info file.""" return safe_read_from_file(tty_filepath, self.logger.warning).split("\n")
def _read_config(self, config_file): """Read project configuration file striping out comment lines.""" content_file = safe_read_from_file(config_file, self.logger.error) or "" project_lines = self.there_are_comments.sub("", content_file) return project_lines.split("\n") if project_lines else []