Exemplo n.º 1
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]
Exemplo n.º 2
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 []
Exemplo n.º 3
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
Exemplo n.º 4
0
 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
Exemplo n.º 5
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]
Exemplo n.º 6
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
Exemplo n.º 7
0
    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)))
Exemplo n.º 8
0
    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)))
Exemplo n.º 9
0
 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
Exemplo n.º 10
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
Exemplo n.º 11
0
 def read_pid(tty_filepath):
     """Read PID from the tty info file."""
     return safe_read_from_file(
         tty_filepath, self.logger.warning
     ).split("\n")
Exemplo n.º 12
0
 def uuid_from_file():
     return safe_read_from_file(self.uuid_file, self.logger.warning)
Exemplo n.º 13
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
Exemplo n.º 14
0
 def read_pid(tty_filepath):
     """Read PID from the tty info file."""
     return safe_read_from_file(tty_filepath,
                                self.logger.warning).split("\n")
Exemplo n.º 15
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 []
Exemplo n.º 16
0
 def uuid_from_file():
     return safe_read_from_file(self.uuid_file, self.logger.warning)