<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import json <EOL> import os <EOL> from osbs . api import OSBS <EOL> from osbs . conf import Configuration <EOL> from osbs . exceptions import OsbsResponseException <EOL> from atomic_reactor . plugin import PreBuildPlugin <EOL> from atomic_reactor . util import get_build_json <EOL> def is_rebuild ( workflow ) : <EOL> return ( CheckAndSetRebuildPlugin . key in workflow . prebuild_results and <EOL> workflow . prebuild_results [ CheckAndSetRebuildPlugin . key ] ) <EOL> class CheckAndSetRebuildPlugin ( PreBuildPlugin ) : <EOL> """<STR_LIT>""" <EOL> key = "<STR_LIT>" <EOL> is_allowed_to_fail = False <EOL> def __init__ ( self , tasker , workflow , label_key , label_value , <EOL> url , verify_ssl = True , use_auth = True ) : <EOL> """<STR_LIT>""" <EOL> super ( CheckAndSetRebuildPlugin , self ) . __init__ ( tasker , workflow ) <EOL> self . label_key = label_key <EOL> self . label_value = label_value <EOL> self . url = url <EOL> self . verify_ssl = verify_ssl <EOL> self . use_auth = use_auth <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = get_build_json ( ) . get ( "<STR_LIT>" , { } ) <EOL> labels = metadata . get ( "<STR_LIT>" , { } ) <EOL> buildconfig = labels [ "<STR_LIT>" ] <EOL> is_rebuild = labels . get ( self . label_key ) == self . label_value <EOL> self . log . info ( "<STR_LIT>" , is_rebuild ) <EOL> if not is_rebuild : <EOL> osbs_conf = Configuration ( conf_file = None , openshift_uri = self . url , <EOL> openshift_url = self . url , <EOL> use_auth = self . use_auth , <EOL> verify_ssl = self . verify_ssl , <EOL> namespace = metadata . get ( '<STR_LIT>' , None ) ) <EOL> osbs = OSBS ( osbs_conf , osbs_conf ) <EOL> labels = { self . label_key : self . label_value } <EOL> try : <EOL> osbs . set_labels_on_build_config ( buildconfig , labels ) <EOL> except OsbsResponseException as ex : <EOL> if ex . status_code == <NUM_LIT> : <EOL> self . log . debug ( "<STR_LIT>" , ex . status_code ) <EOL> osbs . set_labels_on_build_config ( buildconfig , labels ) <EOL> else : <EOL> raise <EOL> return is_rebuild </s>
