From f6364cdcd182212b6fbfcf668f2ac9f0d9ab1c67 Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Mar 14 2023 15:23:35 +0000 Subject: Better messages. Do not check if not needed. Signed-off-by: Troy Dawson --- diff --git a/src/centpkg/cli.py b/src/centpkg/cli.py index 061001b..5ef3f19 100755 --- a/src/centpkg/cli.py +++ b/src/centpkg/cli.py @@ -164,47 +164,62 @@ class centpkgClient(cliClient): # Only run if we have internal configuraions, or scratch internal_config_file = "/etc/rpkg/centpkg_internal.conf" if os.path.exists(internal_config_file): - # Get our internal only variables - cfg = ConfigParser.SafeConfigParser() - cfg.read(internal_config_file) - pp_api_url = config_get_safely(cfg, "centpkg.internal", 'pp_api_url') - gitbz_query_url = config_get_safely(cfg, "centpkg.internal", 'gitbz_query_url') - rhel_dist_git = config_get_safely(cfg, "centpkg.internal", 'rhel_dist_git') - - # Find out divergent branch and stabalization - self.log.info("Checking rhel-target information:") - stream_version = self.cmd.target.split('-')[0] - rhel_version = centpkg.utils.stream_mapping(stream_version) - active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url) - divergent_branch = centpkg.utils.does_divergent_branch_exist( - self.cmd.repo_name, - rhel_version, - rhel_dist_git, - pp_api_url, - "rpms") - - # Good to know - if divergent_branch : - self.log.info(" a divergent branch was found.") - else: - self.log.info(" a divergent branch was not found.") - if in_stabilization : - self.log.info(" we are in stabilization mode.") - else: - self.log.info(" we are not in stabilization mode.") - - # Update args.custom_user_metadata - if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata: - try: - temp_custom_user_metadata = json.loads(self.args.custom_user_metadata) - # Use ValueError instead of json.JSONDecodeError for Python 2 and 3 compatibility - except ValueError as e: - self.parser.error("--custom-user-metadata is not valid JSON: %s" % e) - if not isinstance(temp_custom_user_metadata, dict): - self.parser.error("--custom-user-metadata must be a JSON object") - if hasattr(self.args, 'rhel_target') and self.args.rhel_target: + + # If rhel-target is set, no need to check, just use it + if hasattr(self.args, 'rhel_target') and self.args.rhel_target: + # If custom-user-metadata set, add onto it + if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata: + try: + temp_custom_user_metadata = json.loads(self.args.custom_user_metadata) + # Use ValueError instead of json.JSONDecodeError for Python 2 and 3 compatibility + except ValueError as e: + self.parser.error("--custom-user-metadata is not valid JSON: %s" % e) + if not isinstance(temp_custom_user_metadata, dict): + self.parser.error("--custom-user-metadata must be a JSON object") temp_custom_user_metadata["rhel-target"] = self.args.rhel_target else: + temp_custom_user_metadata = {"rhel-target": self.args.rhel_target} + self.args.custom_user_metadata = json.dumps(temp_custom_user_metadata) + + else: + # Get our internal only variables + cfg = ConfigParser.SafeConfigParser() + cfg.read(internal_config_file) + pp_api_url = config_get_safely(cfg, "centpkg.internal", 'pp_api_url') + gitbz_query_url = config_get_safely(cfg, "centpkg.internal", 'gitbz_query_url') + rhel_dist_git = config_get_safely(cfg, "centpkg.internal", 'rhel_dist_git') + + # Find out divergent branch and stabalization + self.log.info("Checking rhel-target information:") + stream_version = self.cmd.target.split('-')[0] + rhel_version = centpkg.utils.stream_mapping(stream_version) + active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url) + divergent_branch = centpkg.utils.does_divergent_branch_exist( + self.cmd.repo_name, + rhel_version, + rhel_dist_git, + pp_api_url, + "rpms") + + # Good to know + if divergent_branch : + self.log.info(" a divergent branch was found.") + else: + self.log.info(" a divergent branch was not found.") + if in_stabilization : + self.log.info(" we are in stabilization mode.") + else: + self.log.info(" we are not in stabilization mode.") + + # Update args.custom_user_metadata + if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata: + try: + temp_custom_user_metadata = json.loads(self.args.custom_user_metadata) + # Use ValueError instead of json.JSONDecodeError for Python 2 and 3 compatibility + except ValueError as e: + self.parser.error("--custom-user-metadata is not valid JSON: %s" % e) + if not isinstance(temp_custom_user_metadata, dict): + self.parser.error("--custom-user-metadata must be a JSON object") if divergent_branch: temp_custom_user_metadata["rhel-target"] = "latest" elif not divergent_branch and not in_stabilization : @@ -215,10 +230,6 @@ class centpkgClient(cliClient): self.log.info("or branch for the previous version.") self.log.info("Exiting") raise SystemExit - self.args.custom_user_metadata = json.dumps(temp_custom_user_metadata) - else: - if hasattr(self.args, 'rhel_target') and self.args.rhel_target: - temp_custom_user_metadata = {"rhel-target": self.args.rhel_target} self.args.custom_user_metadata = json.dumps(temp_custom_user_metadata) else: if divergent_branch: @@ -232,13 +243,14 @@ class centpkgClient(cliClient): self.log.info("Exiting") raise SystemExit - # Good to know - self.log.info(" rhel-target: " + json.loads(self.args.custom_user_metadata)['rhel-target']) + # Good to know + self.log.info(" rhel-target: " + json.loads(self.args.custom_user_metadata)['rhel-target']) else: if not self.args.scratch: - self.log.info("NO SCRATCH BUILD") + self.log.info("NO INTERNAL CONFIGURATION") self.log.info("Only scratch builds are allowed without internal configurations") + self.log.info("Hint: Install the rhel-packager package from https://download.devel.redhat.com/rel-eng/RCMTOOLS/latest-RCMTOOLS-2-RHEL-9/compose/BaseOS/x86_64/os/Packages/ if you want to build the package via internal (Red Hat) configuration.") self.log.info("Exiting") raise SystemExit