<s> import distutils . dir_util <EOL> import logging <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> from giftwrap . builders import Builder <EOL> from giftwrap . openstack_git_repo import OpenstackGitRepo <EOL> from giftwrap . package import Package <EOL> from giftwrap . util import execute <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class PackageBuilder ( Builder ) : <EOL> def __init__ ( self , spec ) : <EOL> self . _temp_dir = None <EOL> super ( PackageBuilder , self ) . __init__ ( spec ) <EOL> def _execute ( self , command , cwd = None , exit = <NUM_LIT:0> ) : <EOL> return execute ( command , cwd , exit ) <EOL> def _make_temp_dir ( self , prefix = '<STR_LIT>' ) : <EOL> return tempfile . mkdtemp ( prefix ) <EOL> def _make_dir ( self , path , mode = <NUM_LIT:0> <NUM_LIT> ) : <EOL> os . makedirs ( path , mode ) <EOL> def _prepare_build ( self ) : <EOL> return <EOL> def _prepare_project_build ( self , project ) : <EOL> install_path = project . install_path <EOL> LOG . info ( "<STR_LIT>" , project . name ) <EOL> if os . path . exists ( install_path ) : <EOL> if self . _spec . settings . force_overwrite : <EOL> LOG . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % install_path ) <EOL> shutil . rmtree ( install_path ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % <EOL> install_path ) <EOL> def _clone_project ( self , giturl , name , gitref , depth , path ) : <EOL> LOG . info ( "<STR_LIT>" , name ) <EOL> repo = OpenstackGitRepo ( giturl , name , gitref , depth = depth ) <EOL> repo . clone ( path ) <EOL> return repo <EOL> def _create_virtualenv ( self , venv_command , path ) : <EOL> self . _execute ( venv_command , path ) <EOL> def _install_pip_dependencies ( self , venv_path , dependencies ) : <EOL> pip_path = self . _get_venv_pip_path ( venv_path ) <EOL> for dependency in dependencies : <EOL> self . _execute ( "<STR_LIT>" % ( pip_path , dependency ) ) <EOL> def _copy_sample_config ( self , src_clone_dir , project ) : <EOL> src_config = os . path . join ( src_clone_dir , '<STR_LIT>' ) <EOL> dest_config = os . path . join ( project . install_path , '<STR_LIT>' ) <EOL> if not os . path . exists ( src_config ) : <EOL> LOG . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" , project . name ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" , src_config , <EOL> dest_config ) <EOL> distutils . dir_util . copy_tree ( src_config , dest_config ) <EOL> def _install_project ( self , venv_path , src_clone_dir ) : <EOL> pip_path = self . _get_venv_pip_path ( venv_path ) <EOL> self . _execute ( "<STR_LIT>" % ( pip_path , src_clone_dir ) ) <EOL> def _finalize_project_build ( self , project ) : <EOL> pkg = Package ( project . package_name , project . version , <EOL> project . install_path , self . _spec . settings . output_dir , <EOL> self . _spec . settings . force_overwrite , <EOL> project . system_dependencies ) <EOL> pkg . build ( ) <EOL> def _finalize_build ( self ) : <EOL> return <EOL> def _cleanup_build ( self ) : <EOL> shutil . rmtree ( self . _temp_dir ) </s>
