<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import portage <EOL> import qisys <EOL> from qitoolchain . binary_package . gentoo import GentooPackage as GentooNoPortagePackage <EOL> _ARCH_VARIANT = r'<STR_LIT>' <EOL> _RE_ARCH_VARIANT = re . compile ( _ARCH_VARIANT ) <EOL> _DEPENDENCY = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def _get_pkg_arch ( metadata_dir ) : <EOL> """<STR_LIT>""" <EOL> def _parse_march ( flags_file ) : <EOL> value = None <EOL> with open ( flags_file , '<STR_LIT:r>' ) as fcflags : <EOL> cflags = fcflags . read ( ) <EOL> match = _RE_ARCH_VARIANT . search ( cflags ) <EOL> if match is not None : <EOL> value = match . group ( <NUM_LIT:2> ) <EOL> return value <EOL> with open ( os . path . join ( metadata_dir , '<STR_LIT>' ) , '<STR_LIT:r>' ) as fchost : <EOL> arch = fchost . readline ( ) . strip ( ) . split ( '<STR_LIT:->' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> variant = None <EOL> for flag_file in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> variant = _parse_march ( os . path . join ( metadata_dir , flag_file ) ) <EOL> if variant is not None : <EOL> break <EOL> return ( arch , variant ) <EOL> class GentooPackage ( GentooNoPortagePackage ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , package_path ) : <EOL> GentooNoPortagePackage . __init__ ( self , package_path ) <EOL> def _load ( self ) : <EOL> """<STR_LIT>""" <EOL> with qisys . sh . TempDir ( ) as work_dir : <EOL> pkg = portage . xpak . tbz2 ( self . path ) <EOL> pkg . decompose ( work_dir , cleanup = <NUM_LIT:0> ) <EOL> arch , arch_variant = _get_pkg_arch ( work_dir ) <EOL> with open ( os . path . join ( work_dir , '<STR_LIT>' ) , '<STR_LIT:r>' ) as fpf : <EOL> pf = fpf . readline ( ) . strip ( ) <EOL> name , version , revision = portage . versions . pkgsplit ( pf ) <EOL> dependency = dict ( ) <EOL> for dep , dep_filename in _DEPENDENCY . iteritems ( ) : <EOL> dep_path = os . path . join ( work_dir , dep_filename ) <EOL> if not os . path . exists ( dep_path ) : <EOL> dependency [ dep ] = list ( ) <EOL> continue <EOL> with open ( dep_path , '<STR_LIT:r>' ) as fdep : <EOL> dependency [ dep ] = fdep . read ( ) . strip ( ) . split ( ) <EOL> dependency [ '<STR_LIT:all>' ] = list ( ) <EOL> for dep_list in _DEPENDENCY . keys ( ) : <EOL> dependency [ '<STR_LIT:all>' ] . extend ( dependency [ dep_list ] ) <EOL> for dep , dep_list in dependency . iteritems ( ) : <EOL> dependency [ dep ] = list ( set ( dep_list ) ) <EOL> metadata = { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:version>' : version , <EOL> '<STR_LIT>' : revision , <EOL> '<STR_LIT>' : arch , <EOL> '<STR_LIT>' : arch_variant , <EOL> '<STR_LIT>' : dependency , <EOL> } <EOL> self . metadata = metadata </s>
