def _from_location(self, location): """Return the ID of a location (origin URL or local copy path).""" # Get Version control file location and convert to a URL if rqd. loc = self._find_vc_file_from_location(location) if loc: location = self._parse_cylc_vc_file(loc) # 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"]
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: raise SuiteIdTextError(location) else: if "commit:revision" in info_entry: revision = int(info_entry["commit:revision"]) return str(self) + self.FORMAT_VERSION % (branch, revision)
def _from_location(self, location): """Return the ID of a location (origin URL or local copy path).""" suite_engine_proc = SuiteEngineProcessor.get_processor() suite_dir_rel_root = getattr(suite_engine_proc, "SUITE_DIR_REL_ROOT", None) # Cylc8 run directory # TODO: extract version control information loc = Path(location) sdrr = Path('~', suite_dir_rel_root).expanduser().resolve() try: loc.relative_to(sdrr) except ValueError: # Not an installed Cylc8 workflow run directory pass else: if (loc / 'rose-suite.info').is_file(): # This is an installed workflow with a rose-suite.info file # (most likely a Cylc8 run directory) # TODO: extract version control information written by # Cylc install, see: # https://github.com/metomi/rose/issues/2432 # https://github.com/cylc/cylc-flow/issues/3849 raise SuiteIdLocationError(location) # Cylc7 run directory # Use a hacky way to read the "log/rose-suite-run.version" file 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 line in 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"]
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 line in 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"]