def test_normabspath(self):
     base = "/foo/bar"
     self.assertEqual("/foo/bar", normabspath('.', base))
     self.assertEqual("/foo/bar", normabspath('foo/..', base))
     self.assertEqual("/foo/bar", normabspath(base, base))
     self.assertEqual("/foo", normabspath("/foo", base))
     self.assertEqual("/foo/bar/bim", normabspath('bim', base))
     self.assertEqual("/foo", normabspath('..', base))
Ejemplo n.º 2
0
        def do_work(self):
            localname = ""
            scm = None
            uri = ""
            curr_uri = None
            exists = False
            version = ""  # what is given in config file
            modified = ""
            actualversion = ""  # revision number of version
            specversion = ""  # actual revision number
            localname = self.element.get_local_name()
            path = self.element.get_path() or localname

            if localname is None or localname == "":
                raise MultiProjectException(
                    "Missing local-name in element: %s" % self.element)
            abs_path = normabspath(path, self.path)
            if (os.path.exists(abs_path)):
                exists = True
            if self.element.is_vcs_element():
                if not exists:
                    path_spec = self.element.get_path_spec()
                    version = path_spec.get_version()
                else:
                    path_spec = self.element.get_versioned_path_spec()
                    version = path_spec.get_version()
                    curr_uri = path_spec.get_curr_uri()
                    status = self.element.get_status(self.path)
                    if (status is not None and status.strip() != ''):
                        modified = True
                    specversion = path_spec.get_revision()
                    if (version is not None and version.strip() != '' and
                        (specversion is None or specversion.strip() == '')):

                        specversion = '"%s"' % version
                    actualversion = path_spec.get_current_revision()
                scm = path_spec.get_scmtype()
                uri = path_spec.get_uri()
            return {
                'scm': scm,
                'exists': exists,
                'localname': localname,
                'path': path,
                'uri': uri,
                'curr_uri': curr_uri,
                'version': version,
                'specversion': specversion,
                'actualversion': actualversion,
                'modified': modified,
                'properties': self.element.get_properties()
            }
Ejemplo n.º 3
0
 def test_normabspath(self):
     base = "/foo/bar"
     self.assertEqual("/foo/bar", normabspath('.', base))
     self.assertEqual("/foo/bar", normabspath('foo/..', base))
     self.assertEqual("/foo/bar", normabspath(base, base))
     self.assertEqual("/foo", normabspath("/foo", base))
     self.assertEqual("/foo/bar/bim", normabspath('bim', base))
     self.assertEqual("/foo", normabspath('..', base))
Ejemplo n.º 4
0
        def do_work(self):
            localname = ""
            scm = None
            uri = ""
            curr_uri = None
            exists = False
            version = ""  # what is given in config file
            modified = ""
            actualversion = ""  # revision number of version
            specversion = ""  # actual revision number
            localname = self.element.get_local_name()
            path = self.element.get_path() or localname

            if localname is None or localname == "":
                raise MultiProjectException(
                    "Missing local-name in element: %s" % self.element)
            if (os.path.exists(normabspath(path, self.path))):
                exists = True
            if self.element.is_vcs_element():
                if not exists:
                    path_spec = self.element.get_path_spec()
                    version = path_spec.get_version()
                else:
                    path_spec = self.element.get_versioned_path_spec()
                    version = path_spec.get_version()
                    curr_uri = path_spec.get_curr_uri()
                    status = self.element.get_status(self.path, self.untracked)
                    if (status is not None and
                        status.strip() != ''):
                        modified = True
                    specversion = path_spec.get_revision()
                    if (version is not None and
                        version.strip() != '' and
                        (specversion is None or specversion.strip() == '')):

                        specversion = '"%s"' % version
                    actualversion = path_spec.get_current_revision()
                scm = path_spec.get_scmtype()
                uri = path_spec.get_uri()
            return {'scm': scm,
                    'exists': exists,
                    'localname': localname,
                    'path': path,
                    'uri': uri,
                    'curr_uri': curr_uri,
                    'version': version,
                    'specversion': specversion,
                    'actualversion': actualversion,
                    'modified': modified,
                    'properties': self.element.get_properties()}
Ejemplo n.º 5
0
    def add_path_spec(self, path_spec, merge_strategy='KillAppend'):
        """
        add new element to this config with information provided in path spec

        :param merge_strategy: see insert_element
        :param path_specs: PathSpec objects
        :returns: merge action taken, see insert_element
        """
        # compute the local_path for the config element
        local_path = normabspath(path_spec.get_local_name(),
                                 self.get_base_path())
        if os.path.isfile(local_path):
            if path_spec.get_tags(
            ) is not None and 'setup-file' in path_spec.get_tags():
                elem = SetupConfigElement(local_path,
                                          os.path.normpath(
                                              path_spec.get_local_name()),
                                          properties=path_spec.get_tags())
                return self.insert_element(elem, merge_strategy)
            else:
                print("!!!!! Warning: Not adding file %s" % local_path)
                return None
        else:
            # scmtype == None kept for historic reasons here
            if (path_spec.get_scmtype() == None
                    and self.config_filename is not None and os.path.exists(
                        os.path.join(local_path, self.config_filename))):

                print(
                    "!!!!! Warning: Not recursing into other config folder %s containing file %s"
                    % (local_path, self.config_filename))
                return None

            if path_spec.get_scmtype() != None:
                return self._insert_vcs_path_spec(path_spec, local_path,
                                                  merge_strategy)
            else:
                # keep the given local name (e.g. relative path) for other
                # elements, but normalize
                local_name = os.path.normpath(path_spec.get_local_name())
                elem = OtherConfigElement(local_path,
                                          local_name,
                                          path_spec.get_uri(),
                                          path_spec.get_version(),
                                          properties=path_spec.get_tags())
                return self.insert_element(elem, merge_strategy)
Ejemplo n.º 6
0
    def add_path_spec(self, path_spec, merge_strategy='KillAppend'):
        """
        add new element to this config with information provided in path spec

        :param merge_strategy: see insert_element
        :param path_specs: PathSpec objects
        :returns: merge action taken, see insert_element
        """
        # compute the local_path for the config element
        local_path = normabspath(
            path_spec.get_local_name(), self.get_base_path())
        if os.path.isfile(local_path):
            if path_spec.get_tags() is not None and 'setup-file' in path_spec.get_tags():
                elem = SetupConfigElement(local_path,
                                          os.path.normpath(path_spec.get_local_name()),
                                          properties=path_spec.get_tags())
                return self.insert_element(elem, merge_strategy)
            else:
                print("!!!!! Warning: Not adding file %s" % local_path)
                return None
        else:
            # scmtype == None kept for historic reasons here
            if (path_spec.get_scmtype() == None and
                self.config_filename is not None and
                os.path.exists(os.path.join(local_path, self.config_filename))):

                print("!!!!! Warning: Not recursing into other config folder %s containing file %s" % (local_path, self.config_filename))
                return None

            if path_spec.get_scmtype() != None:
                return self._insert_vcs_path_spec(path_spec, local_path, merge_strategy)
            else:
                # keep the given local name (e.g. relative path) for other
                # elements, but normalize
                local_name = os.path.normpath(path_spec.get_local_name())
                elem = OtherConfigElement(local_path,
                                          local_name,
                                          path_spec.get_uri(),
                                          path_spec.get_version(),
                                          properties=path_spec.get_tags())
                return self.insert_element(elem, merge_strategy)