def remove_tty_flag(tty_id): """Remove tty flag.""" feedback = self.feedback["tty_file_removal"].format(tty_id) with logged(self.logger.error, feedback, (IOError,)): with ignored(OSError): os.remove(filepath_from_tty_id(tty_id)) return True return False
def remove_tty_flag(tty_id): """Remove tty flag.""" feedback = self.feedback["tty_file_removal"].format(tty_id) with logged(self.logger.error, feedback, (IOError, )): with ignored(OSError): os.remove(filepath_from_tty_id(tty_id)) return True return False
def stop_project(self, container_name): """Destroy project's container and its allocated resources.""" def destroy_container(): action = [self.cernvm_fork_bin, container_name, "-D"] return call(action, stdout=DEVNULL) == 0 # Check success of container destruction is_destroyed = destroy_container() if is_destroyed: # Remove run file and host shared mount run_filepath = self.path_of_runfile(container_name) with ignored(EnvironmentError): os.remove(run_filepath) instance_name = "inst-{0}".format(container_name) project_www_folder = os.path.join(self.www_dir, instance_name) shutil.rmtree(project_www_folder) else: self.logger.warning(self.feedback["destruction_error"]) return is_destroyed
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 is_alive(pid): """Return if a process with a PID is still alive.""" with ignored(OSError): os.kill(pid, 0) return True return False