diff --git a/.gitmodules b/.gitmodules index e0842980..12a09f07 100644 --- a/.gitmodules +++ b/.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 diff --git a/apps/jetpack/management/commands/force_sdk.py b/apps/jetpack/management/commands/force_sdk.py new file mode 100644 index 00000000..992a5fa3 --- /dev/null +++ b/apps/jetpack/management/commands/force_sdk.py @@ -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 = "" + 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)) diff --git a/apps/jetpack/management/commands/loaddata.py b/apps/jetpack/management/commands/loaddata.py deleted file mode 100644 index b09173d1..00000000 --- a/apps/jetpack/management/commands/loaddata.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.core.management.commands.loaddata import Command as BaseCommand - - -class Command(BaseCommand): - pass diff --git a/apps/jetpack/models.py b/apps/jetpack/models.py index 1430fc10..e84ceb34 100644 --- a/apps/jetpack/models.py +++ b/apps/jetpack/models.py @@ -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(): diff --git a/apps/jetpack/tests/sdk_tests.py b/apps/jetpack/tests/sdk_tests.py new file mode 100644 index 00000000..ef2ad7d6 --- /dev/null +++ b/apps/jetpack/tests/sdk_tests.py @@ -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) + diff --git a/lib/addon-sdk-0.9 b/lib/addon-sdk-0.9 deleted file mode 160000 index 00a6d7de..00000000 --- a/lib/addon-sdk-0.9 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 00a6d7dea6ba954762962bad95d542b75aafd412 diff --git a/lib/addon-sdk-1.0b1 b/lib/addon-sdk-1.0b1 deleted file mode 160000 index 09a374a7..00000000 --- a/lib/addon-sdk-1.0b1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 09a374a7ea9cb67ae0a336f1e819529200fe5e28 diff --git a/lib/addon-sdk-1.0b2 b/lib/addon-sdk-1.0b2 deleted file mode 160000 index da6bfc93..00000000 --- a/lib/addon-sdk-1.0b2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit da6bfc93466460e6fefa95a80ef328df6c19b4ff diff --git a/lib/addon-sdk-1.0b3 b/lib/addon-sdk-1.0b3 deleted file mode 160000 index e47587d7..00000000 --- a/lib/addon-sdk-1.0b3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e47587d7fa845ea2074f15df4d020899e1ecb7be diff --git a/lib/addon-sdk-1.0b4 b/lib/addon-sdk-1.0b4 deleted file mode 160000 index 6b272bef..00000000 --- a/lib/addon-sdk-1.0b4 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b272befd4886b33e77b0dce92e0b49ca97dab80 diff --git a/lib/addon-sdk-1.0b4rc1 b/lib/addon-sdk-1.0b4rc1 deleted file mode 160000 index 3bf78913..00000000 --- a/lib/addon-sdk-1.0b4rc1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3bf7891342279e6cf6d0f660b6d8487afb458621 diff --git a/lib/addon-sdk-1.0b4rc3 b/lib/addon-sdk-1.0b4rc3 deleted file mode 160000 index 6b272bef..00000000 --- a/lib/addon-sdk-1.0b4rc3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b272befd4886b33e77b0dce92e0b49ca97dab80 diff --git a/lib/addon-sdk-1.0b5 b/lib/addon-sdk-1.0b5 deleted file mode 160000 index fceae1bb..00000000 --- a/lib/addon-sdk-1.0b5 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fceae1bb71cfea631a974d1ea068a91377ac3d44 diff --git a/lib/jetpack-sdk-0.8 b/lib/jetpack-sdk-0.8 deleted file mode 160000 index 8c85da7a..00000000 --- a/lib/jetpack-sdk-0.8 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8c85da7ae9f29c048061f1ae3c0c6c6cc1845a4d