Create paraview status file (.pvsm) based on input vtk files.
    :param vtk_files:
    :param pvsm_filename:
    :param relative_paths:
    :return:
171209
def create_pvsm_file(vtk_files, pvsm_filename, relative_paths=True):
    
    from xml.etree.ElementTree import Element, SubElement, Comment
    import os.path as op

    top = Element('ParaView')

    comment = Comment('Generated for PyMOTW')
    top.append(comment)

    numberi = 4923
    # vtk_file = "C:\Users\miros\lisa_data\83779720_2_liver.vtk"

    sms = SubElement(top, "ServerManagerState", version="5.4.1")
    file_list = SubElement(sms, "ProxyCollection", name="sources")
    for vtk_file_orig in vtk_files:
        numberi +=1
        dir, vtk_file_head = op.split(vtk_file_orig)
        if relative_paths:
            vtk_file = vtk_file_head
        else:
            vtk_file = vtk_file_orig
        number = str(numberi)
        proxy1 = SubElement(sms, "Proxy", group="sources", type="LegacyVTKFileReader", id=number, servers="1")
        property = SubElement(proxy1, "Property", name="FileNameInfo", id=number + ".FileNameInfo", number_of_elements="1")
        element = SubElement(property, "Element", index="0", value=vtk_file)
        property2 = SubElement(proxy1, "Property", name="FileNames", id=number + ".FileNames", number_of_elements="1")
        pr2s1 = SubElement(property2, "Element", index="0", value=vtk_file)
        pr2s2 = SubElement(property2, "Domain", name="files", id=number + ".FileNames.files")

    #     < Property
    #     name = "Opacity"
    #     id = "8109.Opacity"
    #     number_of_elements = "1" >
    #     < Element
    #     index = "0"
    #     value = "0.28" / >
    #     < Domain
    #     name = "range"
    #     id = "8109.Opacity.range" / >
    # < / Property >

        fn1 = SubElement(file_list, "Item", id=number, name=vtk_file_head)

    xml_str = prettify(top)
    # logger.debug(xml_str)
    with open(op.expanduser(pvsm_filename), "w") as file:
        file.write(xml_str)
1172521
def postproc(self):
        
        self.do_file_sub(
            "/etc/ovirt-engine/engine-config/engine-config.properties",
            r"Password.type=(.*)",
            r"Password.type=********"
        )
        self.do_file_sub(
            "/etc/rhevm/rhevm-config/rhevm-config.properties",
            r"Password.type=(.*)",
            r"Password.type=********"
        )

        engine_files = (
            'ovirt-engine.xml',
            'ovirt-engine_history/current/ovirt-engine.v1.xml',
            'ovirt-engine_history/ovirt-engine.boot.xml',
            'ovirt-engine_history/ovirt-engine.initial.xml',
            'ovirt-engine_history/ovirt-engine.last.xml',
        )
        for filename in engine_files:
            self.do_file_sub(
                "/var/tmp/ovirt-engine/config/%s" % filename,
                r"<password>(.*)</password>",
                r"<password>********</password>"
            )

        self.do_file_sub(
            "/etc/ovirt-engine/redhatsupportplugin.conf",
            r"proxyPassword=(.*)",
            r"proxyPassword=********"
        )

        passwd_files = [
            "logcollector.conf",
            "imageuploader.conf",
            "isouploader.conf"
        ]
        for conf_file in passwd_files:
            conf_path = os.path.join("/etc/ovirt-engine", conf_file)
            self.do_file_sub(
                conf_path,
                r"passwd=(.*)",
                r"passwd=********"
            )
            self.do_file_sub(
                conf_path,
                r"pg-pass=(.*)",
                r"pg-pass=********"
            )

        sensitive_keys = self.DEFAULT_SENSITIVE_KEYS
        # Handle --alloptions case which set this to True.
        keys_opt = self.get_option('sensitive_keys')
        if keys_opt and keys_opt is not True:
            sensitive_keys = keys_opt
        key_list = [x for x in sensitive_keys.split(':') if x]
        for key in key_list:
            self.do_path_regex_sub(
                self.DB_PASS_FILES,
                r'{key}=(.*)'.format(key=key),
                r'{key}=********'.format(key=key)
            )

        # Answer files contain passwords
        for key in (
            'OVESETUP_CONFIG/adminPassword',
            'OVESETUP_CONFIG/remoteEngineHostRootPassword',
            'OVESETUP_DWH_DB/password',
            'OVESETUP_DB/password',
            'OVESETUP_REPORTS_CONFIG/adminPassword',
            'OVESETUP_REPORTS_DB/password',
        ):
            self.do_path_regex_sub(
                r'/var/lib/ovirt-engine/setup/answers/.*',
                r'{key}=(.*)'.format(key=key),
                r'{key}=********'.format(key=key)
            )

        # aaa profiles contain passwords
        protect_keys = [
            "vars.password",
            "pool.default.auth.simple.password",
            "pool.default.ssl.truststore.password",
            "config.datasource.dbpassword"
        ]
        regexp = r"((?m)^\s*#*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)

        self.do_path_regex_sub(r"/etc/ovirt-engine/aaa/.*\.properties", regexp,
                               r"\1*********")
1371978
def ValidateVfsPath(path):
  """"""

  components = (path or "").lstrip("/").split("/")
  if not components:
    raise ValueError("Empty path is not a valid path: %s." %
                     utils.SmartStr(path))

  if components[0] not in ROOT_FILES_WHITELIST:
    raise ValueError(
        "First path component was '%s', but has to be one of %s" %
        (utils.SmartStr(components[0]), ", ".join(ROOT_FILES_WHITELIST)))

  return True
509132
def base_uri(relative_path=''):
    
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        if 'pytest' in sys.modules:
            for arg in reversed(sys.argv):
                path = os.path.realpath(arg)

                if os.path.exists(path):
                    base_path = path if os.path.isdir(path) else os.path.dirname(path)
                    break
        else:
            base_path = os.path.dirname(os.path.realpath(sys.argv[0]))

    if not os.path.exists(base_path):
        raise ValueError('Path %s does not exist' % base_path)

    return 'file://%s' % os.path.join(base_path, relative_path)
1247919
def list_status(self, path, **kwargs):
        
        return [
            FileStatus(**item) for item in
            _json(self._get(path, 'LISTSTATUS', **kwargs))['FileStatuses']['FileStatus']
        ]
245510
def GetFileEntryByPathSpec(self, path_spec):
    
    volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)

    # The virtual root file has not corresponding volume index but
    # should have a location.
    if volume_index is None:
      location = getattr(path_spec, 'location', None)
      if location is None or location != self.LOCATION_ROOT:
        return None

      return lvm_file_entry.LVMFileEntry(
          self._resolver_context, self, path_spec, is_root=True,
          is_virtual=True)

    if (volume_index < 0 or
        volume_index >= self._vslvm_volume_group.number_of_logical_volumes):
      return None

    return lvm_file_entry.LVMFileEntry(self._resolver_context, self, path_spec)
864069
def hash_and_stat_file(self, path, saltenv='base'):
        '''
        
        '''
        hash_result = self.hash_file(path, saltenv)
        try:
            path = self._check_proto(path)
        except MinionError as err:
            if not os.path.isfile(path):
                return hash_result, None
            else:
                try:
                    return hash_result, list(os.stat(path))
                except Exception:
                    return hash_result, None
        load = {'path': path,
                'saltenv': saltenv,
                'cmd': '_file_find'}
        fnd = self.channel.send(load)
        try:
            stat_result = fnd.get('stat')
        except AttributeError:
            stat_result = None
        return hash_result, stat_result
584752
def _load_file(self, filename):
        
        filename = os.path.abspath(os.path.expanduser(filename))
        # test if file exists
        if not os.path.isfile(filename):
            raise Exception('File %s does not exist' % filename)

        # Get extension
        ext = vtki.get_ext(filename)
        # Extensions: .vtm and .vtmb

        # Select reader
        if ext in ['.vtm', '.vtmb']:
            reader = vtk.vtkXMLMultiBlockDataReader()
        else:
            raise IOError('File extension must be either "vtm" or "vtmb"')

        # Load file
        reader.SetFileName(filename)
        reader.Update()
        self.ShallowCopy(reader.GetOutput())
273380
def to_file(cls, status):
        
        return {
            Status.PENDING: DataFile.PENDING,
            Status.WAITING: DataFile.PENDING,
            Status.COMPLETED: DataFile.COMPLETED,
            Status.DELETED: DataFile.COMPLETED
        }[status]
579026
def quick_make_file(local_file, tpl_file)
      current_file = local_file(local_file)
      template_file = @template.real_path(tpl_file)
      @template.make_file(
        template_file,
        current_file,
        @args.all.dup,
        make_data_files_array(current_file),
        method(:update_latest_options)
      )
    end
19707
def _find_observable_paths(extra_files=None):
    """"""
    rv = set(
        os.path.dirname(os.path.abspath(x)) if os.path.isfile(x) else os.path.abspath(x)
        for x in sys.path
    )

    for filename in extra_files or ():
        rv.add(os.path.dirname(os.path.abspath(filename)))

    for module in list(sys.modules.values()):
        fn = getattr(module, "__file__", None)
        if fn is None:
            continue
        fn = os.path.abspath(fn)
        rv.add(os.path.dirname(fn))

    return _find_common_roots(rv)
910111
def get_open_state_machine_of_file_system_path(self, file_system_path):
        
        for sm in self.state_machines.values():
            if sm.file_system_path == file_system_path:
                return sm
96929
def make_path_relative(path: str) -> str:
    
    if "../" in path:
        raise ManifestBuildingError(
            f"Path: {path} appears to be outside of the virtual source tree. "
            "Please make sure all sources are within the virtual source tree root directory."
        )

    if path[:2] != "./":
        return f"./{path}"
    return path
121712
def vofile(filename, **kwargs):
    
    basename = os.path.basename(filename)
    if os.access(basename, os.R_OK):
        return open(basename, 'r')
    kwargs['view'] = kwargs.get('view', 'data')
    return client.open(filename, **kwargs)
973174
def create_release_vcs(path, vcs_name=None):
    """"""
    from rez.plugin_managers import plugin_manager
    vcs_types = get_release_vcs_types()
    if vcs_name:
        if vcs_name not in vcs_types:
            raise ReleaseVCSError("Unknown version control system: %r" % vcs_name)
        cls = plugin_manager.get_plugin_class('release_vcs', vcs_name)
        return cls(path)

    classes_by_level = {}
    for vcs_name in vcs_types:
        cls = plugin_manager.get_plugin_class('release_vcs', vcs_name)
        result = cls.find_vcs_root(path)
        if not result:
            continue
        vcs_path, levels_up = result
        classes_by_level.setdefault(levels_up, []).append((cls, vcs_path))

    if not classes_by_level:
        raise ReleaseVCSError("No version control system for package "
                      "releasing is associated with the path %s" % path)

    # it's ok to have multiple results, as long as there is only one at the
    # "closest" directory up from this dir - ie, if we start at:
    #    /blah/foo/pkg_root
    # and these dirs exist:
    #    /blah/.hg
    #    /blah/foo/.git
    # ...then this is ok, because /blah/foo/.git is "closer" to the original
    # dir, and will be picked. However, if these two directories exist:
    #    /blah/foo/.git
    #    /blah/foo/.hg
    # ...then we error, because we can't decide which to use

    lowest_level = sorted(classes_by_level)[0]
    clss = classes_by_level[lowest_level]
    if len(clss) > 1:
        clss_str = ", ".join(x[0].name() for x in clss)
        raise ReleaseVCSError("Several version control systems are associated "
                              "with the path %s: %s. Use rez-release --vcs to "
                              "choose." % (path, clss_str))
    else:
        cls, vcs_root = clss[0]
        return cls(pkg_root=path, vcs_root=vcs_root)
980847
def create_from_file(file_path)
      client_setup
      resource = OneviewSDK::Resource.from_file(@client, file_path)
      fail_nice 'Failed to determine resource type!' if resource.class == OneviewSDK::Resource
      existing_resource = resource.class.new(@client, resource.data)
      resource.data.delete('uri')
      if existing_resource.retrieve!
        if options['if_missing']
          puts "Skipped: #{resource.class.name.split('::').last} '#{resource[:name]}' already exists.\n#{existing_resource[:uri]}"
          return
        end
        if existing_resource.like?(resource.data)
          puts "Skipped: #{resource.class.name.split('::').last} '#{resource[:name]}' is up to date.\n#{existing_resource[:uri]}"
          return
        end
        begin
          existing_resource.update(resource.data)
          puts "Updated Successfully!\n#{existing_resource[:uri]}"
        rescue StandardError => e
          fail_nice "Failed to update #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
        end
      else
        begin
          resource.create
          puts "Created Successfully!\n#{resource[:uri]}"
        rescue StandardError => e
          fail_nice "Failed to create #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
        end
      end
    rescue IncompleteResource => e
      fail_nice "Failed to create #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
    rescue SystemCallError => e # File open errors
      fail_nice e
    end
761482
def paths
      relative_paths = gem_names.flat_map do |plugin|
        Dir.glob("vendor/gems/ruby/*/gems/#{plugin}*/lib/**/**/**/**.rb")
      end

      relative_paths.map { |path| File.join(dir, path) }
    end