<s> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import shutil <EOL> import textwrap <EOL> from os . path import exists , join <EOL> import oscar <EOL> def create_local_app_folder ( local_app_path ) : <EOL> if exists ( local_app_path ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % local_app_path ) <EOL> for folder in subfolders ( local_app_path ) : <EOL> if not exists ( folder ) : <EOL> os . mkdir ( folder ) <EOL> init_path = join ( folder , '<STR_LIT>' ) <EOL> if not exists ( init_path ) : <EOL> create_file ( init_path ) <EOL> def subfolders ( path ) : <EOL> """<STR_LIT>""" <EOL> folders = [ ] <EOL> while path not in ( '<STR_LIT:/>' , '<STR_LIT>' ) : <EOL> folders . append ( path ) <EOL> path = os . path . dirname ( path ) <EOL> folders . reverse ( ) <EOL> return folders <EOL> def inherit_app_config ( local_app_path , app_package , app_label ) : <EOL> if '<STR_LIT>' in app_label : <EOL> config_name = '<STR_LIT>' % app_label . split ( '<STR_LIT:.>' ) . pop ( ) . title ( ) <EOL> elif app_label == '<STR_LIT>' : <EOL> config_name = '<STR_LIT>' <EOL> else : <EOL> config_name = app_label . title ( ) + '<STR_LIT>' <EOL> create_file ( <EOL> join ( local_app_path , '<STR_LIT>' ) , <EOL> "<STR_LIT>" . format ( <EOL> app_package = app_package , config_name = config_name ) ) <EOL> create_file ( <EOL> join ( local_app_path , '<STR_LIT>' ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> app_package = app_package , <EOL> app_label = app_label , <EOL> config_name = config_name ) ) <EOL> def fork_app ( label , folder_path , logger = None ) : <EOL> """<STR_LIT>""" <EOL> if logger is None : <EOL> logger = logging . getLogger ( __name__ ) <EOL> valid_labels = [ x . replace ( '<STR_LIT>' , '<STR_LIT>' ) for x in oscar . OSCAR_CORE_APPS <EOL> if x . startswith ( '<STR_LIT>' ) ] <EOL> if label not in valid_labels : <EOL> raise ValueError ( "<STR_LIT>" % label ) <EOL> if folder_path == '<STR_LIT:.>' : <EOL> folder_path = '<STR_LIT>' <EOL> label_folder = label . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) <EOL> local_app_path = join ( folder_path , label_folder ) <EOL> logger . info ( "<STR_LIT>" % local_app_path ) <EOL> create_local_app_folder ( local_app_path ) <EOL> app_package = local_app_path . replace ( '<STR_LIT:/>' , '<STR_LIT:.>' ) <EOL> oscar_app_path = join ( oscar . __path__ [ <NUM_LIT:0> ] , '<STR_LIT>' , label_folder ) <EOL> if exists ( os . path . join ( oscar_app_path , '<STR_LIT>' ) ) : <EOL> logger . info ( "<STR_LIT>" ) <EOL> create_file ( join ( local_app_path , '<STR_LIT>' ) , <EOL> "<STR_LIT>" % label ) <EOL> logger . info ( "<STR_LIT>" ) <EOL> inherit_app_config ( local_app_path , app_package , label ) <EOL> oscar_models_path = join ( oscar_app_path , '<STR_LIT>' ) <EOL> if exists ( oscar_models_path ) : <EOL> logger . info ( "<STR_LIT>" ) <EOL> create_file ( <EOL> join ( local_app_path , '<STR_LIT>' ) , <EOL> "<STR_LIT>" % label ) <EOL> migrations_path = '<STR_LIT>' <EOL> source = join ( oscar_app_path , migrations_path ) <EOL> if exists ( source ) : <EOL> logger . info ( "<STR_LIT>" , migrations_path ) <EOL> destination = join ( local_app_path , migrations_path ) <EOL> shutil . copytree ( source , destination ) <EOL> msg = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) % app_package <EOL> snippet = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) % app_package <EOL> record = "<STR_LIT>" % ( <EOL> "<STR_LIT:\n>" . join ( textwrap . wrap ( msg ) ) , snippet ) <EOL> logger . info ( record ) <EOL> def create_file ( filepath , content = '<STR_LIT>' ) : <EOL> with open ( filepath , '<STR_LIT:w>' ) as f : <EOL> f . write ( content ) </s>
