<s> """<STR_LIT>""" <EOL> import copy <EOL> import os . path <EOL> import sys <EOL> import logging <EOL> import yum <EOL> import yum . packages <EOL> import yum . rpmtrans <EOL> import yum . callbacks <EOL> import yum . Errors <EOL> import yum . misc <EOL> import rpmUtils . arch <EOL> import rpmUtils . miscutils <EOL> import Bcfg2 . Client . XML <EOL> import Bcfg2 . Client . Tools <EOL> import Bcfg2 . Options <EOL> def build_yname ( pkgname , inst ) : <EOL> """<STR_LIT>""" <EOL> rv = { } <EOL> if isinstance ( inst , yum . packages . PackageObject ) : <EOL> for i in [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> rv [ i ] = getattr ( inst , i ) <EOL> else : <EOL> rv [ '<STR_LIT:name>' ] = pkgname <EOL> if inst . get ( '<STR_LIT:version>' ) != '<STR_LIT>' : <EOL> rv [ '<STR_LIT:version>' ] = inst . get ( '<STR_LIT:version>' ) <EOL> if inst . get ( '<STR_LIT>' , False ) : <EOL> rv [ '<STR_LIT>' ] = inst . get ( '<STR_LIT>' ) <EOL> if inst . get ( '<STR_LIT>' , False ) and inst . get ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> rv [ '<STR_LIT>' ] = inst . get ( '<STR_LIT>' ) <EOL> if inst . get ( '<STR_LIT>' , False ) and inst . get ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> rv [ '<STR_LIT>' ] = inst . get ( '<STR_LIT>' ) <EOL> return rv <EOL> def short_yname ( nevra ) : <EOL> """<STR_LIT>""" <EOL> rv = nevra . copy ( ) <EOL> if '<STR_LIT:version>' in rv : <EOL> rv [ '<STR_LIT>' ] = rv [ '<STR_LIT:version>' ] <EOL> del rv [ '<STR_LIT:version>' ] <EOL> if '<STR_LIT>' in rv : <EOL> rv [ '<STR_LIT>' ] = rv [ '<STR_LIT>' ] <EOL> del rv [ '<STR_LIT>' ] <EOL> return rv <EOL> def nevra2string ( pkg ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( pkg , yum . packages . PackageObject ) : <EOL> return str ( pkg ) <EOL> else : <EOL> ret = [ ] <EOL> for attr , fmt in [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:name>' , '<STR_LIT:%s>' ) , ( '<STR_LIT:version>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] : <EOL> if attr in pkg : <EOL> ret . append ( fmt % pkg [ attr ] ) <EOL> return "<STR_LIT>" . join ( ret ) <EOL> class RPMDisplay ( yum . rpmtrans . RPMBaseCallback ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> yum . rpmtrans . RPMBaseCallback . __init__ ( self ) <EOL> self . bcfg2_logger = logging . getLogger ( self . __class__ . __name__ ) <EOL> self . state = None <EOL> self . package = None <EOL> def event ( self , package , action , te_current , te_total , <EOL> ts_current , ts_total ) : <EOL> """<STR_LIT>""" <EOL> if self . package != str ( package ) or action != self . state : <EOL> self . bcfg2_logger . info ( "<STR_LIT>" % ( self . action [ action ] , package ) ) <EOL> self . state = action <EOL> self . package = str ( package ) <EOL> def scriptout ( self , package , msgs ) : <EOL> """<STR_LIT>""" <EOL> if msgs : <EOL> msg = "<STR_LIT>" % ( package , msgs ) <EOL> self . bcfg2_logger . debug ( msg ) <EOL> def errorlog ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> self . bcfg2_logger . error ( msg ) <EOL> class YumDisplay ( yum . callbacks . ProcessTransBaseCallback ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> yum . callbacks . ProcessTransBaseCallback . __init__ ( self ) <EOL> self . logger = logging . getLogger ( self . __class__ . __name__ ) <EOL> class YUM ( Bcfg2 . Client . Tools . PkgTool ) : <EOL> """<STR_LIT>""" <EOL> options = Bcfg2 . Client . Tools . PkgTool . options + [ <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = True , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = True , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = True , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = [ "<STR_LIT>" ] , <EOL> dest = "<STR_LIT>" , type = Bcfg2 . Options . Types . comma_list , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = True , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = True , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = [ ] , <EOL> dest = "<STR_LIT>" , type = Bcfg2 . Options . Types . comma_list , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = [ ] , <EOL> type = Bcfg2 . Options . Types . comma_list , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = [ ] , <EOL> type = Bcfg2 . Options . Types . comma_list , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) ] <EOL> pkgtype = '<STR_LIT>' <EOL> __execs__ = [ ] <EOL> __handles__ = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:ignore>' ) ] <EOL> __req__ = { '<STR_LIT>' : [ '<STR_LIT:type>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:type>' ] } <EOL> conflicts = [ '<STR_LIT>' ] <EOL> def __init__ ( self , config ) : <EOL> self . yumbase = self . _loadYumBase ( ) <EOL> Bcfg2 . Client . Tools . PkgTool . __init__ ( self , config ) <EOL> self . ignores = [ ] <EOL> for struct in config : <EOL> self . ignores . extend ( [ entry . get ( '<STR_LIT:name>' ) <EOL> for entry in struct <EOL> if ( entry . tag == '<STR_LIT>' and <EOL> entry . get ( '<STR_LIT:type>' ) == '<STR_LIT:ignore>' ) ] ) <EOL> self . instance_status = { } <EOL> self . extra_instances = [ ] <EOL> self . modlists = { } <EOL> for struct in config : <EOL> self . __important__ . extend ( <EOL> [ entry . get ( '<STR_LIT:name>' ) <EOL> for entry in struct <EOL> if ( entry . tag == '<STR_LIT>' and <EOL> ( entry . get ( '<STR_LIT:name>' ) . startswith ( '<STR_LIT>' ) or <EOL> entry . get ( '<STR_LIT:name>' ) . startswith ( '<STR_LIT>' ) ) or <EOL> entry . get ( '<STR_LIT:name>' ) == '<STR_LIT>' ) ] ) <EOL> self . yum_avail = dict ( ) <EOL> self . yum_installed = dict ( ) <EOL> self . verify_cache = dict ( ) <EOL> yup = self . yumbase . doPackageLists ( pkgnarrow = '<STR_LIT>' ) <EOL> if hasattr ( self . yumbase . rpmdb , '<STR_LIT>' ) : <EOL> yinst = self . yumbase . rpmdb . pkglist <EOL> else : <EOL> yinst = self . yumbase . rpmdb . getPkgList ( ) <EOL> for dest , source in [ ( self . yum_avail , yup . updates ) , <EOL> ( self . yum_installed , yinst ) ] : <EOL> for pkg in source : <EOL> if dest is self . yum_avail : <EOL> pname = pkg . name <EOL> data = [ ( pkg . arch , ( pkg . epoch , pkg . version , pkg . release ) ) ] <EOL> else : <EOL> pname = pkg [ <NUM_LIT:0> ] <EOL> data = [ ( pkg [ <NUM_LIT:1> ] , ( pkg [ <NUM_LIT:2> ] , pkg [ <NUM_LIT:3> ] , pkg [ <NUM_LIT:4> ] ) ) ] <EOL> if pname in dest : <EOL> dest [ pname ] . update ( data ) <EOL> else : <EOL> dest [ pname ] = dict ( data ) <EOL> self . installonlypkgs = self . yumbase . conf . installonlypkgs <EOL> if '<STR_LIT>' not in self . installonlypkgs : <EOL> self . installonlypkgs . append ( '<STR_LIT>' ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_install_missing ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_pkg_checks ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_pkg_verify ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_fix_version ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_reinstall_broken ) <EOL> self . logger . debug ( "<STR_LIT>" % self . installonlypkgs ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_verify_flags ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_disabled_plugins ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> Bcfg2 . Options . setup . yum_enabled_plugins ) <EOL> def _loadYumBase ( self ) : <EOL> '''<STR_LIT>''' <EOL> rv = yum . YumBase ( ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> logger = self . logger <EOL> else : <EOL> logger = logging . getLogger ( self . name ) <EOL> if Bcfg2 . Options . setup . debug : <EOL> debuglevel = <NUM_LIT:3> <EOL> elif Bcfg2 . Options . setup . verbose : <EOL> debuglevel = <NUM_LIT:2> <EOL> else : <EOL> debuglevel = <NUM_LIT:0> <EOL> if len ( Bcfg2 . Options . setup . yum_disabled_plugins ) > <NUM_LIT:0> : <EOL> rv . preconf . disabled_plugins = Bcfg2 . Options . setup . yum_disabled_plugins <EOL> if len ( Bcfg2 . Options . setup . yum_enabled_plugins ) > <NUM_LIT:0> : <EOL> rv . preconf . enabled_plugins = Bcfg2 . Options . setup . yum_enabled_plugins <EOL> try : <EOL> rv . preconf . debuglevel = debuglevel <EOL> rv . _getConfig ( ) <EOL> except AttributeError : <EOL> rv . _getConfig ( self . yumbase . conf . config_file_path , <EOL> debuglevel = debuglevel ) <EOL> try : <EOL> rv . doConfigSetup ( ) <EOL> rv . doTsSetup ( ) <EOL> rv . doRpmDBSetup ( ) <EOL> except yum . Errors . RepoError : <EOL> logger . error ( "<STR_LIT>" % sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> raise Bcfg2 . Client . Tools . ToolInstantiationError <EOL> except Exception : <EOL> logger . error ( "<STR_LIT>" % sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> raise Bcfg2 . Client . Tools . ToolInstantiationError <EOL> return rv <EOL> def _fixAutoVersion ( self , entry ) : <EOL> """<STR_LIT>""" <EOL> if ( entry . get ( '<STR_LIT:name>' ) not in self . yum_installed and <EOL> entry . get ( '<STR_LIT:name>' ) not in self . yum_avail ) : <EOL> entry . set ( '<STR_LIT:version>' , '<STR_LIT>' ) <EOL> else : <EOL> data = copy . copy ( self . yum_installed [ entry . get ( '<STR_LIT:name>' ) ] ) <EOL> if entry . get ( '<STR_LIT:name>' ) in self . yum_avail : <EOL> data . update ( self . yum_avail [ entry . get ( '<STR_LIT:name>' ) ] ) <EOL> for ( arch , ( epoch , vers , rel ) ) in list ( data . items ( ) ) : <EOL> inst = Bcfg2 . Client . XML . SubElement ( entry , "<STR_LIT>" , <EOL> name = entry . get ( '<STR_LIT:name>' ) , <EOL> version = vers , arch = arch , <EOL> release = rel , epoch = epoch ) <EOL> if '<STR_LIT>' in entry . attrib : <EOL> inst . set ( '<STR_LIT>' , entry . get ( '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in entry . attrib : <EOL> inst . set ( '<STR_LIT>' , entry . get ( '<STR_LIT>' ) ) <EOL> def _buildInstances ( self , entry ) : <EOL> """<STR_LIT>""" <EOL> instances = [ inst for inst in entry <EOL> if inst . tag == '<STR_LIT>' or inst . tag == '<STR_LIT>' ] <EOL> if instances == [ ] : <EOL> instance = Bcfg2 . Client . XML . SubElement ( entry , '<STR_LIT>' ) <EOL> for attrib in list ( entry . attrib . keys ( ) ) : <EOL> instance . attrib [ attrib ] = entry . attrib [ attrib ] <EOL> instances = [ instance ] <EOL> return instances <EOL> def _getGPGKeysAsPackages ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . yumbase . rpmdb , '<STR_LIT>' ) : <EOL> return self . yumbase . rpmdb . returnGPGPubkeyPackages ( ) <EOL> return self . yumbase . rpmdb . searchNevra ( name = '<STR_LIT>' ) <EOL> def missing_attrs ( self , entry ) : <EOL> """<STR_LIT>""" <EOL> missing = Bcfg2 . Client . Tools . PkgTool . missing_attrs ( self , entry ) <EOL> if ( entry . get ( '<STR_LIT:name>' , None ) is None and <EOL> entry . get ( '<STR_LIT>' , None ) is None ) : <EOL> missing += [ '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> return missing <EOL> def _verifyHelper ( self , pkg_obj ) : <EOL> """<STR_LIT>""" <EOL> def verify ( pkg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return pkg . verify ( fast = Bcfg2 . Options . setup . quick ) <EOL> except TypeError : <EOL> return pkg . verify ( ) <EOL> key = ( pkg_obj . name , pkg_obj . epoch , pkg_obj . version , pkg_obj . release , <EOL> pkg_obj . arch ) <EOL> if key in self . verify_cache : <EOL> results = self . verify_cache [ key ] <EOL> else : <EOL> results = verify ( pkg_obj ) <EOL> self . verify_cache [ key ] = results <EOL> if not rpmUtils . arch . isMultiLibArch ( ) : <EOL> return results <EOL> packages = self . yumbase . rpmdb . searchNevra ( name = pkg_obj . name , <EOL> epoch = pkg_obj . epoch , <EOL> ver = pkg_obj . version , <EOL> rel = pkg_obj . release ) <EOL> if len ( packages ) == <NUM_LIT:1> : <EOL> return results <EOL> files = set ( pkg_obj . returnFileEntries ( ) ) <EOL> common = { } <EOL> for pkg in packages : <EOL> if pkg != pkg_obj : <EOL> files = files & set ( pkg . returnFileEntries ( ) ) <EOL> for pkg in packages : <EOL> key = ( pkg . name , pkg . epoch , pkg . version , pkg . release , pkg . arch ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> ( pkg_obj , pkg ) ) <EOL> if key not in self . verify_cache : <EOL> self . verify_cache [ key ] = verify ( pkg ) <EOL> for fname in list ( self . verify_cache [ key ] . keys ( ) ) : <EOL> if fname in files : <EOL> common [ fname ] = common . get ( fname , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> flag = len ( packages ) - <NUM_LIT:1> <EOL> for fname , i in list ( common . items ( ) ) : <EOL> if i == flag : <EOL> if fname in results : <EOL> del results [ fname ] <EOL> return results <EOL> def RefreshPackages ( self ) : <EOL> """<STR_LIT>""" <EOL> self . installed = { } <EOL> packages = self . _getGPGKeysAsPackages ( ) + self . yumbase . rpmdb . returnPackages ( ) <EOL> for pkg in packages : <EOL> pattrs = { } <EOL> for i in [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if i == '<STR_LIT>' and getattr ( pkg , i ) is None : <EOL> pattrs [ i ] = '<STR_LIT>' <EOL> elif i == '<STR_LIT>' and getattr ( pkg , i ) is None : <EOL> pattrs [ i ] = '<STR_LIT:0>' <EOL> else : <EOL> pattrs [ i ] = getattr ( pkg , i ) <EOL> self . installed . setdefault ( pkg . name , [ ] ) . append ( pattrs ) <EOL> def VerifyPackage ( self , entry , modlist ) : <EOL> """<STR_LIT>""" <EOL> if entry . get ( '<STR_LIT:version>' , False ) == '<STR_LIT>' : <EOL> self . _fixAutoVersion ( entry ) <EOL> if entry . get ( '<STR_LIT>' ) : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> entry . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> entry . get ( '<STR_LIT:name>' ) ) <EOL> self . verify_cache = dict ( ) <EOL> self . modlists [ entry ] = modlist <EOL> instances = self . _buildInstances ( entry ) <EOL> pkg_cache = [ ] <EOL> package_fail = False <EOL> qtext_versions = [ ] <EOL> virt_pkg = False <EOL> pkg_checks = ( Bcfg2 . Options . setup . yum_pkg_checks and <EOL> entry . get ( '<STR_LIT>' , '<STR_LIT:true>' ) . lower ( ) == '<STR_LIT:true>' ) <EOL> pkg_verify = ( Bcfg2 . Options . setup . yum_pkg_verify and <EOL> entry . get ( '<STR_LIT>' , '<STR_LIT:true>' ) . lower ( ) == '<STR_LIT:true>' ) <EOL> yum_group = False <EOL> if entry . get ( '<STR_LIT:name>' ) == '<STR_LIT>' : <EOL> all_pkg_objs = self . _getGPGKeysAsPackages ( ) <EOL> pkg_verify = False <EOL> elif entry . get ( '<STR_LIT>' ) : <EOL> entry . set ( '<STR_LIT:name>' , '<STR_LIT>' % entry . get ( '<STR_LIT>' ) ) <EOL> yum_group = True <EOL> all_pkg_objs = [ ] <EOL> instances = [ ] <EOL> if self . yumbase . comps . has_group ( entry . get ( '<STR_LIT>' ) ) : <EOL> group = self . yumbase . comps . return_group ( entry . get ( '<STR_LIT>' ) ) <EOL> group_packages = [ p <EOL> for p , d in group . mandatory_packages . items ( ) <EOL> if d ] <EOL> group_type = entry . get ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> if group_type in [ '<STR_LIT:default>' , '<STR_LIT>' , '<STR_LIT:all>' ] : <EOL> group_packages += [ <EOL> p for p , d in group . default_packages . items ( ) <EOL> if d ] <EOL> if group_type in [ '<STR_LIT>' , '<STR_LIT:all>' ] : <EOL> group_packages += [ <EOL> p for p , d in group . optional_packages . items ( ) <EOL> if d ] <EOL> if len ( group_packages ) == <NUM_LIT:0> : <EOL> self . logger . error ( "<STR_LIT>" % <EOL> entry . get ( "<STR_LIT>" ) ) <EOL> for pkg in group_packages : <EOL> instance = Bcfg2 . Client . XML . SubElement ( entry , '<STR_LIT>' ) <EOL> instance . attrib [ '<STR_LIT:name>' ] = pkg <EOL> instance . attrib [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> try : <EOL> newest = self . yumbase . pkgSack . returnNewestByName ( pkg ) [ <NUM_LIT:0> ] <EOL> instance . attrib [ '<STR_LIT:version>' ] = newest [ '<STR_LIT:version>' ] <EOL> instance . attrib [ '<STR_LIT>' ] = newest [ '<STR_LIT>' ] <EOL> instance . attrib [ '<STR_LIT>' ] = newest [ '<STR_LIT>' ] <EOL> except : <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> pkg ) <EOL> instance . attrib [ '<STR_LIT:version>' ] = '<STR_LIT>' <EOL> instances . append ( instance ) <EOL> else : <EOL> self . logger . error ( "<STR_LIT>" % entry . get ( "<STR_LIT>" ) ) <EOL> else : <EOL> all_pkg_objs = self . yumbase . rpmdb . searchNevra ( name = entry . get ( '<STR_LIT:name>' ) ) <EOL> if len ( all_pkg_objs ) == <NUM_LIT:0> and yum_group is not True : <EOL> all_pkg_objs = self . yumbase . rpmdb . searchProvides ( entry . get ( '<STR_LIT:name>' ) ) <EOL> if len ( all_pkg_objs ) > <NUM_LIT:0> : <EOL> virt_pkg = True <EOL> self . logger . info ( "<STR_LIT>" % <EOL> entry . get ( '<STR_LIT:name>' ) ) <EOL> for pkg in all_pkg_objs : <EOL> self . logger . info ( "<STR_LIT>" % pkg ) <EOL> for inst in instances : <EOL> if yum_group : <EOL> nevra = build_yname ( inst . get ( '<STR_LIT:name>' ) , inst ) <EOL> all_pkg_objs = self . yumbase . rpmdb . searchNevra ( name = inst . get ( '<STR_LIT:name>' ) ) <EOL> else : <EOL> nevra = build_yname ( entry . get ( '<STR_LIT:name>' ) , inst ) <EOL> if nevra in pkg_cache : <EOL> continue <EOL> else : <EOL> pkg_cache . append ( nevra ) <EOL> self . logger . debug ( "<STR_LIT>" % nevra2string ( nevra ) ) <EOL> stat = self . instance_status . setdefault ( inst , { } ) <EOL> stat [ '<STR_LIT>' ] = True <EOL> stat [ '<STR_LIT>' ] = False <EOL> stat [ '<STR_LIT>' ] = { } <EOL> stat [ '<STR_LIT>' ] = False <EOL> if yum_group : <EOL> stat [ '<STR_LIT>' ] = inst <EOL> else : <EOL> stat [ '<STR_LIT>' ] = entry <EOL> stat [ '<STR_LIT>' ] = modlist <EOL> if inst . get ( '<STR_LIT>' ) : <EOL> verify_flags = inst . get ( '<STR_LIT>' ) . lower ( ) . replace ( '<STR_LIT:U+0020>' , <EOL> '<STR_LIT:U+002C>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> else : <EOL> verify_flags = Bcfg2 . Options . setup . yum_verify_flags <EOL> if '<STR_LIT>' in nevra : <EOL> pkg_objs = [ p for p in all_pkg_objs if p . arch == nevra [ '<STR_LIT>' ] ] <EOL> else : <EOL> pkg_objs = all_pkg_objs <EOL> if len ( pkg_objs ) == <NUM_LIT:0> : <EOL> entry . set ( '<STR_LIT>' , '<STR_LIT:false>' ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> nevra2string ( nevra ) ) <EOL> stat [ '<STR_LIT>' ] = False <EOL> package_fail = True <EOL> qtext_versions . append ( "<STR_LIT>" % nevra ) <EOL> continue <EOL> if not pkg_checks : <EOL> continue <EOL> if virt_pkg : <EOL> vlist = [ ] <EOL> for attr in [ "<STR_LIT>" , "<STR_LIT:version>" , "<STR_LIT>" ] : <EOL> vlist . append ( nevra . get ( attr ) ) <EOL> if tuple ( vlist ) == ( None , None , None ) : <EOL> pkg_objs = [ po for po in all_pkg_objs ] <EOL> else : <EOL> pkg_objs = [ po for po in all_pkg_objs <EOL> if po . checkPrco ( '<STR_LIT>' , <EOL> ( nevra [ "<STR_LIT:name>" ] , '<STR_LIT>' , <EOL> tuple ( vlist ) ) ) ] <EOL> elif entry . get ( '<STR_LIT:name>' ) == '<STR_LIT>' : <EOL> if '<STR_LIT:version>' not in nevra : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> continue <EOL> if '<STR_LIT>' not in nevra : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> continue <EOL> pkg_objs = [ p for p in all_pkg_objs <EOL> if ( p . version == nevra [ '<STR_LIT:version>' ] and <EOL> p . release == nevra [ '<STR_LIT>' ] ) ] <EOL> else : <EOL> pkg_objs = self . yumbase . rpmdb . searchNevra ( ** short_yname ( nevra ) ) <EOL> if len ( pkg_objs ) == <NUM_LIT:0> : <EOL> package_fail = True <EOL> stat [ '<STR_LIT>' ] = True <EOL> current_pkg = all_pkg_objs [ <NUM_LIT:0> ] <EOL> if virt_pkg : <EOL> provides = [ p for p in current_pkg . provides <EOL> if p [ <NUM_LIT:0> ] == entry . get ( "<STR_LIT:name>" ) ] [ <NUM_LIT:0> ] <EOL> current_evr = provides [ <NUM_LIT:2> ] <EOL> self . logger . info ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( entry . get ( "<STR_LIT:name>" ) , <EOL> nevra2string ( nevra ) , <EOL> nevra2string ( current_pkg ) , <EOL> yum . misc . prco_tuple_to_string ( provides ) ) ) <EOL> else : <EOL> current_evr = ( current_pkg . epoch , <EOL> current_pkg . version , <EOL> current_pkg . release ) <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( entry . get ( "<STR_LIT:name>" ) , <EOL> nevra2string ( nevra ) , <EOL> nevra2string ( current_pkg ) ) ) <EOL> wanted_evr = ( nevra . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> nevra . get ( '<STR_LIT:version>' , '<STR_LIT>' ) , <EOL> nevra . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> entry . set ( '<STR_LIT>' , "<STR_LIT>" % current_evr ) <EOL> entry . set ( '<STR_LIT:version>' , "<STR_LIT>" % wanted_evr ) <EOL> if rpmUtils . miscutils . compareEVR ( current_evr , wanted_evr ) == <NUM_LIT:1> : <EOL> entry . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> entry . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> qtext_versions . append ( "<STR_LIT>" % str ( all_pkg_objs [ <NUM_LIT:0> ] ) ) <EOL> continue <EOL> if Bcfg2 . Options . setup . quick : <EOL> continue <EOL> if not ( pkg_verify and <EOL> inst . get ( '<STR_LIT>' , '<STR_LIT:true>' ) . lower ( ) == '<STR_LIT:true>' ) : <EOL> continue <EOL> if len ( pkg_objs ) > <NUM_LIT:1> : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> for pkg in pkg_objs : <EOL> self . logger . debug ( "<STR_LIT>" % str ( pkg ) ) <EOL> try : <EOL> vrfy_result = self . _verifyHelper ( pkg_objs [ <NUM_LIT:0> ] ) <EOL> except : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . warning ( "<STR_LIT>" % err ) <EOL> package_fail = True <EOL> continue <EOL> ignores = [ ig . get ( '<STR_LIT:name>' ) for ig in entry . findall ( '<STR_LIT>' ) ] + [ ig . get ( '<STR_LIT:name>' ) for ig in inst . findall ( '<STR_LIT>' ) ] + self . ignores <EOL> for fname , probs in list ( vrfy_result . items ( ) ) : <EOL> if fname in modlist : <EOL> self . logger . debug ( "<STR_LIT>" % fname ) <EOL> continue <EOL> if fname in ignores : <EOL> self . logger . debug ( "<STR_LIT>" % fname ) <EOL> continue <EOL> tmp = [ ] <EOL> for prob in probs : <EOL> if prob . type == '<STR_LIT>' and os . path . islink ( fname ) : <EOL> continue <EOL> elif '<STR_LIT>' + prob . type in verify_flags : <EOL> continue <EOL> if prob . type not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> tmp . append ( ( prob . type , prob . message ) ) <EOL> if tmp != [ ] : <EOL> stat [ '<STR_LIT>' ] [ fname ] = tmp <EOL> if stat [ '<STR_LIT>' ] != { } : <EOL> stat [ '<STR_LIT>' ] = True <EOL> package_fail = True <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . logger . info ( "<STR_LIT>" % <EOL> stat [ '<STR_LIT>' ] . get ( '<STR_LIT:name>' ) ) <EOL> for fname , probs in list ( stat [ '<STR_LIT>' ] . items ( ) ) : <EOL> if len ( probs ) > <NUM_LIT:1> : <EOL> self . logger . info ( "<STR_LIT>" % fname ) <EOL> for prob in probs : <EOL> self . logger . info ( "<STR_LIT>" % prob [ <NUM_LIT:1> ] ) <EOL> else : <EOL> self . logger . info ( "<STR_LIT>" % ( fname , probs [ <NUM_LIT:0> ] ) ) <EOL> if len ( all_pkg_objs ) > <NUM_LIT:0> : <EOL> provides = set ( [ p [ <NUM_LIT:0> ] for p in all_pkg_objs [ <NUM_LIT:0> ] . provides ] + <EOL> [ all_pkg_objs [ <NUM_LIT:0> ] . name ] ) <EOL> install_only = len ( set ( self . installonlypkgs ) & provides ) > <NUM_LIT:0> <EOL> else : <EOL> install_only = False <EOL> if virt_pkg or ( install_only and not Bcfg2 . Options . setup . kevlar ) or yum_group : <EOL> self . extra_instances = None <EOL> else : <EOL> self . extra_instances = self . FindExtraInstances ( entry , all_pkg_objs ) <EOL> if self . extra_instances is not None : <EOL> package_fail = True <EOL> return not package_fail <EOL> def FindExtraInstances ( self , entry , all_pkg_objs ) : <EOL> """<STR_LIT>""" <EOL> if len ( all_pkg_objs ) == <NUM_LIT:0> : <EOL> return None <EOL> name = entry . get ( '<STR_LIT:name>' ) <EOL> extra_entry = Bcfg2 . Client . XML . Element ( '<STR_LIT>' , name = name , <EOL> type = self . pkgtype ) <EOL> instances = self . _buildInstances ( entry ) <EOL> pkg_objs = [ p for p in all_pkg_objs ] <EOL> checked = [ ] <EOL> for inst in instances : <EOL> nevra = build_yname ( name , inst ) <EOL> pkgs = self . yumbase . rpmdb . searchNevra ( ** short_yname ( nevra ) ) <EOL> if len ( pkgs ) > <NUM_LIT:0> : <EOL> if pkgs [ <NUM_LIT:0> ] in checked : <EOL> continue <EOL> else : <EOL> checked . append ( pkgs [ <NUM_LIT:0> ] ) <EOL> pkg_objs . remove ( pkgs [ <NUM_LIT:0> ] ) <EOL> for pkg in pkg_objs : <EOL> self . logger . debug ( "<STR_LIT>" % str ( pkg ) ) <EOL> Bcfg2 . Client . XML . SubElement ( extra_entry , '<STR_LIT>' , <EOL> epoch = pkg . epoch , name = pkg . name , <EOL> version = pkg . version , <EOL> release = pkg . release , arch = pkg . arch ) <EOL> if pkg_objs == [ ] : <EOL> return None <EOL> else : <EOL> return extra_entry <EOL> def FindExtra ( self ) : <EOL> """<STR_LIT>""" <EOL> packages = [ e . get ( '<STR_LIT:name>' ) for e in self . getSupportedEntries ( ) ] <EOL> extras = [ ] <EOL> for pkg in list ( self . installed . keys ( ) ) : <EOL> if pkg not in packages : <EOL> entry = Bcfg2 . Client . XML . Element ( '<STR_LIT>' , name = pkg , <EOL> type = self . pkgtype ) <EOL> for i in self . installed [ pkg ] : <EOL> Bcfg2 . Client . XML . SubElement ( entry , '<STR_LIT>' , <EOL> epoch = i [ '<STR_LIT>' ] , <EOL> version = i [ '<STR_LIT:version>' ] , <EOL> release = i [ '<STR_LIT>' ] , <EOL> arch = i [ '<STR_LIT>' ] ) <EOL> extras . append ( entry ) <EOL> return extras <EOL> def _installGPGKey ( self , inst , key_file ) : <EOL> """<STR_LIT>""" <EOL> tset = self . yumbase . rpmdb . readOnlyTS ( ) <EOL> if not os . path . exists ( key_file ) : <EOL> self . logger . debug ( "<STR_LIT>" % key_file ) <EOL> return False <EOL> rawkey = open ( key_file ) . read ( ) <EOL> gpg = yum . misc . getgpgkeyinfo ( rawkey ) <EOL> ver = yum . misc . keyIdToRPMVer ( gpg [ '<STR_LIT>' ] ) <EOL> rel = yum . misc . keyIdToRPMVer ( gpg [ '<STR_LIT>' ] ) <EOL> if not ( ver == inst . get ( '<STR_LIT:version>' ) and rel == inst . get ( '<STR_LIT>' ) ) : <EOL> self . logger . info ( "<STR_LIT>" <EOL> % ( key_file , inst . get ( '<STR_LIT:version>' ) , <EOL> inst . get ( '<STR_LIT>' ) ) ) <EOL> return False <EOL> if not yum . misc . keyInstalled ( tset , gpg [ '<STR_LIT>' ] , <EOL> gpg [ '<STR_LIT>' ] ) == <NUM_LIT:0> : <EOL> result = tset . pgpImportPubkey ( yum . misc . procgpgkey ( rawkey ) ) <EOL> else : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> ( inst . get ( '<STR_LIT:version>' ) , inst . get ( '<STR_LIT>' ) ) ) <EOL> return True <EOL> if result != <NUM_LIT:0> : <EOL> self . logger . debug ( <EOL> "<STR_LIT>" % <EOL> ( self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) , <EOL> nevra2string ( inst ) ) ) <EOL> return False <EOL> else : <EOL> self . logger . debug ( <EOL> "<STR_LIT>" % <EOL> ( self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) , <EOL> inst . get ( '<STR_LIT:version>' ) , inst . get ( '<STR_LIT>' ) ) ) <EOL> return True <EOL> def _runYumTransaction ( self ) : <EOL> """<STR_LIT>""" <EOL> def cleanup ( ) : <EOL> """<STR_LIT>""" <EOL> self . yumbase . closeRpmDB ( ) <EOL> self . RefreshPackages ( ) <EOL> rpm_display = RPMDisplay ( ) <EOL> yum_display = YumDisplay ( ) <EOL> try : <EOL> rescode , restring = self . yumbase . buildTransaction ( ) <EOL> except yum . Errors . YumBaseError : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % err ) <EOL> cleanup ( ) <EOL> return <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> ( rescode , restring ) ) <EOL> if rescode != <NUM_LIT:1> : <EOL> try : <EOL> self . yumbase . processTransaction ( callback = yum_display , <EOL> rpmDisplay = rpm_display ) <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> except yum . Errors . YumBaseError : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % err ) <EOL> cleanup ( ) <EOL> return <EOL> else : <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> skip_broken = self . yumbase . conf . skip_broken <EOL> self . yumbase . conf . skip_broken = True <EOL> try : <EOL> rescode , restring = self . yumbase . buildTransaction ( ) <EOL> if rescode != <NUM_LIT:1> : <EOL> self . yumbase . processTransaction ( callback = yum_display , <EOL> rpmDisplay = rpm_display ) <EOL> self . logger . debug ( <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" % restring ) <EOL> except yum . Errors . YumBaseError : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % err ) <EOL> self . yumbase . conf . skip_broken = skip_broken <EOL> cleanup ( ) <EOL> def Install ( self , packages ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> states = dict ( ) <EOL> install_pkgs = [ ] <EOL> gpg_keys = [ ] <EOL> upgrade_pkgs = [ ] <EOL> downgrade_pkgs = [ ] <EOL> reinstall_pkgs = [ ] <EOL> def queue_pkg ( pkg , inst , queue ) : <EOL> """<STR_LIT>""" <EOL> if pkg . get ( '<STR_LIT:name>' ) == '<STR_LIT>' : <EOL> gpg_keys . append ( inst ) <EOL> else : <EOL> queue . append ( inst ) <EOL> if self . extra_instances is not None and len ( self . extra_instances ) > <NUM_LIT:0> : <EOL> if Bcfg2 . Options . setup . remove in [ '<STR_LIT:all>' , '<STR_LIT>' ] : <EOL> self . Remove ( self . extra_instances ) <EOL> else : <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for pkg in self . extra_instances : <EOL> for inst in pkg : <EOL> self . logger . info ( "<STR_LIT>" % <EOL> ( ( pkg . get ( '<STR_LIT:name>' ) , <EOL> nevra2string ( inst ) ) ) ) <EOL> for pkg in packages : <EOL> insts = [ pinst for pinst in pkg <EOL> if pinst . tag in [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> if insts : <EOL> for inst in insts : <EOL> if inst not in self . instance_status : <EOL> self . logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> nevra2string ( build_yname ( pkg . get ( '<STR_LIT:name>' ) , inst ) ) ) <EOL> continue <EOL> status = self . instance_status [ inst ] <EOL> if not status . get ( '<STR_LIT>' , False ) and Bcfg2 . Options . setup . yum_install_missing : <EOL> queue_pkg ( pkg , inst , install_pkgs ) <EOL> elif ( status . get ( '<STR_LIT>' , False ) and <EOL> Bcfg2 . Options . setup . yum_fix_version ) : <EOL> if pkg . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> queue_pkg ( pkg , inst , downgrade_pkgs ) <EOL> else : <EOL> queue_pkg ( pkg , inst , upgrade_pkgs ) <EOL> elif ( status . get ( '<STR_LIT>' , False ) and <EOL> Bcfg2 . Options . setup . yum_reinstall_broken ) : <EOL> queue_pkg ( pkg , inst , reinstall_pkgs ) <EOL> else : <EOL> pass <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> self . logger . warning ( msg % pkg . get ( '<STR_LIT:name>' ) ) <EOL> queue_pkg ( pkg , pkg , install_pkgs ) <EOL> if len ( gpg_keys ) > <NUM_LIT:0> : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> for inst in gpg_keys : <EOL> if inst . get ( '<STR_LIT>' ) is None : <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> continue <EOL> key_file = os . path . join ( <EOL> self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) , <EOL> inst . get ( '<STR_LIT>' ) ) <EOL> self . _installGPGKey ( inst , key_file ) <EOL> self . RefreshPackages ( ) <EOL> pkg = self . instance_status [ gpg_keys [ <NUM_LIT:0> ] ] . get ( '<STR_LIT>' ) <EOL> states [ pkg ] = self . VerifyPackage ( pkg , [ ] ) <EOL> self . _loadYumBase ( ) <EOL> if len ( install_pkgs ) > <NUM_LIT:0> : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> for inst in install_pkgs : <EOL> pkg_arg = self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) <EOL> self . logger . debug ( "<STR_LIT>" % pkg_arg ) <EOL> try : <EOL> self . yumbase . install ( ** build_yname ( pkg_arg , inst ) ) <EOL> except yum . Errors . YumBaseError : <EOL> yume = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % <EOL> ( pkg_arg , yume ) ) <EOL> if len ( upgrade_pkgs ) > <NUM_LIT:0> : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> for inst in upgrade_pkgs : <EOL> pkg_arg = self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) <EOL> self . logger . debug ( "<STR_LIT>" % pkg_arg ) <EOL> try : <EOL> self . yumbase . update ( ** build_yname ( pkg_arg , inst ) ) <EOL> except yum . Errors . YumBaseError : <EOL> yume = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % <EOL> ( pkg_arg , yume ) ) <EOL> if len ( downgrade_pkgs ) > <NUM_LIT:0> : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> for inst in downgrade_pkgs : <EOL> pkg_arg = self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) <EOL> self . logger . debug ( "<STR_LIT>" % pkg_arg ) <EOL> try : <EOL> self . yumbase . downgrade ( ** build_yname ( pkg_arg , inst ) ) <EOL> except yum . Errors . YumBaseError : <EOL> yume = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % <EOL> ( pkg_arg , yume ) ) <EOL> if len ( reinstall_pkgs ) > <NUM_LIT:0> : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> for inst in reinstall_pkgs : <EOL> pkg_arg = self . instance_status [ inst ] . get ( '<STR_LIT>' ) . get ( '<STR_LIT:name>' ) <EOL> self . logger . debug ( "<STR_LIT>" % pkg_arg ) <EOL> try : <EOL> self . yumbase . reinstall ( ** build_yname ( pkg_arg , inst ) ) <EOL> except yum . Errors . YumBaseError : <EOL> yume = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % <EOL> ( pkg_arg , yume ) ) <EOL> self . _runYumTransaction ( ) <EOL> if not Bcfg2 . Options . setup . kevlar : <EOL> for pkg_entry in [ p for p in packages if self . canVerify ( p ) ] : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> pkg_entry . get ( '<STR_LIT:name>' ) ) <EOL> states [ pkg_entry ] = self . VerifyPackage ( pkg_entry , <EOL> self . modlists . get ( pkg_entry , [ ] ) ) <EOL> self . modified . extend ( ent for ent in packages if states [ ent ] ) <EOL> return states <EOL> def Remove ( self , packages ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> for pkg in packages : <EOL> for inst in pkg : <EOL> nevra = build_yname ( pkg . get ( '<STR_LIT:name>' ) , inst ) <EOL> if pkg . get ( '<STR_LIT:name>' ) != '<STR_LIT>' : <EOL> self . yumbase . remove ( ** nevra ) <EOL> self . modified . append ( pkg ) <EOL> else : <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( nevra [ '<STR_LIT:name>' ] , nevra [ '<STR_LIT:version>' ] , <EOL> nevra [ '<STR_LIT>' ] ) ) <EOL> self . _runYumTransaction ( ) <EOL> self . extra = self . FindExtra ( ) <EOL> def VerifyPath ( self , entry , _ ) : <EOL> """<STR_LIT>""" <EOL> return True </s>
