@@ -0,0 +1,2070 @@
+from __future__ import absolute_import%0Afrom __future__ import unicode_literals%0Afrom django.core.management.base import BaseCommand%0A%0Afrom couchdbkit import ResourceNotFound%0Afrom corehq.apps.app_manager.models import Application%0Afrom six.moves import input%0A%0A%0Aclass Command(BaseCommand):%0A    help = %22Unlinks linked project spaces and converts the downstream app into a standalone app.%22%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument(%0A            'linked_app_id',%0A            help='The ID of the downstream app'%0A        )%0A        parser.add_argument(%0A            'linked_domain',%0A            help='The name of the downstream project space'%0A        )%0A        parser.add_argument(%0A            'master_domain',%0A            help='The name of the master project space'%0A        )%0A%0A    def handle(self, linked_app_id, linked_domain, master_domain, **options):%0A        try:%0A            linked_app = Application.get(linked_app_id)%0A        except ResourceNotFound:%0A            print('No downstream app found for ID %7B%7D '.format(linked_app_id))%0A            return%0A%0A        if linked_app.domain != linked_domain:%0A            print(%22Project space in the app found from ID %7B%7D does not match the linked project space %22%0A                  %22that was given.%22.format(linked_app_id))%0A            return%0A%0A        confirm = input(%0A            %22%22%22%0A            Found %7B%7D in project space %7B%7D linked to project space %7B%7D. %0A            Are you sure you want to un-link these apps? %5By/n%5D%0A            %22%22%22.format(linked_app.name, linked_domain, master_domain)%0A        )%0A        if confirm.lower() != 'y':%0A            return%0A%0A        print('Unlinking apps')%0A        raw_linked_app_doc = Application.get_db().get(linked_app.id)%0A        del raw_linked_app_doc%5B'master'%5D%0A        del raw_linked_app_doc%5B'linked_app_translations'%5D%0A        del raw_linked_app_doc%5B'linked_app_logo_refs'%5D%0A        del raw_linked_app_doc%5B'uses_master_app_form_ids'%5D%0A        raw_linked_app_doc%5B'doc_type'%5D = 'Application'%0A        Application.get_db().save_doc(raw_linked_app_doc)%0A        print('Operation completed')%0A

Add unlink_apps management command