Пример #1
0
    def get_current_workspace(self):
        path = pathlib.Path().absolute()

        # Traverse path upwards to get the workspace
        workspace = None
        while workspace == None and path.as_posix() != "/":
            workspace = self.get_by_path(path.as_posix())
            path = path.parent

        return workspace
Пример #2
0
        def helper(self, path: Path, *args: Any, **kwargs: Any) -> Any:

            path = self._path / path

            path = Path(os.path.normpath(str(path)))

            return f(self, path.as_posix(), *args, **kwargs)
Пример #3
0
def rel(path: pathlib.Path) -> str:
    """
    Convert a path to a relative Path.

    Returns a string as these should only be used for presentation.
    """
    return os.path.relpath(path.as_posix(), pathlib.Path.cwd().as_posix())
Пример #4
0
 def abspath(self, path):
     if isinstance(path, PurePath):
         path = path.as_posix()
     if hasattr(path, 'decode'):  # CRUFT: python 2
         path = path.decode()
     if path[0] != '/':
         path = '/'.join((self._wd[:-1], path))
     return os.path.normpath(path)
Пример #5
0
        def setup_loader():
            with resources.path("fapolicy_analyzer.resources",
                                "filled_fading_balls.gif") as path:
                animation = GdkPixbuf.PixbufAnimation.new_from_file(
                    path.as_posix())

            loader = self.get_object("trustViewLoader")
            loader.set_from_animation(animation)
Пример #6
0
 def exclusion(path):
     if path.as_posix() in non_special_excludes:
         return True
     for pattern in match_excludes:
         result = path.match(pattern, match_entire=True)
         if result:
             return True
     return False
Пример #7
0
 def exclusion(path):
     if path.as_posix() in non_special_excludes:
         return True
     for pattern in match_excludes:
         result = path.match(pattern, match_entire=True)
         if result:
             return True
     return False
Пример #8
0
def external_execution(ctx, playbook_configuration_id,
                       playbook_configuration_version, path):
    """Create bundle for external execution.

    This command creates tarball which has everything required for
    external execution of the plugin. This tarball includes commandline
    for execution with Ansible, the contents of the plugin, generated
    dynamic inventory.

    Please pay attention to following:

    \b
      - This execution won't be added to the decapod and
        will be done without any Decapod interaction
      - You should have installed Ansible 2.3 or newer
      - Please be sure that ceph-ansible is present in role path
        of the ansible.

    http://docs.ansible.com/ansible/intro_configuration.html#roles-path
    https://github.com/ceph/ceph-ansible
    """

    playbook_configuration_id = str(playbook_configuration_id)
    subdir_path = "{0}-{1}".format(
        playbook_configuration_id,
        playbook_configuration_version
    )
    if path is None:
        path = subdir_path
    path = pathlib.Path(path).absolute()

    playbook_config = \
        playbook_configuration.PlaybookConfigurationModel.find_version(
            playbook_configuration_id, playbook_configuration_version)
    if not playbook_config:
        ctx.fail("Cannot find such playbook config")

    plugin = get_plugin(playbook_config.playbook_id)
    working_dir = tempfile.TemporaryDirectory(prefix="exec")
    ctx.call_on_close(working_dir.cleanup)
    working_dir = pathlib.Path(working_dir.name)

    tmpdir = working_dir.joinpath(subdir_path).absolute()
    tmpdir.mkdir()
    tmpdir.joinpath("fetch_directory").mkdir()

    copy_decapod_common_playbooks(tmpdir)
    copy_ceph_ansible(tmpdir)
    copy_private_ssh_key(tmpdir)
    copy_ansible_config(tmpdir)
    copy_plugin_contents(tmpdir, plugin)
    copy_monitor_keyring(tmpdir, playbook_config)
    copy_decapod_data(tmpdir, playbook_config)
    dump_inventory(tmpdir, playbook_config)
    compose_commandline(tmpdir, playbook_config)

    shutil.make_archive(path.as_posix(), "gztar", working_dir.as_posix())
    click.echo(path.with_suffix(".tar.gz").as_posix())
Пример #9
0
def external_execution(ctx, playbook_configuration_id,
                       playbook_configuration_version, path):
    """Create bundle for external execution.

    This command creates tarball which has everything required for
    external execution of the plugin. This tarball includes commandline
    for execution with Ansible, the contents of the plugin, generated
    dynamic inventory.

    Please pay attention to following:

    \b
      - This execution won't be added to the decapod and
        will be done without any Decapod interaction
      - You should have installed Ansible 2.3 or newer
      - Please be sure that ceph-ansible is present in role path
        of the ansible.

    http://docs.ansible.com/ansible/intro_configuration.html#roles-path
    https://github.com/ceph/ceph-ansible
    """

    playbook_configuration_id = str(playbook_configuration_id)
    subdir_path = "{0}-{1}".format(playbook_configuration_id,
                                   playbook_configuration_version)
    if path is None:
        path = subdir_path
    path = pathlib.Path(path).absolute()

    playbook_config = \
        playbook_configuration.PlaybookConfigurationModel.find_version(
            playbook_configuration_id, playbook_configuration_version)
    if not playbook_config:
        ctx.fail("Cannot find such playbook config")

    plugin = get_plugin(playbook_config.playbook_id)
    working_dir = tempfile.TemporaryDirectory(prefix="exec")
    ctx.call_on_close(working_dir.cleanup)
    working_dir = pathlib.Path(working_dir.name)

    tmpdir = working_dir.joinpath(subdir_path).absolute()
    tmpdir.mkdir()
    tmpdir.joinpath("fetch_directory").mkdir()

    copy_decapod_common_playbooks(tmpdir)
    copy_ceph_ansible(tmpdir)
    copy_private_ssh_key(tmpdir)
    copy_ansible_config(tmpdir)
    copy_plugin_contents(tmpdir, plugin)
    copy_monitor_keyring(tmpdir, playbook_config)
    copy_decapod_data(tmpdir, playbook_config)
    dump_inventory(tmpdir, playbook_config)
    compose_commandline(tmpdir, playbook_config)

    shutil.make_archive(path.as_posix(), "gztar", working_dir.as_posix())
    click.echo(path.with_suffix(".tar.gz").as_posix())
Пример #10
0
def _expand_paths_itr(paths, marker='*'):
    """Iterator version of :func:`expand_paths`.
    """
    for path in paths:
        if is_path(path):
            if marker in path:  # glob path pattern
                for ppath in sglob(path):
                    yield ppath
            else:
                yield path  # a simple file path
        elif is_path_obj(path):
            if marker in path.as_posix():
                for ppath in sglob(path.as_posix()):
                    yield normpath(ppath)
            else:
                yield normpath(path.as_posix())
        elif is_ioinfo(path):
            yield path.path
        else:  # A file or file-like object
            yield path
Пример #11
0
def _expand_paths_itr(paths, marker='*'):
    """Iterator version of :func:`expand_paths`.
    """
    for path in paths:
        if is_path(path):
            if marker in path:  # glob path pattern
                for ppath in sglob(path):
                    yield ppath
            else:
                yield path  # a simple file path
        elif is_path_obj(path):
            if marker in path.as_posix():
                for ppath in sglob(path.as_posix()):
                    yield normpath(ppath)
            else:
                yield normpath(path.as_posix())
        elif is_ioinfo(path):
            yield path.path
        else:  # A file or file-like object
            yield path
Пример #12
0
    def has_path(self, path):
        '''Check to see if an image path exists in the database.

        Parameters
        ----------
        path : path-like object
            candidate image path

        Returns
        -------
        bool
            ``True`` if the filename is in the database
        '''
        try:
            path = path.as_posix()
        except AttributeError:
            pass
        return not database.Image.get_hash(path) is None
Пример #13
0
    def handle_image(self, objects, obj):
        obj.get_int("INDEXINSHEET")
        obj.check("OWNERPARTID", b"-1")
        obj.get_bool("KEEPASPECT")

        location = get_location(obj)
        corner = list()
        for x in "XY":
            corner.append(get_int_frac(obj, "CORNER." + x))

        kw = dict()
        name = obj["FILENAME"]
        if obj.get_bool("EMBEDIMAGE"):
            file = self.storage_files.get(name)
            if file is None:
                warn("Embedded file {!r} not found".format(name))
            else:
                self.storage_stream.seek(file)
                [length] = struct.unpack("<L", self.storage_stream.read(4))
                file = zlib.decompress(self.storage_stream.read(length))
                kw.update(data=file)
                self.files_used.add(name)
        else:
            path = PureWindowsPath(os.fsdecode(name))
            if not issubclass(Path, PureWindowsPath) and path.drive:
                warn("Cannot use file {} with drive".format(path))
            else:
                path = Path(path.as_posix())
                if path.is_reserved():
                    warn("Cannot use reserved file name " + format(path))
                elif path.exists():
                    kw.update(file=str(path))
                else:
                    warn("External file {} does not exist".format(path))
        if kw:
            self.renderer.image(location, corner, **kw)
        else:
            self.renderer.rectangle(location, corner, width=0.6)
            self.renderer.line(location, corner, width=0.6)
            self.renderer.line((location[0], corner[1]),
                               (corner[0], location[1]),
                               width=0.6)
Пример #14
0
 def handle_image(self, objects, obj):
     obj.get_int("INDEXINSHEET")
     obj.check("OWNERPARTID", b"-1")
     obj.get_bool("KEEPASPECT")
     
     location = get_location(obj)
     corner = list()
     for x in "XY":
         corner.append(get_int_frac(obj, "CORNER." + x))
     
     kw = dict()
     name = obj["FILENAME"]
     if obj.get_bool("EMBEDIMAGE"):
         file = self.storage_files.get(name)
         if file is None:
             warn("Embedded file {!r} not found".format(name))
         else:
             self.storage_stream.seek(file)
             [length] = struct.unpack("<L", self.storage_stream.read(4))
             file = zlib.decompress(self.storage_stream.read(length))
             kw.update(data=file)
             self.files_used.add(name)
     else:
         path = PureWindowsPath(os.fsdecode(name))
         if not issubclass(Path, PureWindowsPath) and path.drive:
             warn("Cannot use file {} with drive".format(path))
         else:
             path = Path(path.as_posix())
             if path.is_reserved():
                 warn("Cannot use reserved file name " + format(path))
             elif path.exists():
                 kw.update(file=str(path))
             else:
                 warn("External file {} does not exist".format(path))
     if kw:
         self.renderer.image(location, corner, **kw)
     else:
         self.renderer.rectangle(location, corner, width=0.6)
         self.renderer.line(location, corner, width=0.6)
         self.renderer.line((location[0], corner[1]),
             (corner[0], location[1]), width=0.6)
Пример #15
0
def get_schema_path(major, minor):
    """Get the path to a package resource directory housing alert schema
    definitions.

    Parameters
    ----------
    major : `int`
        Major version number for the schema.
    minor : `int`
        Minor version number for the schema.

    Returns
    -------
    path : `str`
        Path to the directory containing the schemas.

    """

    # Note that as_posix() is right here, since pkg_resources
    # always uses slash-delimited paths, even on Windows.
    path = PurePath(f"schema/{major}/{minor}/")
    return pkg_resources.resource_filename(__name__, path.as_posix())
Пример #16
0
 def __init__(self, root_dir, set_name='train', size=[240, 320], rgb=True, downsampleDepthFactor=1, training_depth='inpaint'):
     # training depth option: inpaint | original
     self.root_dir = root_dir  
     self.size = size
     self.set_name = set_name
     self.training_depth = training_depth
     self.rgb = rgb
     self.current_set_len = 0
     self.path2files = []
     self.downsampleDepthFactor = downsampleDepthFactor
     self.NYU_MIN_DEPTH_CLIP = 0.0
     self.NYU_MAX_DEPTH_CLIP = 10.0
     
     self.path2files = [path.as_posix() for path in Path(self.root_dir, self.set_name).glob("**/*") if path.name.endswith('.h5')]
     self.current_set_len = len(self.path2files)   
     
     self.TF2tensor = transforms.ToTensor()
     self.TF2PIL = transforms.ToPILImage()
     self.TFNormalize = transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))
     self.funcResizeTensor = nn.Upsample(size=self.size, mode='nearest', align_corners=None)
     self.funcResizeDepth = nn.Upsample(size=[int(self.size[0]*self.downsampleDepthFactor),
                                              int(self.size[1]*self.downsampleDepthFactor)], 
                                        mode='nearest', align_corners=None)
Пример #17
0
def make_absolute(path: pathlib.PurePath) -> pathlib.Path:
    """Make the path absolute without resolving symlinks or drive letters.

    This function is an alternative to `Path.resolve()`. It make the path absolute,
    and resolves `../../`, but contrary to `Path.resolve()` does NOT perform these
    changes:
        - Symlinks are NOT followed.
        - Windows Network shares that are mapped to a drive letter are NOT resolved
          to their UNC notation.

    The type of the returned path is determined by the current platform.
    """
    str_path = path.as_posix()
    if len(str_path) >= 2 and str_path[0].isalpha() and str_path[1] == ':':
        # This is an absolute Windows path. It must be handled with care on non-Windows platforms.
        if platform.system() != 'Windows':
            # Normalize the POSIX-like part of the path, but leave out the drive letter.
            non_drive_path = str_path[2:]
            normalized = os.path.normpath(non_drive_path)
            # Stick the drive letter back on the normalized path.
            return pathlib.Path(str_path[:2] + normalized)

    return pathlib.Path(os.path.abspath(str_path))
Пример #18
0
 def rel(self, path: pathlib.Path) -> str:
     return os.path.relpath(path.as_posix(), self.directory.as_posix())