<s> from __future__ import print_function <EOL> import os <EOL> import six <EOL> import sys <EOL> import shutil <EOL> import tarfile <EOL> from jinja2 import Environment , PackageLoader <EOL> BASE_DIR = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> def check_template ( members ) : <EOL> required_members = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> for fname in required_members : <EOL> assert fname in members , "<STR_LIT>" % fname <EOL> return False <EOL> return True <EOL> def from_template ( args ) : <EOL> """<STR_LIT>""" <EOL> project_name = args . name <EOL> template = args . template <EOL> with tarfile . open ( template ) as tar : <EOL> check_template ( tar . getnames ( ) ) <EOL> tar . extractall ( project_name ) <EOL> def from_oct ( args ) : <EOL> """<STR_LIT>""" <EOL> project_name = args . name <EOL> env = Environment ( loader = PackageLoader ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> config_content = env . get_template ( '<STR_LIT>' ) . render ( script_name = '<STR_LIT>' ) <EOL> script_content = env . get_template ( '<STR_LIT>' ) . render ( ) <EOL> try : <EOL> os . makedirs ( project_name ) <EOL> os . makedirs ( os . path . join ( project_name , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( project_name , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( project_name , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> shutil . copytree ( os . path . join ( BASE_DIR , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( project_name , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> shutil . copytree ( os . path . join ( BASE_DIR , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( project_name , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> shutil . copy ( os . path . join ( BASE_DIR , '<STR_LIT>' , '<STR_LIT:html>' , '<STR_LIT>' ) , <EOL> os . path . join ( project_name , '<STR_LIT>' ) ) <EOL> except OSError : <EOL> print ( '<STR_LIT>' % project_name , file = sys . stderr ) <EOL> raise <EOL> with open ( os . path . join ( project_name , '<STR_LIT>' ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( config_content ) <EOL> with open ( os . path . join ( project_name , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( script_content ) <EOL> def create_project ( args ) : <EOL> if os . path . exists ( args . name ) : <EOL> raise OSError ( "<STR_LIT>" % args . name ) <EOL> if args . template is not None : <EOL> from_template ( args ) <EOL> else : <EOL> from_oct ( args ) <EOL> def new_project ( sp ) : <EOL> if six . PY2 : <EOL> parser = sp . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> else : <EOL> parser = sp . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" , aliases = [ '<STR_LIT>' ] ) <EOL> parser . add_argument ( '<STR_LIT:name>' , type = str ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = str , default = None , help = "<STR_LIT>" ) <EOL> parser . set_defaults ( func = create_project ) </s>
