Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
create subdirs for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
zalun committed Jan 3, 2011
1 parent f454fd9 commit 423fe04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions apps/jetpack/models.py
Expand Up @@ -27,6 +27,7 @@
# ManifestNotValid

from xpi import xpi_utils
from utils.os_utils import make_path

log = commonware.log.getLogger('f.jetpack')

Expand Down Expand Up @@ -1145,8 +1146,10 @@ def write(self):

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)
Expand Down
2 changes: 1 addition & 1 deletion apps/jetpack/views.py
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion utils/os_utils.py
@@ -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

0 comments on commit 423fe04

Please sign in to comment.