def delete(self, id_, local_only=False): """Delete the local copy and the origin of a suite. It takes the suite ID as an argument. Return the SuiteId of the suite on success. """ if isinstance(id_, str): id_ = SuiteId(id_text=id_) local_copy = id_.to_local_copy() if os.path.exists(local_copy): if not self.force_mode: status = self.popen("svn", "status", local_copy)[0] if status: raise LocalCopyStatusError(id_, status) if os.getcwd() == local_copy: self.fs_util.chdir(os.path.expanduser("~")) self.fs_util.delete(local_copy) if not local_only: self.popen( "svn", "delete", "-q", "-m", self.COMMIT_MESSAGE_DELETE % str(id_), id_.to_origin()) self.event_handler(SuiteDeleteEvent(id_)) return id_
def checkout(self, id_): """Create a local copy of a suite with the given ID. Return the SuiteId of the suite on success. """ if isinstance(id_, str): id_ = SuiteId(id_text=id_) if id_.revision is None: id_.revision = id_.REV_HEAD if id_.branch is None: id_.branch = id_.BRANCH_TRUNK local_copy = id_.to_local_copy() if os.path.exists(local_copy): id0 = SuiteId(location=local_copy) if id_.to_string_with_version() == id0.to_string_with_version(): self.event_handler(LocalCopyCreateSkipEvent(id_)) return id_ elif self.force_mode: self.fs_util.delete(local_copy) else: raise FileExistError(local_copy) local_copy_dir = os.path.dirname(local_copy) if not os.path.isdir(local_copy_dir): self.fs_util.makedirs(os.path.dirname(local_copy)) origin = "%s/%s@%s" % (id_.to_origin(), id_.branch, id_.revision) self.popen("svn", "checkout", "-q", origin, local_copy) self.event_handler(LocalCopyCreateEvent(id_)) return id_
def checkout(self, id): """Create a local copy of a suite with the given ID. Return the SuiteId of the suite on success. """ if isinstance(id, str): id = SuiteId(id_text=id) if id.revision is None: id.revision = id.REV_HEAD if id.branch is None: id.branch = id.BRANCH_TRUNK local_copy = id.to_local_copy() if os.path.exists(local_copy): id0 = SuiteId(location=local_copy) if id.to_string_with_version() == id0.to_string_with_version(): self.event_handler(LocalCopyCreateSkipEvent(id)) return id elif self.force_mode: if os.path.isfile(local_copy): unlink(local_copy) else: shutil.rmtree(local_copy) self.event_handler(FileDeleteEvent(local_copy)) else: raise FileExistError(local_copy) local_copy_dir = os.path.dirname(local_copy) if not os.path.isdir(local_copy_dir): os.makedirs(os.path.dirname(local_copy)) self.event_handler(FileCreateEvent(local_copy_dir)) origin = id.to_origin() + "/" + id.branch + "@" + id.revision self.popen("svn", "checkout", "-q", origin, local_copy) self.event_handler(LocalCopyCreateEvent(id)) return id
def delete(self, id, local_only=False): """Delete the local copy and the origin of a suite. It takes the suite ID as an argument. Return the SuiteId of the suite on success. """ if isinstance(id, str): id = SuiteId(id_text=id) local_copy = id.to_local_copy() if os.path.exists(local_copy): if not self.force_mode: status = self.popen("svn", "status", local_copy)[0] if status: raise LocalCopyStatusError(id, status) if os.getcwd() == local_copy: # TODO: Event? os.chdir(os.path.expanduser("~")) shutil.rmtree(local_copy) self.event_handler(FileDeleteEvent(local_copy)) if not local_only: self.popen("svn", "delete", "-q", "-m", "%s: deleted." % str(id), id.to_origin()) self.event_handler(SuiteDeleteEvent(id)) return id
def create(self, info_config, from_id=None, prefix=None, meta_suite_mode=False): """Create a suite. info_config -- A rose.config.ConfigNode object, which will be used as the content of the "rose-suite.info" file of the new suite. from_id -- If defined, copy items from it. prefix -- If defined, create the suite in the suite repository named by the prefix instead of the default one. meta_suite_mode -- If True, create the special metadata suite. Ignored if from_id is not None. Return the SuiteId of the suite on success. """ for key in ["owner", "project", "title"]: if not info_config.get([key], no_ignore=True): raise SuiteInfoFieldError(key) if from_id is not None: return self._copy(info_config, from_id) new_id = None while new_id is None: if meta_suite_mode: if prefix is None: new_id = SuiteId(id_text="ROSIE") else: idx = SuiteId.FORMAT_IDX % (prefix, "ROSIE") new_id = SuiteId(id_text=idx) else: new_id = SuiteId.get_next(prefix) new_origin = new_id.to_origin() + "/" + new_id.BRANCH_TRUNK dir = self._get_work_dir() rose.config.dump(info_config, os.path.join(dir, "rose-suite.info")) open(os.path.join(dir, "rose-suite.conf"), "w").close() try: self.popen("svn", "import", "-q", "-m", "%s: new suite." % str(new_id), dir, new_origin) self.event_handler(SuiteCreateEvent(new_id)) except RosePopenError as e: try: self.popen("svn", "info", new_origin) if not meta_suite_mode: new_id = None except RosePopenError: raise e finally: self._delete_work_dir() return new_id
def create(self, info_config, from_id=None, prefix=None, meta_suite_mode=False): """Create a suite. info_config -- A rose.config.ConfigNode object, which will be used as the content of the "rose-suite.info" file of the new suite. from_id -- If defined, copy items from it. prefix -- If defined, create the suite in the suite repository named by the prefix instead of the default one. meta_suite_mode -- If True, create the special metadata suite. Ignored if from_id is not None. Return the SuiteId of the suite on success. """ if from_id is not None and (not prefix or from_id.prefix == prefix): return self._copy1(info_config, from_id) dir_ = self._get_work_dir() try: # Create a temporary suite in the file system if from_id: from_id_url = "%s/%s@%s" % ( from_id.to_origin(), from_id.branch, from_id.revision) self.popen("svn", "export", "-q", "--force", from_id_url, dir_) else: open(os.path.join(dir_, "rose-suite.conf"), "w").close() rose.config.dump( info_config, os.path.join(dir_, "rose-suite.info")) # Attempt to import the temporary suite to the repository new_id = None while new_id is None: if meta_suite_mode: if prefix is None: new_id = SuiteId(id_text="ROSIE") else: idx = SuiteId.FORMAT_IDX % (prefix, "ROSIE") new_id = SuiteId(id_text=idx) else: new_id = SuiteId.get_next(prefix) new_origin = new_id.to_origin() + "/" + new_id.BRANCH_TRUNK try: if from_id: message = self.COMMIT_MESSAGE_COPY % ( new_id, from_id.to_string_with_version()) else: message = self.COMMIT_MESSAGE_CREATE % str(new_id) self.popen( "svn", "import", "-q", "-m", message, dir_, new_origin) self.event_handler(SuiteCreateEvent(new_id)) if from_id: self.event_handler(SuiteCopyEvent(new_id, from_id)) except RosePopenError as exc: try: self.popen("svn", "info", new_origin) if not meta_suite_mode: new_id = None except RosePopenError: raise exc return new_id finally: self._delete_work_dir()
def create(self, info_config, from_id=None, prefix=None, meta_suite_mode=False): """Create a suite. info_config -- A rose.config.ConfigNode object, which will be used as the content of the "rose-suite.info" file of the new suite. from_id -- If defined, copy items from it. prefix -- If defined, create the suite in the suite repository named by the prefix instead of the default one. meta_suite_mode -- If True, create the special metadata suite. Ignored if from_id is not None. Return the SuiteId of the suite on success. """ if from_id is not None and (not prefix or from_id.prefix == prefix): return self._copy1(info_config, from_id) dir_ = self._get_work_dir() try: # Create a temporary suite in the file system if from_id: from_id_url = "%s/%s@%s" % (from_id.to_origin(), from_id.branch, from_id.revision) self.popen("svn", "export", "-q", "--force", from_id_url, dir_) else: open(os.path.join(dir_, "rose-suite.conf"), "w").close() rose.config.dump(info_config, os.path.join(dir_, "rose-suite.info")) # Attempt to import the temporary suite to the repository new_id = None while new_id is None: if meta_suite_mode: if prefix is None: new_id = SuiteId(id_text="ROSIE") else: idx = SuiteId.FORMAT_IDX % (prefix, "ROSIE") new_id = SuiteId(id_text=idx) else: new_id = SuiteId.get_next(prefix) new_origin = new_id.to_origin() + "/" + new_id.BRANCH_TRUNK try: if from_id: message = self.COMMIT_MESSAGE_COPY % ( new_id, from_id.to_string_with_version()) else: message = self.COMMIT_MESSAGE_CREATE % str(new_id) self.popen("svn", "import", "-q", "-m", message, dir_, new_origin) self.event_handler(SuiteCreateEvent(new_id)) if from_id: self.event_handler(SuiteCopyEvent(new_id, from_id)) except RosePopenError as exc: try: self.popen("svn", "info", new_origin) if not meta_suite_mode: new_id = None except RosePopenError: raise exc return new_id finally: self._delete_work_dir()