diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 3668e782623..f768cc6999f 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -73,15 +73,14 @@ class TemplateCommand(BaseCommand): # 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=())) diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 27e3bb4a97d..4bde86ce4ad 100644 --- a/docs/ref/django-admin.txt +++ b/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 ```` 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 diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index f896817eabb..948eb3a6592 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -1404,17 +1404,17 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): "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 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): 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