* SDK and PackageRevision have purge option in delete method

This will remove the object and some dependencies

* New management command added (force_sdk)
  ``./manager.py force_sdk 1.0 --purge``
  will make all existing add-ons to use SDK 1.0 and will remove all other
  SDKs

* All SDKs except of the 1.0rc2 are removed from submodules and file system
This commit is contained in:
Piotr Zalewa 2011-06-17 22:22:50 +01:00
Родитель 8c81f6df60
Коммит 0107082e20
14 изменённых файлов: 141 добавлений и 44 удалений

27
.gitmodules поставляемый
Просмотреть файл

@ -1,33 +1,6 @@
[submodule "lib/jetpack-sdk-0.8"]
path = lib/jetpack-sdk-0.8
url = git://github.com/mozillalabs/jetpack-sdk.git
[submodule "lib/addon-sdk-0.9"]
path = lib/addon-sdk-0.9
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0b1"]
path = lib/addon-sdk-1.0b1
url = git://github.com/mozilla/addon-sdk
[submodule "lib/addon-sdk-1.0b2"]
path = lib/addon-sdk-1.0b2
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0b3"]
path = lib/addon-sdk-1.0b3
url = git://github.com/mozilla/addon-sdk.git
[submodule "vendor"]
path = vendor
url = git://github.com/mozilla/FlightDeck-lib.git
[submodule "lib/addon-sdk-1.0b4rc1"]
path = lib/addon-sdk-1.0b4rc1
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0b4rc3"]
path = lib/addon-sdk-1.0b4rc3
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0b4"]
path = lib/addon-sdk-1.0b4
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0b5"]
path = lib/addon-sdk-1.0b5
url = git://github.com/mozilla/addon-sdk.git
[submodule "lib/addon-sdk-1.0rc2"]
path = lib/addon-sdk-1.0rc2
url = git://github.com/mozilla/addon-sdk.git

Просмотреть файл

@ -0,0 +1,66 @@
"""
jetpack.management.commands.force_sdk
-------------------------------------
Force all addons depending on SDK which version is between given versions
to depend on another SDK
"""
from optparse import make_option
from django.core.management.commands.loaddata import Command as BaseCommand
from django.db import models
from jetpack.models import SDK, PackageRevision
class Command(BaseCommand):
args = "<target_version from_version to_version>"
option_list = BaseCommand.option_list + (
make_option('--purge',
action='store_true',
dest='purge',
default=False,
help='Delete all SDK except of target version'),
)
def handle(self, target_version, from_version=None, to_version=None, *args, **kwargs):
"""Force add-ons to use SDK with version ``target_version``
:params:
* target_version (string) Use that target_version
* from_version (string) Choose add-ons using sdk with higher
version
* to_version (string) Choose add-ons using sdk with lower version
* kwargs['purge'] (boolean) Should all other SDKs be purged
"""
try:
sdk = SDK.objects.get(version=target_version)
except:
self.stderr.write("ERROR: No such version (%s)\n" % target_version)
exit(1)
from_q = to_q = models.Q()
revisions = PackageRevision.objects.filter(package__type='a')
if from_version:
from_q = models.Q(sdk__version__gt=from_version)
revisions = revisions.filter(from_q)
if to_version:
to_q = models.Q(sdk__version__lt=to_version)
revisions = revisions.filter(to_q)
revisions = revisions.all()
for revision in revisions:
old_sdk = revision.sdk
revision.sdk = sdk
revision.commit_message += ' switched SDK to (%s)' % target_version
revision.save(create_new_revision=False)
self.stdout.write("%d Revisions switched to SDK %s\n" % (
len(revisions), target_version))
if kwargs.get('purge', False):
oldrevs = PackageRevision.objects.filter(package=sdk.core_lib.package).exclude(version_name=sdk.version)
oldsdks = SDK.objects.exclude(version=target_version)
for oldsdk in oldsdks:
oldsdk.delete(purge=True)
self.stdout.write("%d SDK(s) removed\n" % len(oldsdks))

Просмотреть файл

@ -1,5 +0,0 @@
from django.core.management.commands.loaddata import Command as BaseCommand
class Command(BaseCommand):
pass

Просмотреть файл

@ -496,12 +496,27 @@ class PackageRevision(BaseModel):
if force_save:
super(PackageRevision, self).save()
def save(self, **kwargs):
def delete(self, purge=False, *args, **kwargs):
"""Allowing to purge the PackageRevision
"""
if purge:
log.info("Purging PackageRevision %s" % self)
# delete modules
for mod in self.modules.all():
mod.delete()
self.modules.clear()
# delete delete attachments
for att in self.attachments.all():
att.delete()
self.attachments.clear()
super(PackageRevision, self).delete(*args, **kwargs)
def save(self, create_new_revision=True, **kwargs):
"""
overloading save is needed to prevent from updating the same revision
use super(PackageRevision, self).save(**kwargs) if needed
"""
if self.id:
if self.id and create_new_revision:
# create new revision
return self.save_new_revision(**kwargs)
return super(PackageRevision, self).save(**kwargs)
@ -1446,9 +1461,12 @@ class Package(BaseModel):
self.active = False
self.save()
def delete(self):
def delete(self, *args, **kwargs):
"""Remove from the system if possible, otherwise mark as deleted
Unhook from copies if needed and perform database delete
:param: purge (bool) don't bother with checking if anything does
depend on this object - delete anyway (used in SDK removal)
"""
for rev_mutation in PackageRevision.objects.filter(
origin__package=self):
@ -1888,6 +1906,16 @@ class SDK(BaseModel):
# db and editable on the web)
return self.version < '1.0'
def delete(self, purge=True, *args, **kwargs):
if purge:
log.info("Purging PackageRevision %s" % self)
# delete core_lib
if self.core_lib:
self.core_lib.delete(purge=True)
# delete kit_lib
if self.kit_lib:
self.kit_lib.delete(purge=True)
super(SDK, self).delete(*args, **kwargs)
def _get_next_id_number():

Просмотреть файл

@ -0,0 +1,44 @@
"""
jetpack.tests.sdk_tests
-----------------------
"""
import commonware
from test_utils import TestCase
from nose.tools import eq_
from django.contrib.auth.models import User
from jetpack.models import Package, PackageRevision, SDK
log = commonware.log.getLogger('f.test')
class SDKTests(TestCase):
fixtures = ['mozilla_user', 'users', 'core_sdk', 'packages']
def setUp(self):
self.addon = Package.objects.filter(type='a')[0]
self.mozuser = User.objects.get(username='mozilla')
self.sdk = SDK.objects.get()
def test_purge(self):
version = 'testsdk'
kit_lib = PackageRevision.objects.create(
author=self.mozuser,
package=self.sdk.kit_lib.package,
revision_number=self.sdk.kit_lib.revision_number + 1,
version_name=version)
core_lib = PackageRevision.objects.create(
author=self.mozuser,
package=self.sdk.core_lib.package,
revision_number=self.sdk.core_lib.revision_number + 1,
version_name=version)
sdk = SDK.objects.create(
version=version,
kit_lib=kit_lib,
core_lib=core_lib,
dir='somefakedir')
sdk.delete(purge=True)
eq_(len(PackageRevision.objects.filter(version_name=version)), 0)

@ -1 +0,0 @@
Subproject commit 00a6d7dea6ba954762962bad95d542b75aafd412

@ -1 +0,0 @@
Subproject commit 09a374a7ea9cb67ae0a336f1e819529200fe5e28

@ -1 +0,0 @@
Subproject commit da6bfc93466460e6fefa95a80ef328df6c19b4ff

@ -1 +0,0 @@
Subproject commit e47587d7fa845ea2074f15df4d020899e1ecb7be

@ -1 +0,0 @@
Subproject commit 6b272befd4886b33e77b0dce92e0b49ca97dab80

@ -1 +0,0 @@
Subproject commit 3bf7891342279e6cf6d0f660b6d8487afb458621

@ -1 +0,0 @@
Subproject commit 6b272befd4886b33e77b0dce92e0b49ca97dab80

@ -1 +0,0 @@
Subproject commit fceae1bb71cfea631a974d1ea068a91377ac3d44

@ -1 +0,0 @@
Subproject commit 8c85da7ae9f29c048061f1ae3c0c6c6cc1845a4d