Django

Code

Changeset 7652

Show
Ignore:
Timestamp:
06/15/08 22:56:48 (5 months ago)
Author:
adrian
Message:

Fixed #6654 -- Slightly refactored the way 'startproject' and 'startapp' check for existing Python modules. Thanks, i_i

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/commands/startapp.py

    r7294 r7652  
    44 
    55class Command(LabelCommand): 
    6     help = ("Creates a Django app directory structure for the given app name" 
    7             " in the current directory.") 
     6    help = "Creates a Django app directory structure for the given app name in the current directory." 
    87    args = "[appname]" 
    98    label = 'application name' 
     
    1716        if directory is None: 
    1817            directory = os.getcwd() 
     18 
    1919        # Determine the project_name by using the basename of directory, 
    2020        # which should be the full path of the project directory (or the 
     
    2424            raise CommandError("You cannot create an app with the same name" 
    2525                               " (%r) as your project." % app_name) 
     26 
     27        # Check that the app_name cannot be imported. 
     28        try: 
     29            __import__(app_name) 
     30        except ImportError: 
     31            pass 
     32        else: 
     33            raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name." % app_name) 
     34 
    2635        copy_helper(self.style, 'app', app_name, directory, project_name) 
    2736 
  • django/trunk/django/core/management/commands/startproject.py

    r7320 r7652  
    33import re 
    44from random import choice 
    5  
    6 INVALID_PROJECT_NAMES = ('django', 'site', 'test') 
    75 
    86class Command(LabelCommand): 
     
    2119        directory = os.getcwd() 
    2220 
     21        # Check that the project_name cannot be imported. 
    2322        try: 
    24             proj_name = __import__(project_name) 
    25             if proj_name: 
    26                 raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name." % project_name) 
     23            __import__(project_name) 
    2724        except ImportError: 
    28             if project_name in INVALID_PROJECT_NAMES: 
    29                 raise CommandError("%r contains an invalid project name. Please try another name." % project_name) 
     25            pass 
     26        else: 
     27            raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name." % project_name) 
    3028 
    3129        copy_helper(self.style, 'project', project_name, directory)