<s> from conans . util . files import mkdir , save , rmdir <EOL> import os <EOL> from conans . util . log import logger <EOL> from conans . paths import CONANINFO , CONAN_MANIFEST <EOL> from conans . errors import ConanException <EOL> from conans . model . build_info import DEFAULT_RES , DEFAULT_BIN , DEFAULT_LIB , DEFAULT_INCLUDE <EOL> import shutil <EOL> from conans . client . file_copier import FileCopier <EOL> from conans . model . manifest import FileTreeManifest <EOL> from conans . client . output import ScopedOutput <EOL> def create_package ( conanfile , build_folder , package_folder , output ) : <EOL> """<STR_LIT>""" <EOL> mkdir ( package_folder ) <EOL> output . info ( "<STR_LIT>" ) <EOL> output . info ( "<STR_LIT>" % ( package_folder ) ) <EOL> conanfile . copy = FileCopier ( build_folder , package_folder ) <EOL> def wrap ( dst_folder ) : <EOL> def new_method ( pattern , src = "<STR_LIT>" ) : <EOL> conanfile . copy ( pattern , dst_folder , src ) <EOL> return new_method <EOL> conanfile . copy_headers = wrap ( DEFAULT_INCLUDE ) <EOL> conanfile . copy_libs = wrap ( DEFAULT_LIB ) <EOL> conanfile . copy_bins = wrap ( DEFAULT_BIN ) <EOL> conanfile . copy_res = wrap ( DEFAULT_RES ) <EOL> try : <EOL> conanfile . package_folder = package_folder <EOL> conanfile . package ( ) <EOL> package_output = ScopedOutput ( "<STR_LIT>" % output . scope , output ) <EOL> conanfile . copy . report ( package_output , warn = True ) <EOL> except Exception as e : <EOL> os . chdir ( build_folder ) <EOL> try : <EOL> rmdir ( package_folder ) <EOL> except Exception as e_rm : <EOL> output . error ( "<STR_LIT>" <EOL> % ( package_folder , str ( e_rm ) ) ) <EOL> output . warn ( "<STR_LIT>" ) <EOL> raise ConanException ( "<STR_LIT>" % ( conanfile . name , str ( e ) ) ) <EOL> _create_aux_files ( build_folder , package_folder ) <EOL> output . success ( "<STR_LIT>" % os . path . basename ( package_folder ) ) <EOL> def generate_manifest ( package_folder ) : <EOL> digest = FileTreeManifest . create ( package_folder ) <EOL> save ( os . path . join ( package_folder , CONAN_MANIFEST ) , str ( digest ) ) <EOL> def _create_aux_files ( build_folder , package_folder ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> logger . debug ( "<STR_LIT>" % package_folder ) <EOL> shutil . copy ( os . path . join ( build_folder , CONANINFO ) , package_folder ) <EOL> generate_manifest ( package_folder ) <EOL> except IOError : <EOL> raise ConanException ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( CONANINFO , build_folder ) ) </s>
