0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Fixed #17503 -- A destination directory passed to startproject or startapp 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
This commit is contained in:
Carl Meyer 2012-01-04 23:55:34 +00:00
parent 8e9043bccb
commit bc63ba700a
3 changed files with 32 additions and 20 deletions

View File

@ -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=()))

View File

@ -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 File

@ -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