<s> import urllib <EOL> from django . core . urlresolvers import reverse <EOL> from corehq . apps . app_manager . exceptions import MediaResourceError <EOL> from corehq . apps . app_manager . suite_xml . post_process . menu import GridMenuHelper <EOL> from corehq . apps . app_manager . suite_xml . sections . details import DetailContributor <EOL> from corehq . apps . app_manager . suite_xml . sections . entries import EntriesContributor <EOL> from corehq . apps . app_manager . suite_xml . features . careplan import CareplanMenuContributor <EOL> from corehq . apps . app_manager . suite_xml . features . scheduler import SchedulerFixtureContributor <EOL> from corehq . apps . app_manager . suite_xml . sections . fixtures import FixtureContributor <EOL> from corehq . apps . app_manager . suite_xml . post_process . instances import EntryInstances <EOL> from corehq . apps . app_manager . suite_xml . sections . menus import MenuContributor <EOL> from corehq . apps . app_manager . suite_xml . sections . resources import FormResourceContributor , LocaleResourceContributor <EOL> from corehq . apps . app_manager . suite_xml . post_process . workflow import WorkflowHelper <EOL> from corehq . apps . app_manager . suite_xml . sections . sync_requests import SyncRequestContributor <EOL> from corehq . apps . app_manager . suite_xml . xml_models import Suite , MediaResource <EOL> from corehq . apps . app_manager import id_strings <EOL> from corehq . apps . app_manager . util import split_path <EOL> from corehq . apps . hqmedia . models import HQMediaMapItem <EOL> class SuiteGenerator ( object ) : <EOL> descriptor = u"<STR_LIT>" <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> self . modules = list ( app . get_modules ( ) ) <EOL> self . suite = Suite ( version = self . app . version , descriptor = self . descriptor ) <EOL> def _add_sections ( self , contributors ) : <EOL> for contributor in contributors : <EOL> section = contributor . section_name <EOL> getattr ( self . suite , section ) . extend ( <EOL> contributor . get_section_elements ( ) <EOL> ) <EOL> def generate_suite ( self ) : <EOL> self . _add_sections ( [ <EOL> FormResourceContributor ( self . suite , self . app , self . modules ) , <EOL> LocaleResourceContributor ( self . suite , self . app , self . modules ) , <EOL> DetailContributor ( self . suite , self . app , self . modules ) , <EOL> ] ) <EOL> entries = EntriesContributor ( self . suite , self . app , self . modules ) <EOL> menus = MenuContributor ( self . suite , self . app , self . modules ) <EOL> careplan_menus = CareplanMenuContributor ( self . suite , self . app , self . modules ) <EOL> sync_requests = SyncRequestContributor ( self . suite , self . app , self . modules ) <EOL> for module in self . modules : <EOL> self . suite . entries . extend ( entries . get_module_contributions ( module ) ) <EOL> self . suite . menus . extend ( <EOL> careplan_menus . get_module_contributions ( module ) <EOL> ) <EOL> self . suite . menus . extend ( <EOL> menus . get_module_contributions ( module ) <EOL> ) <EOL> self . suite . sync_requests . extend ( sync_requests . get_module_contributions ( module ) ) <EOL> self . _add_sections ( [ <EOL> FixtureContributor ( self . suite , self . app , self . modules ) , <EOL> SchedulerFixtureContributor ( self . suite , self . app , self . modules ) , <EOL> ] ) <EOL> if self . app . enable_post_form_workflow : <EOL> WorkflowHelper ( self . suite , self . app , self . modules ) . update_suite ( ) <EOL> if self . app . use_grid_menus : <EOL> GridMenuHelper ( self . suite , self . app , self . modules ) . update_suite ( ) <EOL> EntryInstances ( self . suite , self . app , self . modules ) . update_suite ( ) <EOL> return self . suite . serializeDocument ( pretty = True ) <EOL> class MediaSuiteGenerator ( object ) : <EOL> descriptor = u"<STR_LIT>" <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> self . suite = Suite ( <EOL> version = self . app . version , <EOL> descriptor = self . descriptor , <EOL> ) <EOL> def generate_suite ( self ) : <EOL> self . suite . media_resources . extend ( self . media_resources ) <EOL> return self . suite . serializeDocument ( pretty = True ) <EOL> @ property <EOL> def media_resources ( self ) : <EOL> PREFIX = '<STR_LIT>' <EOL> self . app . remove_unused_mappings ( ) <EOL> if self . app . multimedia_map is None : <EOL> self . app . multimedia_map = { } <EOL> for path , m in self . app . multimedia_map . items ( ) : <EOL> unchanged_path = path <EOL> if path . startswith ( PREFIX ) : <EOL> path = path [ len ( PREFIX ) : ] <EOL> else : <EOL> raise MediaResourceError ( '<STR_LIT>' % ( path , PREFIX ) ) <EOL> path , name = split_path ( path ) <EOL> install_path = u'<STR_LIT>' . format ( path ) <EOL> local_path = u'<STR_LIT>' . format ( path , name ) <EOL> if not getattr ( m , '<STR_LIT>' , None ) : <EOL> m . unique_id = HQMediaMapItem . gen_unique_id ( m . multimedia_id , unchanged_path ) <EOL> descriptor = None <EOL> if self . app . build_version >= '<STR_LIT>' : <EOL> type_mapping = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> descriptor = u"<STR_LIT>" . format ( <EOL> filetype = type_mapping . get ( m . media_type , "<STR_LIT>" ) , <EOL> name = name <EOL> ) <EOL> yield MediaResource ( <EOL> id = id_strings . media_resource ( m . unique_id , name ) , <EOL> path = install_path , <EOL> version = m . version , <EOL> descriptor = descriptor , <EOL> local = ( local_path <EOL> if self . app . enable_local_resource <EOL> else None ) , <EOL> remote = self . app . url_base + reverse ( <EOL> '<STR_LIT>' , <EOL> args = [ m . media_type , m . multimedia_id ] <EOL> ) + urllib . quote ( name . encode ( '<STR_LIT:utf-8>' ) ) if name else name <EOL> ) </s>
