<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import os . path <EOL> import re <EOL> import subprocess <EOL> from simian . client import client <EOL> from simian . mac . common import hw <EOL> from simian . mac . munki import pkgs <EOL> from simian . mac . munki import plist <EOL> MUNKI_CONFIG_PLIST = '<STR_LIT>' <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class BaseSimianClient ( object ) : <EOL> """<STR_LIT>""" <EOL> def GetSystemRootCACertChain ( self ) : <EOL> """<STR_LIT>""" <EOL> certs = client . SimianClient . GetSystemRootCACertChain ( self ) <EOL> if certs != '<STR_LIT>' : <EOL> return certs <EOL> try : <EOL> argv = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> logging . debug ( '<STR_LIT>' , argv ) <EOL> p = subprocess . Popen ( <EOL> argv , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> rc = p . wait ( ) <EOL> except OSError : <EOL> return '<STR_LIT>' <EOL> if rc == <NUM_LIT:0> : <EOL> logging . debug ( <EOL> '<STR_LIT>' , len ( stdout ) ) <EOL> return stdout <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _GetSystemProfile ( self ) : <EOL> """<STR_LIT>""" <EOL> sp = hw . SystemProfile ( include_only = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> profile = sp . GetProfile ( ) <EOL> return profile <EOL> class SimianClient ( BaseSimianClient , client . SimianClient ) : <EOL> """<STR_LIT>""" <EOL> def _LoadPackageInfo ( self , filename , description , display_name , catalogs ) : <EOL> """<STR_LIT>""" <EOL> p = pkgs . MunkiPackageInfo ( ) <EOL> try : <EOL> p . CreateFromPackage ( filename , description , display_name , catalogs ) <EOL> except pkgs . Error , e : <EOL> raise client . SimianClientError ( str ( e ) ) <EOL> return p . GetPlist ( ) <EOL> def _IsDiskImageReadOnly ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> argv = [ '<STR_LIT>' , '<STR_LIT>' , filename ] <EOL> p = subprocess . Popen ( <EOL> argv , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> rc = p . wait ( ) <EOL> except OSError , e : <EOL> raise client . SimianClientError ( <EOL> '<STR_LIT>' % ( filename , str ( e ) ) ) <EOL> if rc != <NUM_LIT:0> : <EOL> raise client . SimianClientError ( <EOL> '<STR_LIT>' % ( filename , str ( rc ) , stderr ) ) <EOL> if stdout : <EOL> if re . search ( '<STR_LIT>' , stdout ) : <EOL> return True <EOL> return False <EOL> def _IsPackageUploadNecessary ( self , filename , upload_pkginfo ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> cur_pkginfo = self . GetPackageInfo ( filename ) <EOL> except client . SimianServerError : <EOL> return True <EOL> pkginfo_plist = plist . MunkiPackageInfoPlist ( cur_pkginfo ) <EOL> try : <EOL> pkginfo_plist . Parse ( ) <EOL> except plist . PlistError : <EOL> return True <EOL> pkginfo = pkginfo_plist . GetContents ( ) <EOL> upload_pkginfo = plist . MunkiPackageInfoPlist ( upload_pkginfo ) <EOL> upload_pkginfo . Parse ( ) <EOL> if '<STR_LIT>' in pkginfo : <EOL> cur_sha256_hash = pkginfo [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in pkginfo : <EOL> cur_sha256_hash = pkginfo [ '<STR_LIT>' ] <EOL> else : <EOL> cur_sha256_hash = None <EOL> upload_pkginfo_dict = upload_pkginfo . GetContents ( ) <EOL> if '<STR_LIT>' in upload_pkginfo_dict : <EOL> new_sha256_hash = upload_pkginfo_dict [ '<STR_LIT>' ] <EOL> else : <EOL> new_sha256_hash = upload_pkginfo_dict [ '<STR_LIT>' ] <EOL> return cur_sha256_hash != new_sha256_hash <EOL> def UploadMunkiPackage ( <EOL> self , filename , description , display_name , catalogs , manifests , <EOL> install_types , unattended_install = False , unattended_uninstall = False , <EOL> pkginfo_hooks = None , pkginfo_name = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . _IsDiskImageReadOnly ( filename ) : <EOL> raise client . SimianClientError ( <EOL> '<STR_LIT>' % filename ) <EOL> pkginfo = self . _LoadPackageInfo ( <EOL> filename , description , display_name , catalogs ) <EOL> if unattended_install : <EOL> pkginfo [ '<STR_LIT>' ] = True <EOL> pkginfo [ '<STR_LIT>' ] = True <EOL> if unattended_uninstall : <EOL> pkginfo [ '<STR_LIT>' ] = True <EOL> pkginfo [ '<STR_LIT>' ] = True <EOL> if pkginfo_name : <EOL> pkginfo [ '<STR_LIT:name>' ] = unicode ( pkginfo_name ) <EOL> try : <EOL> pkginfo . Validate ( ) <EOL> except plist . Error , e : <EOL> raise client . SimianClientError ( ( <EOL> '<STR_LIT>' % str ( e ) ) ) <EOL> if pkginfo_hooks : <EOL> changes = False <EOL> for pkginfo_hook in pkginfo_hooks : <EOL> output = pkginfo_hook ( pkginfo ) <EOL> if output is True : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> elif output is False : <EOL> raise client . SimianClientError ( '<STR_LIT>' ) <EOL> else : <EOL> pkginfo = output <EOL> changes = True <EOL> logging . debug ( '<STR_LIT>' ) <EOL> if changes : <EOL> description = pkginfo [ '<STR_LIT:description>' ] <EOL> display_name = pkginfo [ '<STR_LIT>' ] <EOL> catalogs = pkginfo [ '<STR_LIT>' ] <EOL> response , unused_filename , catalogs , manifests = self . UploadPackage ( <EOL> filename , description , display_name , catalogs , manifests , <EOL> install_types , pkginfo . GetXml ( ) ) <EOL> name = pkginfo . GetPackageName ( ) <EOL> if '<STR_LIT>' in pkginfo . GetContents ( ) : <EOL> sha256_hash = pkginfo . GetContents ( ) [ '<STR_LIT>' ] <EOL> size_kbytes = pkginfo . GetContents ( ) [ '<STR_LIT>' ] <EOL> else : <EOL> sha256_hash = pkginfo . GetContents ( ) [ '<STR_LIT>' ] <EOL> size_kbytes = pkginfo . GetContents ( ) [ '<STR_LIT>' ] <EOL> return ( response , filename , name , catalogs , manifests , size_kbytes , <EOL> sha256_hash ) <EOL> class SimianAuthClient ( BaseSimianClient , client . SimianAuthClient ) : <EOL> """<STR_LIT>""" <EOL> def _GetPuppetSslDetails ( self , cert_fname = None , interactive_user = False ) : <EOL> """<STR_LIT>""" <EOL> logging . debug ( '<STR_LIT>' ) <EOL> if not cert_fname : <EOL> try : <EOL> facts = self . GetFacter ( ) <EOL> except client . FacterError : <EOL> facts = { } <EOL> cert_name = facts . get ( '<STR_LIT>' , None ) <EOL> logging . debug ( '<STR_LIT>' , cert_name ) <EOL> if not cert_name : <EOL> logging . warning ( '<STR_LIT>' ) <EOL> cert_fname = '<STR_LIT>' % cert_name <EOL> return super ( SimianAuthClient , self ) . _GetPuppetSslDetails ( <EOL> cert_fname = cert_fname , interactive_user = interactive_user ) </s>
