Пример #1
0
 def test_find_directory_finds_envs_by_directory(self):
     this_dir = Path.from_string(__file__).parent()
     stdout, stderr = self.run_cli(["find", "directory", str(this_dir)])
     self.assertEqual(
         (stdout, stderr),
         (str(self.locator.for_directory(this_dir).path) + "\n", ""),
     )
Пример #2
0
 def test_find_directory_with_binary(self):
     this_dir = Path.from_string(__file__).parent()
     stdout, stderr = self.run_cli(["directory", str(this_dir), "python"], )
     this_dir_venv = self.locator.for_directory(this_dir)
     self.assertEqual(
         (stdout, stderr),
         (str(this_dir_venv.binary("python")) + "\n", ""),
     )
Пример #3
0
def makeService(options):
    if options["migrate"]:
        root = Path.from_string(__file__).sibling("alembic")
        alembic_config = alembic.config.Config(
            str(root.descendant("config.ini")),
        )
        alembic.command.upgrade(alembic_config, "head")

    greatPath = Path.from_string(great.__file__).parent()
    staticPath = greatPath.descendant("static")
    templatesPath = greatPath.descendant("templates")

    rootResource = twisted.web.resource.Resource()
    rootResource.putChild("", File(str(staticPath.descendant("index.html"))))
    rootResource.putChild("static", File(str(staticPath)))
    rootResource.putChild("api", MinionResource(create_app()))

    site = server.Site(rootResource)
    return strports.service(description=options["port"], factory=site)
Пример #4
0
def _readlink(fs, path):
    try:
        value = os.readlink(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.NotASymlink.errno:
            raise exceptions.NotASymlink(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise
    else:
        return Path.from_string(value)
Пример #5
0
def _realpath(fs, path):
    """
    .. warning::

        The ``os.path`` module's realpath does not error or warn about
        loops, but we do, following the behavior of GNU ``realpath(1)``!

    """

    real = Path.root()
    for segment in path.segments:
        seen = current, = {str(real.descendant(segment))}
        while os.path.islink(current):
            current = os.path.join(
                os.path.dirname(current), os.readlink(current),
            )
            if current in seen:
                raise exceptions.SymbolicLoop(current)
            seen.add(current)
        real = Path.from_string(current)
    return real
Пример #6
0
        raise


def _lstat(fs, path):
    try:
        return os.lstat(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise


FS = common.create(
    name="NativeFS",
    create_file=_create_file,
    open_file=_open_file,
    remove_file=_remove_file,
    create_directory=_create_directory,
    list_directory=_list_directory,
    remove_empty_directory=_remove_empty_directory,
    temporary_directory=lambda fs: Path.from_string(tempfile.mkdtemp()),
    stat=_stat,
    lstat=_lstat,
    link=_link,
    readlink=_readlink,
)
Пример #7
0
 def test_cwd(self):
     self.assertEqual(Path.cwd(), Path.from_string(os.getcwd()))
Пример #8
0
 def test_str(self):
     self.assertEqual(str(Path.from_string("/a/b/c")), "/a/b/c")
Пример #9
0
 def test_from_relative_string(self):
     self.assertEqual(
         Path.from_string("a/b/c"),
         Path.cwd().descendant("a", "b", "c"),
     )
Пример #10
0
 def test_from_string(self):
     self.assertEqual(Path.from_string("/a/b/c"), Path("a", "b", "c"))
Пример #11
0
 def test_path(self):
     path = parse(type=filesystems.click.PATH, value="some/path/provided")
     self.assertEqual(path, Path.from_string("some/path/provided"))
Пример #12
0
from appdirs import user_config_dir
from filesystems import Path, native
import toml

_PATH = Path.from_string(user_config_dir(__package__)).descendant(
    "config.toml", )


def load(path=_PATH, fs=native.FS()):
    return toml.loads(fs.get_contents(path))