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

Commit

Permalink
add new revision if package with uploaded name existed.
Browse files Browse the repository at this point in the history
  • Loading branch information
zalun committed Dec 30, 2010
1 parent 2abfd6d commit f454fd9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
41 changes: 21 additions & 20 deletions apps/jetpack/models.py
Expand Up @@ -693,12 +693,10 @@ def add_mods_and_atts_from_archive(self, packed, main, lib_dir, att_dir):
if module_path and not module_path.endswith('/'):
module_path = os.path.splitext(module_path)[0]
code = packed.read(path)
# this looks like a potential problem if library
if module_path == main:
main_mod = self.modules.get(
filename=self.module_main)
main_mod.code = code
self.update(main_mod, save=False)
if module_path in [m.filename for m in self.modules.all()]:
mod = self.modules.get(filename=module_path)
mod.code = code
self.update(mod, save=False)
else:
self.module_create(
save=False,
Expand All @@ -712,23 +710,25 @@ def add_mods_and_atts_from_archive(self, packed, main, lib_dir, att_dir):
if att_path and not att_path.endswith('/'):
code = packed.read(path)
basename = os.path.basename(att_path)
# XXX the filename will be changed
upload_name = '%f-%s' % (time.time(), basename)
upload_path = os.path.join(
settings.UPLOAD_DIR,
upload_name)
f = open(upload_path, 'w')
f.write(code)
f.close()
filename, ext = os.path.splitext(att_path)
if ext.startswith('.'):
ext = ext.split('.')[1]
self.attachment_create(
save=False,
filename=filename,
ext=ext,
path=upload_name,
author=self.author)

if (filename, ext) in [(a.filename, a.ext)
for a in self.attachments.all()]:
att = self.attachments.get(filename=filename, ext=ext)
att.data = code
self.update(att, save=False)
else:
att = self.attachment_create(
save=False,
filename=filename,
ext=ext,
path='temp',
author=self.author)
att.data = code
att.write()
self.attachments.add(att)

def attachment_create_by_filename(self, author, filename):
""" find out the filename and ext and call attachment_create """
Expand Down Expand Up @@ -1135,6 +1135,7 @@ def write(self):
self.save()

directory = os.path.dirname(self.get_file_path())

if not os.path.exists(directory):
os.makedirs(directory)

Expand Down
4 changes: 3 additions & 1 deletion apps/jetpack/package_helpers.py
Expand Up @@ -137,6 +137,7 @@ def _save_package(packed, name, harness_options, package_type, author):
try:
obj = Package.objects.get(author=author, name=name,
type=package_type)
new_revision = True
except:
obj = Package(
author=author,
Expand All @@ -149,9 +150,10 @@ def _save_package(packed, name, harness_options, package_type, author):
)
obj.save()
obj.latest.set_version('empty.uploaded')
new_revision=False

obj.create_revision_from_xpi(packed, manifest, author,
harness_options['jetpackID'])
harness_options['jetpackID'], new_revision=new_revision)

return obj

Expand Down
8 changes: 8 additions & 0 deletions apps/jetpack/tests/package_tests.py
Expand Up @@ -120,6 +120,14 @@ def test_create_addon_from_xpi(self):
self.failUnless(('attachment', 'txt') in [(a.filename, a.ext)
for a in addon.latest.attachments.all()])

def test_update_addon_from_xpi(self):
path_xpi = os.path.join(
settings.ROOT, 'apps/jetpack/tests/sample_addon.xpi')
addon = create_package_from_xpi(path_xpi, self.author)
addon = create_package_from_xpi(path_xpi, self.author)
self.failUnless(addon)
eq_(addon.revisions.count(), 2)

def test_create_addon_from_xpi_with_libs(self):
libs = ['sample_library']
path_xpi = os.path.join(
Expand Down

0 comments on commit f454fd9

Please sign in to comment.