Ejemplo n.º 1
0
    def parse_matchmaking_results(self,
                                  task: EvaluationTask) -> MatchmakingResults:
        """
        Parses the results of a matchmaking task.

        :param task: Matchmaking task.
        :return: Results of the matchmaking task.
        """
        stdout = task.stdout
        exc.raise_if_falsy(stdout=stdout)

        parsing_ms = 0.0

        regex = re.compile(r'[pP]arsing: (.*) ms')

        for res in regex.finditer(stdout):
            parsing_ms += float(res.group(1)) if res else 0.0

        res = re.search(r'Reasoner initialization: (.*) ms', stdout)
        init_ms = float(res.group(1)) if res else 0.0

        res = re.search(r'Reasoning: (.*) ms', stdout)
        matchmaking_ms = float(res.group(1)) if res else 0.0

        return MatchmakingResults(parsing_ms=parsing_ms,
                                  init_ms=init_ms,
                                  matchmaking_ms=matchmaking_ms,
                                  max_memory=self._parse_memory(task),
                                  energy_stats=self._parse_energy(task))
Ejemplo n.º 2
0
def write(contents: Dict, path: str, binary: bool = True) -> None:
    """Writes a dictionary to a plist file."""
    exc.raise_if_falsy(contents=contents, path=path)

    with open(path, 'wb') as plist_file:
        fmt = plistlib.FMT_BINARY if binary else plistlib.FMT_XML
        plistlib.dump(contents, plist_file, fmt=fmt, sort_keys=True)
Ejemplo n.º 3
0
    def __init__(self, file_path: str) -> None:
        exc.raise_if_falsy(file_path=file_path)

        self.indent_level = 0
        self.indent_string = '    '

        self.__file_path = file_path
        self.__file: Optional[TextIO] = None
        self.__should_indent = False
Ejemplo n.º 4
0
def killall(process: str, sig: int = signal.SIGKILL) -> bool:
    """Sends signal to processes by name.

    :return: True if a process called 'name' was found, False otherwise.
    """
    exc.raise_if_falsy(process=process)
    found = False

    for pid in find_pids(process):
        found = True
        kill(pid, sig=sig)

    return found
Ejemplo n.º 5
0
def pkill(pattern: str, sig: int = signal.SIGKILL, match_arguments: bool = True) -> bool:
    """pkill-like function.

    :return: True if a matching process was found, False otherwise.
    """
    exc.raise_if_falsy(pattern=pattern)
    found = False

    for pid in find_pids(pattern, regex=True, match_arguments=match_arguments):
        found = True
        kill(pid, sig=sig)

    return found
Ejemplo n.º 6
0
    def _parse_reasoning_stats(
            self, task: EvaluationTask) -> StandardReasoningResults:
        """Parses performance stats for a reasoning task."""
        stdout = task.stdout
        exc.raise_if_falsy(stdout=stdout)

        res = re.search(r'Parsing: (.*) ms', stdout)
        parsing_ms = float(res.group(1)) if res else 0.0

        res = re.search(r'Reasoning: (.*) ms', stdout)
        reasoning_ms = float(res.group(1)) if res else 0.0

        return StandardReasoningResults(parsing_ms=parsing_ms,
                                        reasoning_ms=reasoning_ms,
                                        max_memory=self._parse_memory(task),
                                        energy_stats=self._parse_energy(task))
Ejemplo n.º 7
0
    def __init__(self,
                 executable: str,
                 args: Optional[List[str]] = None,
                 output_action: OutputAction = OutputAction.STORE,
                 input_path: Optional[str] = None) -> None:
        exc.raise_if_falsy(executable=executable, output_action=output_action)

        if not os.path.isabs(executable):
            executable = find_executable(executable)

        self._path = executable
        self._args = args
        self._output_action = output_action
        self._input_path = input_path

        self._completed: Optional[sp.CompletedProcess] = None
        self._process: Optional[sp.Popen] = None
Ejemplo n.º 8
0
def read(plist_path: str) -> Dict:
    """Read a plist file and return its contents as a dictionary."""
    exc.raise_if_falsy(plist_path=plist_path)
    data, error = NSData.dataWithContentsOfFile_options_error_(
        plist_path, 0, objc.nil)

    if not data:
        msg = 'Failed to load plist file at path: {}'.format(plist_path)
        _raise_ioerror_from_nserror(error, msg)

    contents, dummy, error = NSPropertyListSerialization.propertyListWithData_options_format_error_(
        data, NSPropertyListMutableContainersAndLeaves, objc.nil, objc.nil)

    if not contents:
        msg = 'Failed to deserialize plist at path: {}'.format(plist_path)
        _raise_ioerror_from_nserror(error, msg)

    return contents
Ejemplo n.º 9
0
def write(plist_contents: Dict,
          plist_path: str,
          plist_format: Format = Format.BINARY) -> None:
    """Write dictionary to a plist file."""
    exc.raise_if_falsy(plist_contents=plist_contents,
                       plist_path=plist_path,
                       plist_format=plist_format)

    data, error = NSPropertyListSerialization.dataWithPropertyList_format_options_error_(
        plist_contents, plist_format.value, 0, objc.nil)

    if not data:
        _raise_ioerror_from_nserror(error,
                                    'Failed to serialize plist contents.')

    success, error = data.writeToFile_options_error_(plist_path,
                                                     NSDataWritingAtomic,
                                                     objc.nil)

    if not success:
        _raise_ioerror_from_nserror(
            error, 'Failed to write plist to path: {}'.format(plist_path))
Ejemplo n.º 10
0
    def __init__(self,
                 jar: str,
                 jar_args: Optional[List[str]] = None,
                 vm_opts: Optional[List[str]] = None,
                 output_action: OutputAction = OutputAction.STORE,
                 input_path: Optional[str] = None) -> None:

        exc.raise_if_falsy(jar=jar, output_action=output_action)

        args = []

        if vm_opts:
            args.extend(vm_opts)

        args.extend(['-jar', jar])

        if jar_args:
            args.extend(jar_args)

        super(Jar, self).__init__(executable='java',
                                  args=args,
                                  output_action=output_action,
                                  input_path=input_path)
Ejemplo n.º 11
0
def read(path: str) -> Dict:
    """Reads a plist file and returns its contents as a dictionary."""
    exc.raise_if_falsy(path=path)

    with open(path, 'rb') as plist_file:
        return plistlib.load(plist_file)