def _run_task(self): kwargs = {} if "max" in self.options: kwargs["max"] = self.options["max"] for file_pattern in self.options["file_pattern"]: find_replace(find=self.options["find"], replace=self.options["replace"], directory=self.options["path"], filePattern=file_pattern, logger=self.logger, **kwargs)
def test_find_replace_max(self): with utils.temporary_dir() as d: path = os.path.join(d, "test") with open(path, "w") as f: f.write("aa") logger = mock.Mock() utils.find_replace("a", "b", d, "*", logger, max=1) logger.info.assert_called_once() with open(path, "r") as f: result = f.read() assert result == "ba"
def _run_task(self): kwargs = {} if "max" in self.options: kwargs["max"] = self.options["max"] if self.options["env_replace"]: if self.options["replace"] in os.environ.keys(): self.options["replace"] = os.environ[self.options["replace"]] else: raise TaskOptionsError( f"The environment variable {self.options['replace']} was not found. Ensure that this value is populated or set env_replace to False." ) for file_pattern in self.options["file_pattern"]: find_replace( find=self.options["find"], replace=self.options["replace"], directory=self.options["path"], filePattern=file_pattern, logger=self.logger, **kwargs, )
def _run_task(self): # Check that path exists path = Path(self.options["path"]) if not path.is_dir(): raise TaskOptionsError( f"The path {path} does not exist or is not a directory") # Check that revert_path does not exist revert_path = Path(self.options["revert_path"]) if revert_path.exists(): raise TaskOptionsError( f"The revert_path {self.options['revert_path']} already exists. Delete it and try again" ) # Copy path to revert_path copy_tree(str(path), str(revert_path)) # Edit metadata in path self.logger.info( f"Removing the string {self.managed_token} from {path}/classes and {path}/triggers" ) find_replace( self.managed_token, "", str(path / "classes"), "*.cls", self.logger, ) find_replace( self.managed_token, "", str(path / "triggers"), "*.trigger", self.logger, ) self.logger.info( f"{self.managed_token} has been stripped from all classes and triggers in {path}" )
def _run_task(self): # Check that path exists if not os.path.isdir(self.options["path"]): raise TaskOptionsError( "The path {} does not exist or is not a directory".format( self.options["path"])) # Check that revert_path does not exist if os.path.exists(self.options["revert_path"]): raise TaskOptionsError( "The revert_path {} already exists. Delete it and try again". format(self.options["revert_path"])) # Copy path to revert_path copy_tree(self.options["path"], self.options["revert_path"]) # Edit metadata in path self.logger.info( "Removing the string {0} from {1}/classes and {1}/triggers".format( self.managed_token, self.options["path"])) find_replace( self.managed_token, "", os.path.join(self.options["path"], "classes"), "*.cls", self.logger, ) find_replace( self.managed_token, "", os.path.join(self.options["path"], "triggers"), "*.trigger", self.logger, ) self.logger.info( "{} has been stripped from all classes and triggers in {}".format( self.managed_token, self.options["path"]))