Add rhel-target none option

Signed-off-by: Troy Dawson <tdawson@redhat.com>
This commit is contained in:
Troy Dawson 2023-09-07 09:36:01 -07:00
parent 790841602b
commit e25a639d57

View file

@ -202,40 +202,43 @@ class centpkgClient(cliClient):
* zstream - If pre-GA of a y-stream release, this will build for 0day. * zstream - If pre-GA of a y-stream release, this will build for 0day.
If post-GA of a Y-stream release, this will build for the Z-stream of that release. If post-GA of a Y-stream release, this will build for the Z-stream of that release.
* latest - This will always build for the next Y-stream release * latest - This will always build for the next Y-stream release
* none - This will not build in brew. No rhel metadata is set.
'''.format('\n'.join(textwrap.wrap(build_parser.description)))) '''.format('\n'.join(textwrap.wrap(build_parser.description))))
# Now add our additional option # Now add our additional option
build_parser.add_argument( build_parser.add_argument(
'--rhel-target', '--rhel-target',
choices=['exception', 'zstream', 'latest'], choices=['exception', 'zstream', 'latest', 'none'],
help='Set the rhel-target metadata') help='Set the rhel-target metadata')
# Overloaded _build # Overloaded _build
def _build(self, sets=None): def _build(self, sets=None):
# Only do rhel-target if we are centpkg, not centpkg-sig # Only do rhel-target if we are centpkg, not centpkg-sig, or if we are doing scratch
if not os.path.basename(sys.argv[0]).endswith('-sig') and not self.args.scratch: if not os.path.basename(sys.argv[0]).endswith('-sig') and not self.args.scratch:
# Only run if we have internal configuraions, or scratch # Only run if we have internal configuraions
internal_config_file = "/etc/rpkg/centpkg_internal.conf" internal_config_file = "/etc/rpkg/centpkg_internal.conf"
if os.path.exists(internal_config_file): if os.path.exists(internal_config_file):
# If rhel-target is set, no need to check, just use it # If rhel-target is set, no need to check, just use it
if hasattr(self.args, 'rhel_target') and self.args.rhel_target: if hasattr(self.args, 'rhel_target') and self.args.rhel_target:
# If custom-user-metadata set, add onto it # If rhel-target set to none, do nothing with metadata
if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata: if self.args.rhel_target.lower() != "none":
try: # If custom-user-metadata set, add onto it
temp_custom_user_metadata = json.loads(self.args.custom_user_metadata) if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata:
# Use ValueError instead of json.JSONDecodeError for Python 2 and 3 compatibility try:
except ValueError as e: temp_custom_user_metadata = json.loads(self.args.custom_user_metadata)
self.parser.error("--custom-user-metadata is not valid JSON: %s" % e) # Use ValueError instead of json.JSONDecodeError for Python 2 and 3 compatibility
if not isinstance(temp_custom_user_metadata, dict): except ValueError as e:
self.parser.error("--custom-user-metadata must be a JSON object") self.parser.error("--custom-user-metadata is not valid JSON: %s" % e)
temp_custom_user_metadata["rhel-target"] = self.args.rhel_target if not isinstance(temp_custom_user_metadata, dict):
else: self.parser.error("--custom-user-metadata must be a JSON object")
temp_custom_user_metadata = {"rhel-target": 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:
temp_custom_user_metadata = {"rhel-target": self.args.rhel_target}
self.args.custom_user_metadata = json.dumps(temp_custom_user_metadata)
else: else:
# Get our internal only variables # Get our internal only variables