def iter_index_files(app, build_profile_id=None): from corehq.apps.app_manager.views.download import download_index_files skip_files = ('profile.xml', 'profile.ccpr', 'media_profile.xml') text_extensions = ('.xml', '.ccpr', '.txt') files = [] errors = [] def _get_name(f): return {'media_profile.ccpr': 'profile.ccpr'}.get(f, f) def _encode_if_unicode(s): return s.encode('utf-8') if isinstance(s, unicode) else s def _files(files): for name, f in files: if build_profile_id is not None: name = name.replace(build_profile_id + '/', '') if name not in skip_files: # TODO: make RemoteApp.create_all_files not return media files extension = os.path.splitext(name)[1] data = _encode_if_unicode( f) if extension in text_extensions else f yield (_get_name(name), data) try: files = download_index_files(app, build_profile_id) except Exception as e: errors = [unicode(e)] return _files(files), errors
def _download_index_files(app, build_profile_id, is_retry=False): try: return download_index_files(app, build_profile_id) except ResourceConflict as e: if is_retry: raise e return _download_index_files(app, build_profile_id, is_retry=True)
def iter_index_files(app): from corehq.apps.app_manager.views.download import download_index_files skip_files = ('profile.xml', 'profile.ccpr', 'media_profile.xml') text_extensions = ('.xml', '.ccpr', '.txt') get_name = lambda f: {'media_profile.ccpr': 'profile.ccpr'}.get(f, f) files = [] errors = [] def _encode_if_unicode(s): return s.encode('utf-8') if isinstance(s, unicode) else s def _files(files): for name, f in files: if name not in skip_files: # TODO: make RemoteApp.create_all_files not return media files extension = os.path.splitext(name)[1] data = _encode_if_unicode(f) if extension in text_extensions else f yield (get_name(name), data) try: files = download_index_files(app) except Exception: errors = _( "We were unable to get your files " "because your Application has errors. " "Please click Make New Version under Deploy " "for feedback on how to fix these errors." ) return _files(files), errors
def iter_index_files(app, build_profile_id=None): from corehq.apps.app_manager.views.download import download_index_files skip_files = ('profile.xml', 'profile.ccpr', 'media_profile.xml') text_extensions = ('.xml', '.ccpr', '.txt') files = [] errors = [] def _get_name(f): return {'media_profile.ccpr': 'profile.ccpr'}.get(f, f) def _encode_if_unicode(s): return s.encode('utf-8') if isinstance(s, unicode) else s def _files(files): for name, f in files: if build_profile_id is not None: name = name.replace(build_profile_id + '/', '') if name not in skip_files: # TODO: make RemoteApp.create_all_files not return media files extension = os.path.splitext(name)[1] data = _encode_if_unicode( f) if extension in text_extensions else f yield (_get_name(name), data) try: files = download_index_files(app, build_profile_id) except Exception: errors = _("We were unable to get your files " "because your Application has errors. " "Please click Make New Version under Deploy " "for feedback on how to fix these errors.") return _files(files), errors
def iter_index_files(app, build_profile_id=None): from corehq.apps.app_manager.views.download import download_index_files skip_files = ('profile.xml', 'profile.ccpr', 'media_profile.xml') text_extensions = ('.xml', '.ccpr', '.txt') files = [] errors = [] def _get_name(f): return {'media_profile.ccpr': 'profile.ccpr'}.get(f, f) def _encode_if_unicode(s): return s.encode('utf-8') if isinstance(s, unicode) else s def _files(files): for name, f in files: if build_profile_id is not None: name = name.replace(build_profile_id + '/', '') if name not in skip_files: # TODO: make RemoteApp.create_all_files not return media files extension = os.path.splitext(name)[1] data = _encode_if_unicode(f) if extension in text_extensions else f yield (_get_name(name), data) try: files = download_index_files(app, build_profile_id) except Exception as e: errors = [unicode(e)] return _files(files), errors
def iter_index_files(app, build_profile_id=None, download_targeted_version=False): from corehq.apps.app_manager.views.download import download_index_files from dimagi.utils.logging import notify_exception skip_files = [ text_format.format(suffix) for text_format in ['profile{}.xml', 'profile{}.ccpr', 'media_profile{}.xml'] for suffix in ['', '-' + TARGET_COMMCARE, '-' + TARGET_COMMCARE_LTS] ] text_extensions = ('.xml', '.ccpr', '.txt') files = [] errors = [] def _get_name(f): return { 'media_profile{}.ccpr'.format(suffix): 'profile.ccpr' for suffix in ['', '-' + TARGET_COMMCARE, '-' + TARGET_COMMCARE_LTS] }.get(f, f) def _encode_if_unicode(s): return s.encode('utf-8') if isinstance(s, six.text_type) else s def _files(files): for name, f in files: if download_targeted_version and name == 'media_profile.ccpr': continue elif not download_targeted_version and name in [ 'media_profile-{}.ccpr'.format(suffix) for suffix in [TARGET_COMMCARE, TARGET_COMMCARE_LTS] ]: continue if build_profile_id is not None: name = name.replace(build_profile_id + '/', '') if name not in skip_files: # TODO: make RemoteApp.create_all_files not return media files extension = os.path.splitext(name)[1] data = _encode_if_unicode(f) if extension in text_extensions else f yield (_get_name(name), data) try: files = download_index_files(app, build_profile_id) except Exception as e: notify_exception(None, e.message) errors = [six.text_type(e)] return _files(files), errors