Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@carljm carljm authored
View
13 django/core/management/templates.py
@@ -73,15 +73,14 @@ def handle(self, app_or_project, name, target=None, **options):
# if some directory is given, make sure it's nicely expanded
if target is None:
- target = os.getcwd()
+ top_dir = path.join(os.getcwd(), name)
+ try:
+ os.makedirs(top_dir)
+ except OSError, e:
+ raise CommandError(e)
else:
- target = path.expanduser(target)
+ top_dir = path.expanduser(target)
- top_dir = path.join(target, name)
- try:
- os.makedirs(top_dir)
- except OSError, e:
- raise CommandError(e)
extensions = tuple(
handle_extensions(options.get('extensions'), ignored=()))
View
20 docs/ref/django-admin.txt
@@ -922,13 +922,13 @@ template files. (See the `source`_ for more details.) If only the app
name is given, the app directory will be created in the current working
directory.
-If the optional destination is provided, Django will create the new project
-directory in that directory. You can use '.' to denote the current working
-directory.
+If the optional destination is provided, Django will use that existing
+directory rather than creating a new one. You can use '.' to denote the current
+working directory.
For example::
- django-admin.py startapp myapp /Users/jezdez/Code
+ django-admin.py startapp myapp /Users/jezdez/Code/myapp
.. versionadded:: 1.4
.. django-admin-option:: --template
@@ -984,20 +984,20 @@ the current directory or the given destination.
.. versionchanged:: 1.4
By default, the new directory contains ``manage.py`` and a project package
-(containing ``settings.py`` file and other project template files).
-See the `template source`_ for details.
+(containing a ``settings.py`` and other files). See the `template source`_ for
+details.
If only the project name is given, both the project directory and project
package will be named ``<projectname>`` and the project directory
will be created in the current working directory.
-If the optional destination is provided, Django will create the new project
-directory in that directory. You can use '.' to denote the current working
-directory.
+If the optional destination is provided, Django will use that existing
+directory as the project directory, and create ``manage.py`` and the project
+package within it. You can use '.' to denote the current working directory.
For example::
- django-admin.py startproject myproject /Users/jezdez/Code
+ django-admin.py startproject myproject /Users/jezdez/Code/myproject_repo
.. versionadded:: 1.4
View
19 tests/regressiontests/admin_scripts/tests.py
@@ -1404,17 +1404,17 @@ def test_simple_project_different_directory(self):
"Make sure the startproject management command creates a project in a specific directory"
args = ['startproject', 'testproject', 'othertestproject']
testproject_dir = os.path.join(test_dir, 'othertestproject')
+ os.mkdir(testproject_dir)
out, err = self.run_django_admin(args)
self.addCleanup(shutil.rmtree, testproject_dir)
self.assertNoOutput(err)
- self.assertTrue(os.path.isdir(os.path.join(testproject_dir, 'testproject')))
- self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'testproject', 'manage.py')))
+ self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'manage.py')))
# running again..
out, err = self.run_django_admin(args)
self.assertNoOutput(out)
- self.assertOutput(err, "File exists")
+ self.assertOutput(err, "already exists")
def test_custom_project_template(self):
"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):
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
+ def test_custom_project_template_from_tarball_to_alternative_location(self):
+ "Startproject can use a project template from a tarball and create it in a specified location"
+ template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template.tgz')
+ args = ['startproject', '--template', template_path, 'tarballtestproject', 'altlocation']
+ testproject_dir = os.path.join(test_dir, 'altlocation')
+ os.mkdir(testproject_dir)
+
+ out, err = self.run_django_admin(args)
+ self.addCleanup(shutil.rmtree, testproject_dir)
+ self.assertNoOutput(err)
+ self.assertTrue(os.path.isdir(testproject_dir))
+ self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
+
def test_custom_project_template_from_tarball_by_url(self):
"Make sure the startproject management command is able to use a different project template from a tarball via a url"
template_url = '%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url
Please sign in to comment.
Something went wrong with that request. Please try again.