<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import tempfile <EOL> import zipfile <EOL> from qisys import ui <EOL> import qisys . error <EOL> import qisys . qixml <EOL> import qibuild . breakpad <EOL> import qibuild . worktree <EOL> import qibuild . cmake_builder <EOL> import qipy . worktree <EOL> import qipy . python_builder <EOL> import qilinguist . worktree <EOL> import qilinguist . builder <EOL> import qilinguist . pml_translator <EOL> import qipkg . manifest <EOL> class PMLBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pml_path , worktree = None ) : <EOL> if not os . path . exists ( pml_path ) : <EOL> raise qisys . error . Error ( "<STR_LIT>" % pml_path ) <EOL> self . pml_path = pml_path <EOL> self . base_dir = os . path . dirname ( self . pml_path ) <EOL> self . manifest_xml = os . path . join ( self . base_dir , "<STR_LIT>" ) <EOL> if not os . path . exists ( self . manifest_xml ) : <EOL> raise qisys . error . Error ( "<STR_LIT>" % self . manifest_xml ) <EOL> self . pkg_name = pkg_name ( self . manifest_xml ) <EOL> self . worktree = worktree <EOL> if self . worktree : <EOL> self . build_worktree = qibuild . worktree . BuildWorkTree ( self . worktree ) <EOL> self . cmake_builder = qibuild . cmake_builder . CMakeBuilder ( self . build_worktree ) <EOL> self . python_worktree = qipy . worktree . PythonWorkTree ( self . worktree ) <EOL> self . python_builder = qipy . python_builder . PythonBuilder ( <EOL> self . python_worktree , <EOL> build_worktree = self . build_worktree ) <EOL> self . linguist_worktree = qilinguist . worktree . LinguistWorkTree ( self . worktree ) <EOL> self . linguist_builder = qilinguist . builder . QiLinguistBuilder ( ) <EOL> self . builders = [ self . cmake_builder , self . python_builder , self . linguist_builder ] <EOL> else : <EOL> self . cmake_builder = None <EOL> self . build_worktree = None <EOL> self . python_builder = None <EOL> self . python_worktree = None <EOL> self . linguist_builder = None <EOL> self . linguist_worktree = None <EOL> self . builders = list ( ) <EOL> self . build_project = None <EOL> self . _stage_path = None <EOL> self . pml_extra_files = list ( ) <EOL> self . load_pml ( pml_path ) <EOL> self . validator = qipkg . manifest . Validator ( self . manifest_xml ) <EOL> self . validator . print_errors ( ) <EOL> self . validator . print_warnings ( ) <EOL> @ property <EOL> def stage_path ( self ) : <EOL> if self . worktree : <EOL> dot_qi = self . worktree . dot_qi <EOL> build_config = self . cmake_builder . build_config <EOL> name = build_config . build_directory ( prefix = "<STR_LIT>" ) <EOL> return os . path . join ( dot_qi , name ) <EOL> else : <EOL> if not self . _stage_path : <EOL> self . _stage_path = tempfile . mkdtemp ( ) <EOL> return self . _stage_path <EOL> def load_pml ( self , pml_path ) : <EOL> try : <EOL> self . _load_pml ( pml_path ) <EOL> except qisys . worktree . NoSuchProject as e : <EOL> mess = """<STR_LIT>""" <EOL> raise qisys . error . Error ( <EOL> mess . format ( pml_path = pml_path , mess = str ( e ) ) ) <EOL> def _load_pml ( self , pml_path ) : <EOL> for builder in self . builders : <EOL> builder . projects = list ( ) <EOL> tree = qisys . qixml . read ( pml_path ) <EOL> root = tree . getroot ( ) <EOL> qibuild_elems = root . findall ( "<STR_LIT>" ) <EOL> if qibuild_elems and not self . worktree : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" ) <EOL> for qibuild_elem in qibuild_elems : <EOL> name = qisys . qixml . parse_required_attr ( qibuild_elem , "<STR_LIT:name>" , pml_path ) <EOL> project = self . build_worktree . get_build_project ( name , raises = True ) <EOL> self . cmake_builder . projects . append ( project ) <EOL> self . build_project = project <EOL> qipython_elems = root . findall ( "<STR_LIT>" ) <EOL> if qipython_elems and not self . worktree : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" ) <EOL> for qipython_elem in qipython_elems : <EOL> name = qisys . qixml . parse_required_attr ( qipython_elem , "<STR_LIT:name>" , pml_path ) <EOL> project = self . python_worktree . get_python_project ( name , raises = True ) <EOL> self . python_builder . projects . append ( project ) <EOL> qilinguist_elems = root . findall ( "<STR_LIT>" ) <EOL> if qilinguist_elems and not self . worktree : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" ) <EOL> for qilinguist_elem in qilinguist_elems : <EOL> name = qisys . qixml . parse_required_attr ( qilinguist_elem , "<STR_LIT:name>" , pml_path ) <EOL> project = self . linguist_worktree . get_linguist_project ( name , raises = True ) <EOL> self . linguist_builder . projects . append ( project ) <EOL> behaviors = root . find ( "<STR_LIT>" ) <EOL> if behaviors is not None : <EOL> for child in behaviors . findall ( "<STR_LIT>" ) : <EOL> src = child . get ( "<STR_LIT:src>" ) <EOL> full_src = os . path . join ( src , "<STR_LIT>" ) <EOL> self . pml_extra_files . append ( full_src ) <EOL> dialogs = root . find ( "<STR_LIT>" ) <EOL> if dialogs is not None : <EOL> for child in dialogs . findall ( "<STR_LIT>" ) : <EOL> src = child . get ( "<STR_LIT:src>" ) <EOL> self . pml_extra_files . append ( src ) <EOL> resources = root . find ( "<STR_LIT>" ) <EOL> if resources is not None : <EOL> for child in resources . findall ( "<STR_LIT>" ) : <EOL> src = child . get ( "<STR_LIT:src>" ) <EOL> self . pml_extra_files . append ( src ) <EOL> topics = root . find ( "<STR_LIT>" ) <EOL> if topics is not None : <EOL> for child in topics . findall ( "<STR_LIT>" ) : <EOL> src = child . get ( "<STR_LIT:src>" ) <EOL> self . pml_extra_files . append ( src ) <EOL> errors = list ( ) <EOL> for file in self . pml_extra_files : <EOL> full_path = os . path . join ( self . base_dir , file ) <EOL> if not os . path . exists ( full_path ) : <EOL> errors . append ( file ) <EOL> if errors : <EOL> mess = "<STR_LIT>" <EOL> for error in errors : <EOL> mess += error + "<STR_LIT:\n>" <EOL> raise qisys . error . Error ( mess ) <EOL> def configure ( self ) : <EOL> """<STR_LIT>""" <EOL> for builder in self . builders : <EOL> if isinstance ( builder , qibuild . cmake_builder . CMakeBuilder ) : <EOL> builder . dep_types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:test>" ] <EOL> builder . configure ( ) <EOL> def build ( self ) : <EOL> """<STR_LIT>""" <EOL> for builder in self . builders : <EOL> builder . build ( ) <EOL> def install ( self , destination ) : <EOL> """<STR_LIT>""" <EOL> qisys . sh . mkdir ( destination , recursive = True ) <EOL> qisys . sh . install ( self . manifest_xml , destination ) <EOL> for builder in self . builders : <EOL> desc = desc_from_builder ( builder ) <EOL> if builder . projects : <EOL> ui . info ( ui . bold , "<STR_LIT>" % desc ) <EOL> if isinstance ( builder , qibuild . cmake_builder . CMakeBuilder ) : <EOL> builder . dep_types = [ "<STR_LIT>" ] <EOL> builder . install ( destination , components = [ "<STR_LIT>" ] ) <EOL> else : <EOL> builder . install ( destination ) <EOL> if self . pml_extra_files : <EOL> ui . info ( ui . bold , "<STR_LIT>" ) <EOL> for src in self . pml_extra_files : <EOL> full_src = os . path . join ( self . base_dir , src ) <EOL> rel_src = os . path . relpath ( full_src , self . base_dir ) <EOL> full_dest = os . path . join ( destination , rel_src ) <EOL> qisys . sh . install ( full_src , full_dest ) <EOL> ui . info ( ui . bold , "<STR_LIT>" ) <EOL> pml_translator = qilinguist . pml_translator . PMLTranslator ( self . pml_path ) <EOL> pml_translator . release ( ) <EOL> pml_translator . install ( destination ) <EOL> def deploy ( self , url ) : <EOL> """<STR_LIT>""" <EOL> qisys . remote . deploy ( self . stage_path , url ) <EOL> def package ( self , output = None , with_breakpad = False , force = False ) : <EOL> """<STR_LIT>""" <EOL> if not self . validator . is_valid and not force : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> qisys . sh . rm ( self . stage_path ) <EOL> qisys . sh . mkdir ( self . stage_path , recursive = True ) <EOL> res = list ( ) <EOL> if not output : <EOL> output = os . path . join ( os . getcwd ( ) , self . pkg_name + "<STR_LIT>" ) <EOL> self . install ( self . stage_path ) <EOL> ui . info ( ui . bold , "<STR_LIT>" ) <EOL> qisys . archive . compress ( self . stage_path , output = output , flat = True , <EOL> display_progress = True ) <EOL> symbols_archive = None <EOL> if with_breakpad and self . build_project : <EOL> ui . info ( ui . bold , "<STR_LIT>" ) <EOL> dirname = os . path . dirname ( output ) <EOL> symbols_archive = os . path . join ( dirname , self . pkg_name + "<STR_LIT>" ) <EOL> qibuild . breakpad . gen_symbol_archive ( base_dir = self . stage_path , <EOL> output = symbols_archive ) <EOL> ui . info ( ui . bold , "<STR_LIT>" , symbols_archive ) <EOL> ui . info ( ui . bold , "<STR_LIT>" , output , "<STR_LIT:\n>" ) <EOL> qisys . sh . rm ( self . stage_path ) <EOL> if symbols_archive : <EOL> return [ output , symbols_archive ] <EOL> else : <EOL> return output <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . pml_path <EOL> def pkg_name ( manifest_xml ) : <EOL> "<STR_LIT>" <EOL> root = qisys . qixml . read ( manifest_xml ) . getroot ( ) <EOL> uuid = qisys . qixml . parse_required_attr ( root , "<STR_LIT>" , xml_path = manifest_xml ) <EOL> version = qisys . qixml . parse_required_attr ( root , "<STR_LIT:version>" , xml_path = manifest_xml ) <EOL> output_name = "<STR_LIT>" % ( uuid , version ) <EOL> return output_name <EOL> def desc_from_builder ( builder ) : <EOL> class_name = builder . __class__ . __name__ <EOL> if "<STR_LIT>" in class_name : <EOL> return "<STR_LIT>" <EOL> if "<STR_LIT>" in class_name : <EOL> return "<STR_LIT>" <EOL> if "<STR_LIT>" in class_name : <EOL> return "<STR_LIT>" </s>
