<s> """<STR_LIT>""" <EOL> import os <EOL> import qisys <EOL> import qisys . sh <EOL> import qisys . ui <EOL> from qisys . qixml import etree <EOL> from qitoolchain . binary_package . core import BinaryPackage <EOL> from qitoolchain . binary_package . core import BinaryPackageException <EOL> WITH_PORTAGE = True <EOL> try : <EOL> import portage <EOL> except ImportError : <EOL> WITH_PORTAGE = False <EOL> if WITH_PORTAGE : <EOL> from qitoolchain . binary_package . gentoo_portage import GentooPackage <EOL> else : <EOL> from qitoolchain . binary_package . gentoo import GentooPackage <EOL> _PKG_TYPES = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : GentooPackage , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : BinaryPackage , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : BinaryPackage , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : BinaryPackage , <EOL> } , <EOL> } <EOL> def _guess_package_type ( package_path ) : <EOL> for typename , data in _PKG_TYPES . iteritems ( ) : <EOL> if package_path . endswith ( data . get ( '<STR_LIT>' ) ) : <EOL> return typename <EOL> return None <EOL> def open_package ( package_path ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( package_path ) : <EOL> mess = "<STR_LIT>" . format ( package_path ) <EOL> raise SystemError ( mess ) <EOL> package = None <EOL> typename = _guess_package_type ( package_path ) <EOL> if not typename : <EOL> mess = "<STR_LIT>" <EOL> raise BinaryPackageException ( mess ) <EOL> generator = _PKG_TYPES . get ( typename ) . get ( '<STR_LIT:class>' ) <EOL> package = generator ( package_path ) <EOL> return package <EOL> def _fix_package_tree ( root_dir ) : <EOL> """<STR_LIT>""" <EOL> usr_dir = os . path . join ( root_dir , "<STR_LIT>" ) <EOL> if not os . path . exists ( usr_dir ) : <EOL> return <EOL> for ( root , dirs , files ) in os . walk ( usr_dir ) : <EOL> for directory in dirs : <EOL> dst = os . path . join ( root , directory ) <EOL> dst = dst . replace ( usr_dir , root_dir ) <EOL> qisys . sh . mkdir ( dst ) <EOL> for filename in files : <EOL> src = os . path . join ( root , filename ) <EOL> dst = src . replace ( usr_dir , root_dir ) <EOL> qisys . sh . mv ( src , dst ) <EOL> qisys . sh . rm ( usr_dir ) <EOL> def convert_to_qibuild ( package , package_metadata = None , <EOL> output_dir = None , output_name = None ) : <EOL> """<STR_LIT>""" <EOL> metadata = package . get_metadata ( ) <EOL> if package_metadata : <EOL> metadata . update ( package_metadata ) <EOL> package_name = metadata [ "<STR_LIT:name>" ] <EOL> if not output_dir : <EOL> output_dir = os . path . dirname ( package . path ) <EOL> if not output_name : <EOL> output_name = package_name <EOL> for key in [ '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> value = metadata . get ( key ) <EOL> if value : <EOL> if key == '<STR_LIT>' : <EOL> value = "<STR_LIT:r>" + value <EOL> output_name += "<STR_LIT:->" + value <EOL> output_name += "<STR_LIT>" <EOL> qisys . sh . mkdir ( output_dir , recursive = True ) <EOL> output_path = os . path . join ( output_dir , output_name ) <EOL> with qisys . sh . TempDir ( ) as work_dir : <EOL> root_dir = package . extract ( work_dir ) <EOL> _fix_package_tree ( root_dir ) <EOL> package_xml_path = os . path . join ( root_dir , "<STR_LIT>" ) <EOL> package_xml_root = etree . Element ( "<STR_LIT>" ) <EOL> package_xml_tree = etree . ElementTree ( package_xml_root ) <EOL> package_xml_root . set ( "<STR_LIT:name>" , package_name ) <EOL> version = metadata . get ( "<STR_LIT:version>" ) <EOL> if version : <EOL> package_xml_root . set ( "<STR_LIT:version>" , version ) <EOL> qisys . qixml . write ( package_xml_root , package_xml_path ) <EOL> res = qisys . archive . compress ( root_dir , algo = "<STR_LIT>" , quiet = True , flat = True ) <EOL> qisys . sh . mv ( res , output_path ) <EOL> return output_path </s>
