зеркало из https://github.com/mozilla/FlightDeck.git
create subdirs for attachments
This commit is contained in:
Родитель
f454fd9dae
Коммит
423fe04c54
|
@ -27,6 +27,7 @@ from jetpack.errors import SelfDependencyException, FilenameExistException, \
|
|||
# ManifestNotValid
|
||||
|
||||
from xpi import xpi_utils
|
||||
from utils.os_utils import make_path
|
||||
|
||||
log = commonware.log.getLogger('f.jetpack')
|
||||
|
||||
|
@ -1145,8 +1146,10 @@ class Attachment(models.Model):
|
|||
|
||||
def export_file(self, static_dir):
|
||||
" copies from uploads to the package's data directory "
|
||||
shutil.copy('%s/%s' % (settings.UPLOAD_DIR, self.path),
|
||||
'%s/%s.%s' % (static_dir, self.filename, self.ext))
|
||||
path = os.path.join(static_dir, '%s.%s' % (self.filename, self.ext))
|
||||
make_path(os.path.dirname(os.path.abspath(path)))
|
||||
shutil.copy(os.path.join(settings.UPLOAD_DIR, self.path),
|
||||
path)
|
||||
|
||||
def increment(self, revision):
|
||||
revision.attachments.remove(self)
|
||||
|
|
|
@ -362,7 +362,7 @@ def package_add_attachment(r, id_number, type_id,
|
|||
if not filename:
|
||||
log_msg = 'Path not found: %s, package: %s.' % (
|
||||
filename, id_number)
|
||||
log.warning(log_msg)
|
||||
log.error(log_msg)
|
||||
return HttpResponseServerError('Path not found.')
|
||||
|
||||
attachment = revision.attachment_create_by_filename(r.user, filename)
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
# from http://jimmyg.org/blog/2009/working-with-python-subprocess.html
|
||||
import os
|
||||
|
||||
|
||||
# from http://jimmyg.org/blog/2009/working-with-python-subprocess.html
|
||||
def whereis(program):
|
||||
for path in os.environ.get('PATH', '').split(':'):
|
||||
if os.path.exists(os.path.join(path, program)) and \
|
||||
not os.path.isdir(os.path.join(path, program)):
|
||||
return os.path.join(path, program)
|
||||
return None
|
||||
|
||||
|
||||
def make_path(directory):
|
||||
""" Create all needed directories on the path """
|
||||
sections = directory.split('/')
|
||||
path = '/'
|
||||
dir_created = False
|
||||
for d in sections:
|
||||
path = os.path.join(path, d)
|
||||
if path and not os.path.isdir(path):
|
||||
dir_created = True
|
||||
os.mkdir(path)
|
||||
|
||||
return dir_created
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче