def setup_ccz_file_for_hosting(hosted_ccz_id, user_email=None): try: hosted_ccz = HostedCCZ.objects.get(pk=hosted_ccz_id) except HostedCCZ.DoesNotExist: return hosted_ccz.update_status('building') version = hosted_ccz.version ccz_utility = hosted_ccz.utility # set up the file if not already present if not ccz_utility.file_exists(): # profile_id should be None and not any other false value profile_id = hosted_ccz.profile_id or None build = wrap_app( get_build_doc_by_version(hosted_ccz.domain, hosted_ccz.app_id, version)) try: ccz_file = create_files_for_ccz(build, profile_id, download_targeted_version=bool( build.commcare_flavor)) with open(ccz_file, 'rb') as ccz: ccz_utility.store_file_in_blobdb(ccz, name=hosted_ccz.file_name) hosted_ccz.update_status('completed') except: exc = sys.exc_info() hosted_ccz.update_status('failed') if user_email: _notify_failure_to_user(hosted_ccz, build, user_email) # delete the file from blob db if it was added but later failed hosted_ccz.delete_ccz() six.reraise(*exc) else: hosted_ccz.update_status('completed')
def setup_ccz_file_for_hosting(hosted_ccz_id): try: hosted_ccz = HostedCCZ.objects.get(pk=hosted_ccz_id) except HostedCCZ.DoesNotExist: return version = hosted_ccz.version ccz_utility = hosted_ccz.utility # set up the file if not already present if not ccz_utility.file_exists(): # profile_id should be None and not any other false value profile_id = hosted_ccz.profile_id or None build = wrap_app( get_build_doc_by_version(hosted_ccz.domain, hosted_ccz.app_id, version)) ccz_file = create_files_for_ccz( build, profile_id, download_targeted_version=build.has_commcare_flavor) try: with open(ccz_file, 'rb') as ccz: ccz_utility.store_file_in_blobdb(ccz, name=hosted_ccz.file_name) except: exc = sys.exc_info() # delete the file from blob db if it was added but later failed hosted_ccz.delete_ccz() six.reraise(*exc)
def get_app_by_version(domain, app_id, version): app = get_build_doc_by_version(domain, app_id, version) if not app: raise Exception( "No app found with id '{}' and version '{}', on '{}'".format( app_id, version, domain)) return wrap_app(app)
def get_master_app_by_version(domain_link, upstream_app_id, upstream_version): if domain_link.is_remote: app = get_app_by_version(domain_link, upstream_app_id, upstream_version) else: app = get_build_doc_by_version(domain_link.master_domain, upstream_app_id, upstream_version) if app: return wrap_app(app)
def _get_initial_app_profile_details(domain, version, app_id, build_profile_id): # only need to set when performing search to populate with initial values in view if app_id and version: build_doc = get_build_doc_by_version(domain, app_id, version) if build_doc: return [{ 'id': _id, 'text': details['name'], 'selected': build_profile_id == _id } for _id, details in build_doc['build_profiles'].items()]
def _get_initial_app_profile_details(self, version): app_id = self.request.GET.get('app_id') selected_profile_id = self.request.GET.get('profile_id', '') # only when performing search populate these initial values if app_id and version: build_doc = get_build_doc_by_version(self.domain, self.request.GET.get('app_id'), version) if build_doc: return [{ 'id': _id, 'text': details['name'], 'selected': selected_profile_id == _id } for _id, details in build_doc['build_profiles'].items()]
def handle(self, from_domain, from_app_id, to_domain, *args, **options): self.from_domain = from_domain self.to_domain = to_domain to_app_id = options.get('to-app-id') version = options.get('version') if to_app_id: app = get_current_app(self.to_domain, to_app_id) print('Overwriting application: {}'.format(app.name)) else: print('Creating new application') app = Application() if version: from_app_doc = get_build_doc_by_version(self.from_domain, from_app_id, version) else: from_app_doc = get_latest_released_app_doc(self.from_domain, from_app_id) if not from_app_doc: raise CommandError("From app not found") from_app = wrap_app(from_app_doc) print('Overwring app with "{}" (version {})'.format(from_app.name, from_app.version)) overwrite_app(app, from_app, self.report_map)
def test_get_specific_version(self): app_doc = get_build_doc_by_version(self.domain, self.app_id, version=2) self.assertEqual(app_doc['version'], 2)
def app_by_version(request, domain, app_id, version): return JsonResponse( {'app': get_build_doc_by_version(domain, app_id, version)})
def build_doc(self): if self.link_id and self.app_id and self.version: return get_build_doc_by_version(self.domain, self.app_id, self.version)
def test_get_specific_version(self): app_doc = get_build_doc_by_version(self.domain, self.app_id, version=2) self.assertEqual(app_doc["version"], 2)