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 delete(): """CLI function: delete.""" opt_parser = RoseOptionParser(usage='rosie delete [OPTIONS] [--] [ID ...]', description=''' Delete suites. Check the standard working copy location for a checked out suite matching `ID` and remove it if there is no uncommitted change (or if `--force` is specified). Delete the suite directory structure from the HEAD of the central repository matching the `ID`. If no `ID` is specified and `$PWD` is a working copy of a suite, use the `ID` of the suite in the working copy. ''').add_my_options("force_mode", "non_interactive", "local_only") opt_parser.modify_option( 'force_mode', help=("Remove working copies even if there are uncommitted changes." "\nContinue with the next `ID` if delete of a suite fails."), ) opts, args = opt_parser.parse_args() report = Reporter(opts.verbosity - opts.quietness) client = RosieVCClient(event_handler=report, force_mode=opts.force_mode) SuiteId.svn.event_handler = client.event_handler if not args: args.append(SuiteId(location=os.getcwd())) interactive_mode = not opts.non_interactive prompt = PROMPT_DELETE if opts.local_only: prompt = PROMPT_DELETE_LOCAL ret_code = 0 for arg in args: if interactive_mode: try: response = input(prompt % arg) except EOFError: ret_code = 1 continue if response == YES_TO_ALL: interactive_mode = False elif response != YES: ret_code = 1 continue if opts.debug_mode: client.delete(arg, opts.local_only) else: try: client.delete(arg, opts.local_only) except ( LocalCopyStatusError, RosePopenError, SuiteIdPrefixError, ) as exc: client.event_handler(exc) ret_code = 1 if not opts.force_mode: sys.exit(1) if ret_code: sys.exit(ret_code)
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 delete(argv): """CLI function: delete.""" opt_parser = RoseOptionParser().add_my_options( "force_mode", "non_interactive", "local_only" ) opts, args = opt_parser.parse_args(argv) report = Reporter(opts.verbosity - opts.quietness) client = RosieVCClient(event_handler=report, force_mode=opts.force_mode) SuiteId.svn.event_handler = client.event_handler if not args: args.append(SuiteId(location=os.getcwd())) interactive_mode = not opts.non_interactive prompt = PROMPT_DELETE if opts.local_only: prompt = PROMPT_DELETE_LOCAL ret_code = 0 for arg in args: if interactive_mode: try: response = input(prompt % arg) except EOFError: ret_code = 1 continue if response == YES_TO_ALL: interactive_mode = False elif response != YES: ret_code = 1 continue if opts.debug_mode: client.delete(arg, opts.local_only) else: try: client.delete(arg, opts.local_only) except ( LocalCopyStatusError, RosePopenError, SuiteIdPrefixError, ) as exc: client.event_handler(exc) ret_code = 1 if not opts.force_mode: sys.exit(1) if ret_code: sys.exit(ret_code)
def create(): """CLI function: create and copy.""" opt_parser = RoseOptionParser( usage=('rosie create [OPTIONS]' '\n rosie copy [OPTIONS] ID-OF-EXISTING-SUITE'), description=''' rosie create: Create a new suite rosie copy : Create a new suite and copy content from an existing one. Assign a new `ID` and create the directory structure in the central repository for a new suite. The location of the repository for the new suite is determined in order of preference: 1. `--prefix=PREFIX` option 2. prefix of the `ID-OF-EXISTING-SUITE` 3. `[rosie-id]prefix-default` option in the site/user configuration. If `ID-OF-EXISTING-SUITE` is specified, copy items from the existing suite `ID-OF-EXISTING-SUITE` when the suite is created. It is worth noting that revision history of the copied items can only be preserved if `ID-OF-EXISTING-SUITE` is in the same repository of the new suite The syntax of the ID-OF-EXISTING-SUITE is PREFIX-xxNNN[/BRANCH][@REV] (e.g. my-su173, my-su173/trunk, my-su173/trunk@HEAD). If REV is not specified, the last changed revision of the branch is used. If BRANCH is not specified, "trunk" is used. NOTE: ID-OF-EXISTING-SUITE is _not_ a filepath. ''', ) opt_parser.add_my_options( "checkout_mode", "info_file", "meta_suite_mode", "non_interactive", "prefix", "project", ) opts, args = opt_parser.parse_args() verbosity = opts.verbosity - opts.quietness client = RosieVCClient(event_handler=Reporter(verbosity)) SuiteId.svn.event_handler = client.event_handler from_id = None if args: from_id = SuiteId(id_text=args[0]) if from_id.branch is None: from_id.branch = from_id.BRANCH_TRUNK if from_id.revision is None: from_id.revision = from_id.REV_HEAD from_id = SuiteId(id_text=from_id.to_string_with_version()) interactive_mode = not opts.non_interactive if opts.info_file is None: info_config = client.generate_info_config(from_id, opts.prefix, opts.project) if from_id is not None: meta_config = load_meta_config( info_config, directory=None, config_type=metomi.rose.INFO_CONFIG_NAME, error_handler=None, ignore_meta_error=False, ) for node_keys, node in meta_config.walk(no_ignore=True): if isinstance(node.value, dict): continue sect, key = node_keys value = node.value sect = sect.replace("=", "") if key == "copy-mode" and value == "clear": info_config.set([sect], "") if key == "copy-mode" and value == "never": info_config.unset([sect]) info_config = _edit_info_config(opts, client, info_config) else: file_ = opts.info_file if opts.info_file == "-": file_ = sys.stdin info_config = metomi.rose.config.load(file_) info_config = _validate_info_config(opts, client, info_config) if interactive_mode: prefix = opts.prefix if from_id: if not prefix: prefix = from_id.prefix question = PROMPT_COPY % (from_id.to_string_with_version(), prefix) else: if not prefix: prefix = SuiteId.get_prefix_default() question = PROMPT_CREATE % prefix try: response = input(question) except EOFError: sys.exit(1) if response != YES: sys.exit(1) try: id_ = client.create(info_config, from_id, opts.prefix, opts.meta_suite_mode) except (RosePopenError, SuiteIdOverflowError) as exc: client.event_handler(exc) sys.exit(1) if opts.checkout_mode: try: client.checkout(id_) except (FileExistError, RosePopenError) as exc: client.event_handler(exc) sys.exit(1)
def create(self, info_config, from_id=None, prefix=None, meta_suite_mode=False): """Create a suite. info_config -- A metomi.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() metomi.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(argv): """CLI function: create and copy.""" opt_parser = RoseOptionParser() opt_parser.add_my_options("checkout_mode", "info_file", "meta_suite_mode", "non_interactive", "prefix", "project") opts, args = opt_parser.parse_args(argv) verbosity = opts.verbosity - opts.quietness client = RosieVCClient(event_handler=Reporter(verbosity)) SuiteId.svn.event_handler = client.event_handler from_id = None if args: from_id = SuiteId(id_text=args[0]) if from_id.branch is None: from_id.branch = from_id.BRANCH_TRUNK if from_id.revision is None: from_id.revision = from_id.REV_HEAD from_id = SuiteId(id_text=from_id.to_string_with_version()) interactive_mode = not opts.non_interactive if opts.info_file is None: info_config = client.generate_info_config(from_id, opts.prefix, opts.project) if from_id is not None: meta_config = load_meta_config( info_config, directory=None, config_type=metomi.rose.INFO_CONFIG_NAME, error_handler=None, ignore_meta_error=False) for node_keys, node in meta_config.walk(no_ignore=True): if isinstance(node.value, dict): continue sect, key = node_keys value = node.value sect = sect.replace("=", "") if key == "copy-mode" and value == "clear": info_config.set([sect], "") if key == "copy-mode" and value == "never": info_config.unset([sect]) info_config = _edit_info_config(opts, client, info_config) else: file_ = opts.info_file if opts.info_file == "-": file_ = sys.stdin info_config = metomi.rose.config.load(file_) info_config = _validate_info_config(opts, client, info_config) if interactive_mode: prefix = opts.prefix if from_id: if not prefix: prefix = from_id.prefix question = PROMPT_COPY % (from_id.to_string_with_version(), prefix) else: if not prefix: prefix = SuiteId.get_prefix_default() question = PROMPT_CREATE % prefix try: response = input(question) except EOFError: sys.exit(1) if response != YES: sys.exit(1) try: id_ = client.create(info_config, from_id, opts.prefix, opts.meta_suite_mode) except (RosePopenError, SuiteIdOverflowError) as exc: client.event_handler(exc) sys.exit(1) if opts.checkout_mode: try: client.checkout(id_) except (FileExistError, RosePopenError) as exc: client.event_handler(exc) sys.exit(1)