diff --git a/src/centpkg/cli.py b/src/centpkg/cli.py index c8c7539..061001b 100755 --- a/src/centpkg/cli.py +++ b/src/centpkg/cli.py @@ -28,6 +28,7 @@ import six.moves.configparser as ConfigParser import json import koji import os +import sys _DEFAULT_API_BASE_URL = 'https://gitlab.com' @@ -157,91 +158,90 @@ class centpkgClient(cliClient): # Overloaded _build def _build(self, sets=None): - # 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: - temp_custom_user_metadata["rhel-target"] = self.args.rhel_target + # Only do rhel-target if we are centpkg, not centpkg-sig + if not os.path.basename(sys.argv[0]).endswith('-sig'): + + # 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: - if divergent_branch: - temp_custom_user_metadata["rhel-target"] = "latest" - elif not divergent_branch and not in_stabilization : - temp_custom_user_metadata["rhel-target"] = "zstream" + 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: + temp_custom_user_metadata["rhel-target"] = self.args.rhel_target else: - self.log.info("We are currently in Stabalization mode") - self.log.info("You must either set the rhel-target (--rhel-target)") - 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} + if divergent_branch: + temp_custom_user_metadata["rhel-target"] = "latest" + elif not divergent_branch and not in_stabilization : + temp_custom_user_metadata["rhel-target"] = "zstream" + else: + self.log.info("We are currently in Stabalization mode") + self.log.info("You must either set the rhel-target (--rhel-target)") + 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 divergent_branch: - self.args.custom_user_metadata = '{"rhel-target": "latest"}' - elif not divergent_branch and not in_stabilization : - self.args.custom_user_metadata = '{"rhel-target": "zstream"}' + 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: - self.log.info("We are currently in Stabalization mode") - self.log.info("You must either set the rhel-target (--rhel-target)") - self.log.info("or branch for the previous version.") - self.log.info("Exiting") - raise SystemExit - - - # Good to know, but take out for final cut - self.log.info(" rhel-target: " + json.loads(self.args.custom_user_metadata)['rhel-target']) - - # Purposely fail during testing so we do not have so many builds - # self.args.custom_user_metadata = json.loads(self.args.custom_user_metadata) - - else: - if not self.args.scratch: - self.log.info("NO SCRATCH BUILD") - self.log.info("Only scratch builds are allowed without internal configurations") - self.log.info("Exiting") - raise SystemExit - + if divergent_branch: + self.args.custom_user_metadata = '{"rhel-target": "latest"}' + elif not divergent_branch and not in_stabilization : + self.args.custom_user_metadata = '{"rhel-target": "zstream"}' + else: + self.log.info("We are currently in Stabalization mode") + self.log.info("You must either set the rhel-target (--rhel-target)") + self.log.info("or branch for the previous version.") + self.log.info("Exiting") + raise SystemExit + + # 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("Only scratch builds are allowed without internal configurations") + self.log.info("Exiting") + raise SystemExit + # Proceed with build return super(centpkgClient, self)._build(sets)