Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17503 -- A destination directory passed to startproject or sta…

…rtapp as optional second argument is now reused as the project/app directory, rather than a new project/app directory created within it. Refs #17042.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17340 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bc63ba700a0ae3ba435c267789d8c2e3931016df 1 parent 8e9043b
Carl Meyer authored January 04, 2012
13  django/core/management/templates.py
@@ -73,15 +73,14 @@ def handle(self, app_or_project, name, target=None, **options):
73 73
 
74 74
         # if some directory is given, make sure it's nicely expanded
75 75
         if target is None:
76  
-            target = os.getcwd()
  76
+            top_dir = path.join(os.getcwd(), name)
  77
+            try:
  78
+                os.makedirs(top_dir)
  79
+            except OSError, e:
  80
+                raise CommandError(e)
77 81
         else:
78  
-            target = path.expanduser(target)
  82
+            top_dir = path.expanduser(target)
79 83
 
80  
-        top_dir = path.join(target, name)
81  
-        try:
82  
-            os.makedirs(top_dir)
83  
-        except OSError, e:
84  
-            raise CommandError(e)
85 84
 
86 85
         extensions = tuple(
87 86
             handle_extensions(options.get('extensions'), ignored=()))
20  docs/ref/django-admin.txt
@@ -922,13 +922,13 @@ template files. (See the `source`_ for more details.) If only the app
922 922
 name is given, the app directory will be created in the current working
923 923
 directory.
924 924
 
925  
-If the optional destination is provided, Django will create the new project
926  
-directory in that directory. You can use '.' to denote the current working
927  
-directory.
  925
+If the optional destination is provided, Django will use that existing
  926
+directory rather than creating a new one. You can use '.' to denote the current
  927
+working directory.
928 928
 
929 929
 For example::
930 930
 
931  
-    django-admin.py startapp myapp /Users/jezdez/Code
  931
+    django-admin.py startapp myapp /Users/jezdez/Code/myapp
932 932
 
933 933
 .. versionadded:: 1.4
934 934
 .. django-admin-option:: --template
@@ -984,20 +984,20 @@ the current directory or the given destination.
984 984
 .. versionchanged:: 1.4
985 985
 
986 986
 By default, the new directory contains ``manage.py`` and a project package
987  
-(containing ``settings.py`` file and other project template files).
988  
-See the `template source`_ for details.
  987
+(containing a ``settings.py`` and other files).  See the `template source`_ for
  988
+details.
989 989
 
990 990
 If only the project name is given, both the project directory and project
991 991
 package will be named ``<projectname>`` and the project directory
992 992
 will be created in the current working directory.
993 993
 
994  
-If the optional destination is provided, Django will create the new project
995  
-directory in that directory. You can use '.' to denote the current working
996  
-directory.
  994
+If the optional destination is provided, Django will use that existing
  995
+directory as the project directory, and create ``manage.py`` and the project
  996
+package within it. You can use '.' to denote the current working directory.
997 997
 
998 998
 For example::
999 999
 
1000  
-    django-admin.py startproject myproject /Users/jezdez/Code
  1000
+    django-admin.py startproject myproject /Users/jezdez/Code/myproject_repo
1001 1001
 
1002 1002
 .. versionadded:: 1.4
1003 1003
 
19  tests/regressiontests/admin_scripts/tests.py
@@ -1404,17 +1404,17 @@ def test_simple_project_different_directory(self):
1404 1404
         "Make sure the startproject management command creates a project in a specific directory"
1405 1405
         args = ['startproject', 'testproject', 'othertestproject']
1406 1406
         testproject_dir = os.path.join(test_dir, 'othertestproject')
  1407
+        os.mkdir(testproject_dir)
1407 1408
 
1408 1409
         out, err = self.run_django_admin(args)
1409 1410
         self.addCleanup(shutil.rmtree, testproject_dir)
1410 1411
         self.assertNoOutput(err)
1411  
-        self.assertTrue(os.path.isdir(os.path.join(testproject_dir, 'testproject')))
1412  
-        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'testproject', 'manage.py')))
  1412
+        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'manage.py')))
1413 1413
 
1414 1414
         # running again..
1415 1415
         out, err = self.run_django_admin(args)
1416 1416
         self.assertNoOutput(out)
1417  
-        self.assertOutput(err, "File exists")
  1417
+        self.assertOutput(err, "already exists")
1418 1418
 
1419 1419
     def test_custom_project_template(self):
1420 1420
         "Make sure the startproject management command is able to use a different project template"
@@ -1452,6 +1452,19 @@ def test_custom_project_template_from_tarball_by_path(self):
1452 1452
         self.assertTrue(os.path.isdir(testproject_dir))
1453 1453
         self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
1454 1454
 
  1455
+    def test_custom_project_template_from_tarball_to_alternative_location(self):
  1456
+        "Startproject can use a project template from a tarball and create it in a specified location"
  1457
+        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template.tgz')
  1458
+        args = ['startproject', '--template', template_path, 'tarballtestproject', 'altlocation']
  1459
+        testproject_dir = os.path.join(test_dir, 'altlocation')
  1460
+        os.mkdir(testproject_dir)
  1461
+
  1462
+        out, err = self.run_django_admin(args)
  1463
+        self.addCleanup(shutil.rmtree, testproject_dir)
  1464
+        self.assertNoOutput(err)
  1465
+        self.assertTrue(os.path.isdir(testproject_dir))
  1466
+        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
  1467
+
1455 1468
     def test_custom_project_template_from_tarball_by_url(self):
1456 1469
         "Make sure the startproject management command is able to use a different project template from a tarball via a url"
1457 1470
         template_url = '%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url

0 notes on commit bc63ba7

Please sign in to comment.
Something went wrong with that request. Please try again.