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

Commit

Permalink
delete and deactivate backend is working
Browse files Browse the repository at this point in the history
  • Loading branch information
zalun committed Feb 21, 2011
1 parent 733c593 commit aaf2770
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
32 changes: 15 additions & 17 deletions apps/jetpack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ def copy(self, author):
lib_dir=self.lib_dir
)
new_p.save()
# Saving the track of forks
new_p.latest.origin = self.latest
super(PackageRevision, new_p.latest).save()
return new_p

def disable(self):
Expand All @@ -288,21 +291,23 @@ def disable(self):
self.active = False
self.save()

def remove(self):
"""Remove from the system if possible, otherwise mark as deleted
"""
if self.is_addon():
return self.delete()
self.delete()

def delete(self):
"""Unhook from copies and perform database delete
"""Remove from the system if possible, otherwise mark as deleted
Unhook from copies if needed and perform database delete
"""
for rev_mutation in PackageRevision.objects.filter(origin__package=self):
for rev_mutation in PackageRevision.objects.filter(
origin__package=self):
rev_mutation.origin=None
# save without creating a new revision
super(PackageRevision, rev_mutation).save()
log.debug('deleting mutation: %s' % rev_mutation)

if not self.is_addon() and \
PackageRevision.dependencies.through.objects.filter(
to_packagerevision__package=self):
self.deleted = True
log.info("Package (%s) marked as deleted" % self)
return self.save()
log.info("Package (%s) deleted" % self)
return super(Package, self).delete()


Expand Down Expand Up @@ -1133,8 +1138,6 @@ def export_keys(self, sdk_dir):
os.mkdir(keydir)

keyfile = os.path.join(keydir, self.package.jid)
log.debug("Writing key file (%s) for add-on (%s)" % (keyfile,
self.get_version_name()))
with open(keyfile, 'w') as f:
f.write('private-key:%s\n' % self.package.private_key)
f.write('public-key:%s' % self.package.public_key)
Expand Down Expand Up @@ -1242,9 +1245,6 @@ def export_code(self, lib_dir):

path = os.path.join(lib_dir, self.get_filename())
make_path(os.path.dirname(os.path.abspath(path)))

log.debug("Writing code for (%s) to file (%s)" % (self, path))

with open(path, 'w') as f:
f.write(self.code)

Expand Down Expand Up @@ -1352,7 +1352,6 @@ def write(self):
if not os.path.exists(directory):
os.makedirs(directory)

log.debug("Writing (%s)" % self.get_file_path())
with open(self.get_file_path(), 'wb') as f:
f.write(data)

Expand All @@ -1362,7 +1361,6 @@ def export_code(self, static_dir):
return self.export_file(static_dir)
path = os.path.join(static_dir, '%s.%s' % (self.filename, self.ext))
make_path(os.path.dirname(os.path.abspath(path)))
log.debug("Writing (%s)" % path)
with open(path, 'w') as f:
f.write(self.code)

Expand Down
15 changes: 13 additions & 2 deletions apps/jetpack/tests/package_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_disable(self):
addon.active = False
addon.save()
eq_(Package.objects.active().filter(type='a').count(), 0)
eq_(Package.objects.active(author=self.author).filter(type='a').count(), 1)
eq_(Package.objects.active(viewer=self.author).filter(type='a').count(), 1)

def test_delete(self):
addon = Package.objects.create(author=self.author, type='a')
Expand All @@ -193,4 +193,15 @@ def test_delete_with_a_copy(self):
addon.delete()
eq_(Package.objects.active().filter(type='a').count(), 1)
eq_(Package.objects.active(viewer=self.author).filter(type='a').count(), 1)
eq_(PackageRevision.objects.filter(package=addon).count(), 1)
eq_(PackageRevision.objects.filter(package=addon).count(), 0)
eq_(PackageRevision.objects.filter(package=addon_copy).count(), 1)

def test_delete_with_dependency(self):
addon = Package.objects.create(author=self.author, type='a')
lib = Package.objects.create(author=self.author, type='l')
addon.latest.dependency_add(lib.latest)
# deleting lib
lib.delete()
eq_(Package.objects.addons().count(), 1)
eq_(Package.objects.libraries().filter(author=self.author).count(), 0)

0 comments on commit aaf2770

Please sign in to comment.