コード例 #1
0
def rmdir(path: PathLike) -> str:
    r"""
	Remove the given directory and its contents.

	:param path:

	:returns: A message in the format :file:`'removing {<path>}'`

	.. attention::

		On Windows-like systems using ``\`` as a path separator
		you may need to use a *raw string* for the path as the ``toxinidir``
		substitution may contain backslashes:

		.. code-block:: ini

			recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")

	"""

    path = PathPlus(path)
    if path.is_dir():
        shutil.rmtree(path)

    return f"removing {path!s}"
コード例 #2
0
    def __init__(
        self,
        lib_path: PathLike,
        lib_type: int = NISTMS_MAIN_LIB,
        work_dir: Optional[PathLike] = None,
        debug: bool = False,
    ):
        """
		:param lib_path: The path to the mass spectral library.
		:param lib_type: The type of library. One of NISTMS_MAIN_LIB, NISTMS_USER_LIB, NISTMS_REP_LIB.
		:param work_dir: The path to the working directory.
		"""

        if not isinstance(lib_path, pathlib.Path):
            lib_path = pathlib.Path(lib_path)

        if not lib_path.is_dir():
            raise FileNotFoundError(
                f"Library not found at the given path: {lib_path}")

        if lib_type not in {NISTMS_MAIN_LIB, NISTMS_USER_LIB, NISTMS_REP_LIB}:
            raise ValueError(
                "`lib_type` must be one of NISTMS_MAIN_LIB, NISTMS_USER_LIB, NISTMS_REP_LIB."
            )

        # # Check if the server is already running
        # for container in client.containers.list(all=True, filters={"status": "running"}):
        # 	if container.name == "pyms-nist-server":
        # 		self.docker = container
        # 		break
        # else:
        #

        self.debug: bool = bool(debug)

        print("Launching Docker...")

        try:
            self.__launch_container(lib_path, lib_type)
        except docker.errors.ImageNotFound:
            print("Docker Image not found. Downloading now.")
            client.images.pull("domdfcoding/pywine-pyms-nist")
            self.__launch_container(lib_path, lib_type)

        atexit.register(self.uninit)

        retry_count = 0

        # Wait for server to come online
        while retry_count < 240:
            try:
                if requests.get("http://localhost:5001/").text == "ready":
                    self.initialised = True
                    return

            except requests.exceptions.ConnectionError:
                time.sleep(0.5)
                retry_count += 1

        raise TimeoutError("Unable to communicate with the search server.")
コード例 #3
0
def is_datafile(file_name: PathLike) -> bool:
    """
	Returns whether the given path is a valid data file.

	:param file_name: name of the ``.d`` datafile
	"""

    if not isinstance(file_name, pathlib.Path):
        try:
            file_name = pathlib.Path(file_name)
        except TypeError:
            raise TypeError(
                f"'file_name' must be a string or a PathLike object, not {type(file_name)}"
            )

    if file_name.exists():
        if file_name.is_dir():
            if ((file_name / "AcqData") / "Contents.xml").exists():
                return True

    return False