Ejemplo n.º 1
0
    def _from_location(self, location):
        """Return the ID of a location (origin URL or local copy path)."""
        # Is location a "~/cylc-run/$SUITE/" directory?
        # Use a hacky way to read the "log/rose-suite-run.version" file
        suite_engine_proc = SuiteEngineProcessor.get_processor()
        suite_dir_rel_root = getattr(
            suite_engine_proc, "SUITE_DIR_REL_ROOT", None)
        if suite_dir_rel_root and "/" + suite_dir_rel_root + "/" in location:
            loc = location
            while "/" + suite_dir_rel_root + "/" in loc:
                suite_version_file_name = os.path.join(
                    loc, "log/rose-suite-run.version")
                loc = os.path.dirname(loc)
                if not os.access(suite_version_file_name, os.F_OK | os.R_OK):
                    continue
                state = None
                url = None
                rev = None
                for i, line in enumerate(open(suite_version_file_name)):
                    line = line.strip()
                    if state is None:
                        if line == "# SVN INFO":
                            state = line
                    elif state == "# SVN INFO":
                        if line.startswith("URL:"):
                            url = line.split(":", 1)[1].strip()
                        elif line.startswith("Revision:"):
                            rev = line.split(":", 1)[1].strip()
                        elif not line:
                            break
                location = url + "@" + rev
                break

        # Assume location is a Subversion working copy of a Rosie suite
        info_parser = SvnInfoXMLParser()
        try:
            info_entry = info_parser.parse(self.svn("info", "--xml", location))
        except RosePopenError:
            raise SuiteIdLocationError(location)

        if "url" not in info_entry:
            raise SuiteIdLocationError(location)
        root = info_entry["repository:root"]
        url = info_entry["url"]
        path = url[len(root):]
        if not path:
            raise SuiteIdLocationError(location)
        self.prefix = self.get_prefix_from_location_root(root)
        names = path.lstrip("/").split("/", self.SID_LEN + 1)
        if len(names) < self.SID_LEN:
            raise SuiteIdLocationError(location)
        sid = "".join(names[0:self.SID_LEN])
        if not self.REC_IDX.match(sid):
            raise SuiteIdLocationError(location)
        self.idx = self.FORMAT_IDX % (self.prefix, sid)
        self.sid = sid
        if len(names) > self.SID_LEN:
            self.branch = names[self.SID_LEN]
        if "commit:revision" in info_entry:
            self.revision = info_entry["commit:revision"]
Ejemplo n.º 2
0
    def to_string_with_version(self):
        location = self.to_origin()
        info_parser = SvnInfoXMLParser()
        try:
            info_entry = info_parser.parse(self.svn("info", "--xml", location))
        except RosePopenError as e:
            raise SuiteIdTextError(location)

        branch = self.branch
        if not branch:
            branch = self.BRANCH_TRUNK
        revision = self.revision
        if not revision or revision == self.REV_HEAD:
            revision = self.REV_HEAD
            if info_entry.has_key("commit:revision"):
                revision = str(info_entry["commit:revision"])
        return str(self) + self.FORMAT_VERSION % (branch, revision)
Ejemplo n.º 3
0
 def to_string_with_version(self):
     """Return the full ID in the form prefix-idx/branch@rev."""
     branch = self.branch
     if not branch:
         branch = self.BRANCH_TRUNK
     revision = self.revision
     if not revision:
         revision = self.REV_HEAD
     if revision == self.REV_HEAD:
         location = self.to_origin()
         location += self.FORMAT_VERSION % (branch, str(revision))
         info_parser = SvnInfoXMLParser()
         try:
             info_entry = info_parser.parse(
                 self.svn("info", "--xml", location))
         except RosePopenError as exc:
             raise SuiteIdTextError(location)
         else:
             if "commit:revision" in info_entry:
                 revision = int(info_entry["commit:revision"])
     return str(self) + self.FORMAT_VERSION % (branch, revision)
Ejemplo n.º 4
0
 def to_string_with_version(self):
     """Return the full ID in the form prefix-idx/branch@rev."""
     branch = self.branch
     if not branch:
         branch = self.BRANCH_TRUNK
     revision = self.revision
     if not revision:
         revision = self.REV_HEAD
     if revision == self.REV_HEAD:
         location = self.to_origin()
         location += self.FORMAT_VERSION % (branch, str(revision))
         info_parser = SvnInfoXMLParser()
         try:
             info_entry = info_parser.parse(
                 self.svn("info", "--xml", location))
         except RosePopenError as exc:
             raise SuiteIdTextError(location)
         else:
             if "commit:revision" in info_entry:
                 revision = int(info_entry["commit:revision"])
     return str(self) + self.FORMAT_VERSION % (branch, revision)
Ejemplo n.º 5
0
    def _from_location(self, location, skip_status=False):
        """Return the ID of a location (origin URL or local copy path).
        """
        # FIXME: not sure why a closure for "state" does not work here?
        info_parser = SvnInfoXMLParser()
        try:
            info_entry = info_parser.parse(self.svn("info", "--xml", location))
        except RosePopenError as e:
            raise SuiteIdLocationError(location)

        if not info_entry.has_key("url"):
            raise SuiteIdLocationError(location)
        root = info_entry["repository:root"]
        url = info_entry["url"]
        path = url[len(root):]
        if not path:
            raise SuiteIdLocationError(location)
        locations = self.get_prefix_locations()
        if not locations:
            raise SuiteIdLocationError(location)
        for key, value in locations.items():
            if value == root:
                self.prefix = key
                break
        else:
            raise SuiteIdPrefixError(location)
        names = path.lstrip("/").split("/", self.SID_LEN + 1)
        if len(names) < self.SID_LEN:
            raise SuiteIdLocationError(location)
        sid = "".join(names[0:self.SID_LEN])
        if not self.REC_IDX.match(sid):
            raise SuiteIdLocationError(location)
        self.idx = self.FORMAT_IDX %(self.prefix, sid)
        self.sid = sid
        if len(names) > self.SID_LEN:
            self.branch = names[self.SID_LEN]
        if info_entry.has_key("commit:revision"):
            self.revision = info_entry["commit:revision"]
        if not skip_status:
            self._set_statuses(location)
Ejemplo n.º 6
0
    def _from_location(self, location):
        """Return the ID of a location (origin URL or local copy path).
        """
        # FIXME: not sure why a closure for "state" does not work here?
        info_parser = SvnInfoXMLParser()
        try:
            info_entry = info_parser.parse(self.svn("info", "--xml", location))
        except RosePopenError:
            raise SuiteIdLocationError(location)

        if "url" not in info_entry:
            raise SuiteIdLocationError(location)
        root = info_entry["repository:root"]
        url = info_entry["url"]
        path = url[len(root):]
        if not path:
            raise SuiteIdLocationError(location)
        locations = self.get_prefix_locations()
        if not locations:
            raise SuiteIdLocationError(location)
        for key, value in locations.items():
            if value == root:
                self.prefix = key
                break
        else:
            raise SuiteIdPrefixError(location)
        names = path.lstrip("/").split("/", self.SID_LEN + 1)
        if len(names) < self.SID_LEN:
            raise SuiteIdLocationError(location)
        sid = "".join(names[0:self.SID_LEN])
        if not self.REC_IDX.match(sid):
            raise SuiteIdLocationError(location)
        self.idx = self.FORMAT_IDX % (self.prefix, sid)
        self.sid = sid
        if len(names) > self.SID_LEN:
            self.branch = names[self.SID_LEN]
        if "commit:revision" in info_entry:
            self.revision = info_entry["commit:revision"]
Ejemplo n.º 7
0
    def _from_location(self, location):
        """Return the ID of a location (origin URL or local copy path)."""
        # Is location a "~/cylc-run/$SUITE/" directory?
        # Use a hacky way to read the "log/rose-suite-run.version" file
        suite_engine_proc = SuiteEngineProcessor.get_processor()
        suite_dir_rel_root = getattr(suite_engine_proc, "SUITE_DIR_REL_ROOT",
                                     None)
        if suite_dir_rel_root and "/" + suite_dir_rel_root + "/" in location:
            loc = location
            while "/" + suite_dir_rel_root + "/" in loc:
                suite_version_file_name = os.path.join(
                    loc, "log/rose-suite-run.version")
                loc = os.path.dirname(loc)
                if not os.access(suite_version_file_name, os.F_OK | os.R_OK):
                    continue
                state = None
                url = None
                rev = None
                for i, line in enumerate(open(suite_version_file_name)):
                    line = line.strip()
                    if state is None:
                        if line.startswith("# svn info"):
                            state = line
                    elif state.startswith("# svn info"):
                        if line.startswith("URL:"):
                            url = line.split(":", 1)[1].strip()
                        elif line.startswith("Revision:"):
                            rev = line.split(":", 1)[1].strip()
                        elif not line:
                            break
                if url and rev:
                    location = url + "@" + rev
                break

        # Assume location is a Subversion working copy of a Rosie suite
        info_parser = SvnInfoXMLParser()
        try:
            info_entry = info_parser.parse(self.svn("info", "--xml", location))
        except RosePopenError:
            raise SuiteIdLocationError(location)

        if "url" not in info_entry:
            raise SuiteIdLocationError(location)
        root = info_entry["repository:root"]
        url = info_entry["url"]
        path = url[len(root):]
        if not path:
            raise SuiteIdLocationError(location)
        self.prefix = self.get_prefix_from_location_root(root)
        names = path.lstrip("/").split("/", self.SID_LEN + 1)
        if len(names) < self.SID_LEN:
            raise SuiteIdLocationError(location)
        sid = "".join(names[0:self.SID_LEN])
        if not self.REC_IDX.match(sid):
            raise SuiteIdLocationError(location)
        self.idx = self.FORMAT_IDX % (self.prefix, sid)
        self.sid = sid
        if len(names) > self.SID_LEN:
            self.branch = names[self.SID_LEN]
        if "commit:revision" in info_entry:
            self.revision = info_entry["commit:revision"]