mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Made sure the new project template functionality works when the template
path specified has a trailing path separator. Thanks Alex for the report. Fixes #17475. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17287 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -160,7 +160,7 @@ class TemplateCommand(BaseCommand):
|
||||
if self.verbosity >= 2:
|
||||
self.stdout.write("Cleaning up temporary files.\n")
|
||||
for path_to_remove in self.paths_to_remove:
|
||||
if os.path.isfile(path_to_remove):
|
||||
if path.isfile(path_to_remove):
|
||||
os.remove(path_to_remove)
|
||||
else:
|
||||
shutil.rmtree(path_to_remove,
|
||||
@@ -178,14 +178,15 @@ class TemplateCommand(BaseCommand):
|
||||
if template.startswith('file://'):
|
||||
template = template[7:]
|
||||
expanded_template = path.expanduser(template)
|
||||
if os.path.isdir(expanded_template):
|
||||
expanded_template = path.normpath(expanded_template)
|
||||
if path.isdir(expanded_template):
|
||||
return expanded_template
|
||||
if self.is_url(template):
|
||||
# downloads the file and returns the path
|
||||
absolute_path = self.download(template)
|
||||
else:
|
||||
absolute_path = path.abspath(expanded_template)
|
||||
if os.path.exists(absolute_path):
|
||||
if path.exists(absolute_path):
|
||||
return self.extract(absolute_path)
|
||||
|
||||
raise CommandError("couldn't handle %s template %s." %
|
||||
@@ -203,13 +204,13 @@ class TemplateCommand(BaseCommand):
|
||||
if self.verbosity >= 2:
|
||||
self.stdout.write("Downloading %s\n" % url)
|
||||
try:
|
||||
path, info = urllib.urlretrieve(url,
|
||||
os.path.join(tempdir, filename))
|
||||
the_path, info = urllib.urlretrieve(url,
|
||||
path.join(tempdir, filename))
|
||||
except IOError, e:
|
||||
raise CommandError("couldn't download URL %s to %s: %s" %
|
||||
(url, filename, e))
|
||||
|
||||
used_name = path.split('/')[-1]
|
||||
used_name = the_path.split('/')[-1]
|
||||
|
||||
# Trying to get better name from response headers
|
||||
content_disposition = info.get('content-disposition')
|
||||
@@ -230,18 +231,18 @@ class TemplateCommand(BaseCommand):
|
||||
# Move the temporary file to a filename that has better
|
||||
# chances of being recognnized by the archive utils
|
||||
if used_name != guessed_filename:
|
||||
guessed_path = os.path.join(tempdir, guessed_filename)
|
||||
shutil.move(path, guessed_path)
|
||||
guessed_path = path.join(tempdir, guessed_filename)
|
||||
shutil.move(the_path, guessed_path)
|
||||
return guessed_path
|
||||
|
||||
# Giving up
|
||||
return path
|
||||
return the_path
|
||||
|
||||
def splitext(self, path):
|
||||
def splitext(self, the_path):
|
||||
"""
|
||||
Like os.path.splitext, but takes off .tar, too
|
||||
"""
|
||||
base, ext = posixpath.splitext(path)
|
||||
base, ext = posixpath.splitext(the_path)
|
||||
if base.lower().endswith('.tar'):
|
||||
ext = base[-4:] + ext
|
||||
base = base[:-4]
|
||||
|
||||
Reference in New Issue
Block a user