<s> """<STR_LIT>""" <EOL> import apt <EOL> import apt_pkg <EOL> import sys <EOL> import subprocess <EOL> from ee . core . logging import Log <EOL> from ee . core . apt_repo import EERepo <EOL> from sh import apt_get <EOL> from sh import ErrorReturnCode <EOL> class EEAptGet ( ) : <EOL> """<STR_LIT>""" <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:a>' ) as f : <EOL> proc = subprocess . Popen ( '<STR_LIT>' , <EOL> shell = True , <EOL> stdin = None , stdout = f , <EOL> stderr = subprocess . PIPE , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> output , error_output = proc . communicate ( ) <EOL> if "<STR_LIT>" in str ( error_output ) : <EOL> Log . info ( self , "<STR_LIT>" ) <EOL> error_list = str ( error_output ) . split ( "<STR_LIT>" ) <EOL> for single_error in error_list : <EOL> if "<STR_LIT>" in single_error : <EOL> key = single_error . rsplit ( None , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> EERepo . add_key ( self , key , keyserver = "<STR_LIT>" ) <EOL> proc = subprocess . Popen ( '<STR_LIT>' , <EOL> shell = True , <EOL> stdin = None , stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> Log . info ( self , Log . FAIL + "<STR_LIT>" ) <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception as e : <EOL> Log . error ( self , "<STR_LIT>" ) <EOL> def check_upgrade ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> check_update = subprocess . Popen ( [ '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> shell = True ) . communicate ( ) [ <NUM_LIT:0> ] <EOL> if check_update == b'<STR_LIT>' : <EOL> Log . error ( self , "<STR_LIT>" ) <EOL> Log . info ( self , "<STR_LIT>" ) <EOL> subprocess . Popen ( "<STR_LIT>" , <EOL> shell = True , executable = "<STR_LIT>" , <EOL> stdout = sys . stdout ) . communicate ( ) <EOL> except Exception as e : <EOL> Log . error ( self , "<STR_LIT>" ) <EOL> def dist_upgrade ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:a>' ) as f : <EOL> proc = subprocess . Popen ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> shell = True , stdin = None , <EOL> stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> Log . info ( self , Log . FAIL + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception as e : <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def install ( self , packages ) : <EOL> all_packages = '<STR_LIT:U+0020>' . join ( packages ) <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:a>' ) as f : <EOL> proc = subprocess . Popen ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( all_packages ) , shell = True , <EOL> stdin = None , stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> Log . info ( self , Log . FAIL + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception as e : <EOL> Log . info ( self , Log . FAIL + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def remove ( self , packages , auto = False , purge = False ) : <EOL> all_packages = '<STR_LIT:U+0020>' . join ( packages ) <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:a>' ) as f : <EOL> if purge : <EOL> proc = subprocess . Popen ( '<STR_LIT>' <EOL> . format ( all_packages ) , shell = True , <EOL> stdin = None , stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> else : <EOL> proc = subprocess . Popen ( '<STR_LIT>' <EOL> . format ( all_packages ) , shell = True , <EOL> stdin = None , stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> Log . info ( self , Log . FAIL + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception as e : <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def auto_clean ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> orig_out = sys . stdout <EOL> sys . stdout = open ( self . app . config . get ( '<STR_LIT>' , '<STR_LIT:file>' ) , <EOL> encoding = '<STR_LIT:utf-8>' , mode = '<STR_LIT:a>' ) <EOL> apt_get . autoclean ( "<STR_LIT>" ) <EOL> sys . stdout = orig_out <EOL> except ErrorReturnCode as e : <EOL> Log . debug ( self , "<STR_LIT>" . format ( e ) ) <EOL> Log . error ( self , "<STR_LIT>" ) <EOL> def auto_remove ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> Log . debug ( self , "<STR_LIT>" ) <EOL> apt_get . autoremove ( "<STR_LIT>" ) <EOL> except ErrorReturnCode as e : <EOL> Log . debug ( self , "<STR_LIT>" . format ( e ) ) <EOL> Log . error ( self , "<STR_LIT>" ) <EOL> def is_installed ( self , package_name ) : <EOL> """<STR_LIT>""" <EOL> apt_cache = apt . cache . Cache ( ) <EOL> apt_cache . open ( ) <EOL> if ( package_name . strip ( ) in apt_cache and <EOL> apt_cache [ package_name . strip ( ) ] . is_installed ) : <EOL> return True <EOL> return False <EOL> def download_only ( self , package_name , repo_url = None , repo_key = None ) : <EOL> """<STR_LIT>""" <EOL> packages = '<STR_LIT:U+0020>' . join ( package_name ) <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:a>' ) as f : <EOL> if repo_url is not None : <EOL> EERepo . add ( self , repo_url = repo_url ) <EOL> if repo_key is not None : <EOL> EERepo . add_key ( self , repo_key ) <EOL> proc = subprocess . Popen ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( packages ) , shell = True , <EOL> stdin = None , stdout = f , stderr = f , <EOL> executable = "<STR_LIT>" ) <EOL> proc . wait ( ) <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> Log . error ( self , "<STR_LIT>" , False ) <EOL> if repo_url is not None : <EOL> EERepo . remove ( self , repo_url = repo_url ) <EOL> return False <EOL> except Exception as e : <EOL> Log . error ( self , "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
