<s> import subprocess <EOL> import logging <EOL> from ajenti . api import * <EOL> from api import PackageInfo , PackageManager <EOL> @ plugin <EOL> @ rootcontext <EOL> @ persistent <EOL> class ArchPackageManager ( PackageManager ) : <EOL> platforms = [ '<STR_LIT>' ] <EOL> def init ( self ) : <EOL> self . upgradeable = [ ] <EOL> self . all = [ ] <EOL> def get_lists ( self ) : <EOL> self . context . launch ( '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> def refresh ( self ) : <EOL> try : <EOL> out_u = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except subprocess . CalledProcessError as cpe : <EOL> out_u = '<STR_LIT>' <EOL> out_a = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . upgradeable = self . _parse_upgradeable ( out_u ) <EOL> self . all = self . _parse_all_installed ( out_a ) <EOL> self . all_dict = dict ( ( x . name , x ) for x in self . all ) <EOL> def search ( self , query ) : <EOL> try : <EOL> out_s = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , query ] ) <EOL> except subprocess . CalledProcessError as cpe : <EOL> self . context . notify ( '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> out_s = '<STR_LIT>' <EOL> r = [ ] <EOL> for l in out_s . split ( '<STR_LIT:\n>' ) : <EOL> s = l . split ( '<STR_LIT:/>' ) <EOL> if len ( s ) == <NUM_LIT:2> and not ( s [ <NUM_LIT:0> ] . startswith ( '<STR_LIT:U+0020>' ) ) : <EOL> sn = s [ <NUM_LIT:1> ] . split ( '<STR_LIT:U+0020>' ) <EOL> p = PackageInfo ( ) <EOL> p . name = sn [ <NUM_LIT:0> ] <EOL> p . state = '<STR_LIT:i>' if subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , p . name ] ) == <NUM_LIT:0> else '<STR_LIT:r>' <EOL> p . version = sn [ <NUM_LIT:1> ] <EOL> r . append ( p ) <EOL> return r <EOL> def do ( self , actions , callback = lambda : <NUM_LIT:0> ) : <EOL> to_install = [ a for a in actions if a . action == '<STR_LIT:i>' ] <EOL> to_remove = [ a for a in actions if a . action == '<STR_LIT:r>' ] <EOL> cmd = '<STR_LIT>' <EOL> if len ( to_install ) > <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( a . name for a in to_install ) <EOL> if len ( to_remove ) > <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' <EOL> if len ( to_remove ) > <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( a . name for a in to_remove ) <EOL> logging . debug ( '<STR_LIT>' % cmd ) <EOL> self . context . launch ( '<STR_LIT>' , command = cmd , callback = callback ) <EOL> def _parse_upgradeable ( self , d ) : <EOL> r = [ ] <EOL> for l in d . split ( '<STR_LIT:\n>' ) : <EOL> s = l . split ( '<STR_LIT:U+0020>' ) <EOL> if len ( s ) == <NUM_LIT:1> : <EOL> continue <EOL> p = PackageInfo ( ) <EOL> p . action = '<STR_LIT:i>' <EOL> p . name = s [ <NUM_LIT:0> ] <EOL> p . version = s [ <NUM_LIT:1> ] <EOL> r . append ( p ) <EOL> return r <EOL> def _parse_all_installed ( self , d ) : <EOL> r = [ ] <EOL> lines = d . splitlines ( ) <EOL> infos = [ '<STR_LIT:\n>' . join ( lines [ i : i + <NUM_LIT:2> ] ) for i in range ( <NUM_LIT:0> , len ( lines ) , <NUM_LIT:2> ) ] <EOL> for info in infos : <EOL> s = info . split ( '<STR_LIT:\n>' ) <EOL> if len ( s ) == <NUM_LIT:0> : <EOL> continue <EOL> package = s [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+0020>' ) <EOL> p = PackageInfo ( ) <EOL> p . state = '<STR_LIT:i>' <EOL> p . name = package [ <NUM_LIT:0> ] <EOL> p . version = package [ <NUM_LIT:1> ] <EOL> s [ <NUM_LIT:1> ] . lstrip ( ) . rstrip ( ) <EOL> p . description = '<STR_LIT:U+0020>' . join ( s [ <NUM_LIT:1> ] ) <EOL> r . append ( p ) <EOL> return r </s>
