#!/usr/bin/env python

import os
import shutil
import sys

import mezzanine


class ProjectException(Exception):
    pass
    
def create_project():
    """
    Copies the contents of the project_template directory to a new directory 
    specified as an argument to the command line.
    """

    # Ensure a directory name is specified.
    script_name = os.path.basename(sys.argv[0])
    if len(sys.argv) == 1:
        raise ProjectException("Usage: %s project_name" % script_name)
    project_name = sys.argv[1]

    # Ensure the given directory name doesn't clash with an existing Python 
    # package/module.
    try:
        __import__(project_name)
    except ImportError:
        pass
    else:
        raise ProjectException("'%s' conflicts with the name of an existing "
            "Python module and cannot be used as a project name. Please try "
            "another name." % project_name)
                    
    mezzanine_path = os.path.dirname(os.path.abspath(mezzanine.__file__))
    from_path = os.path.join(mezzanine_path, "project_template")
    to_path = os.path.join(os.getcwd(), project_name)
    shutil.copytree(from_path, to_path)
        
if __name__ == "__main__":
    try:
        create_project()
    except ProjectException, e:
        print
        print e
        print
        



@@ -379,16 +379,144 @@
 rgv%5B0%5D)%0A
+%0A    usage_text = %22Usage: %25s project_name%22 %25 script_name%0A    usage_text += %22%5CnProject names beginning with %5C%22-%5C%22 are illegal.%22%0A%0A
     if l
@@ -532,12 +532,12 @@
 gv) 
-== 1
+!= 2
 :%0A  
@@ -565,26 +565,31 @@
 ception(
-%22U
+u
 sage
-: %25s
+_text)%0A   
  project
@@ -597,55 +597,102 @@
 name
-%22 %25 script_name)%0A    project_name = sys.argv%5B1%5D
+ = sys.argv%5B1%5D%0A    if project_name.startswith(%22-%22):%0A        raise ProjectException(usage_text)
 %0A%0A  

make proj name start with "-" illegal and print usage.