a ˆ#½e/"ã@sŠddlZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z ddlmZmZe d¡ZGdd „d eƒZdS) éN)ÚABC)Ú UserDataStoreÚGlobalDataStore)Úget_plugins_persistent_path)Úcontextmanager)Úrequirements_installedÚcompute_file_md5z app.loggerc@súeZdZdd„Zdd„Zdd„Zdd„Zd d „Zed d „ƒZ d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zdnóz2PluginBase.get_include_js_urls..)Úinclude_js_filesrrrrÚget_include_js_urlsmszPluginBase.get_include_js_urlscs‡fdd„ˆ ¡DƒS)Ncsg|]}ˆ |¡‘qSrrB)rDZcss_filerrrrEqrFz3PluginBase.get_include_css_urls..)Úinclude_css_filesrrrrÚget_include_css_urlspszPluginBase.get_include_css_urlscCsd | ¡|¡S)zŸ :param path: unix-style path :return: Path that can be accessed via a URL (from the browser), relative to plugins//public z/plugins/{}/{})r(r<©rr rrrrCsszPluginBase.public_urlcCsdtj | ¡tƒ¡vS)z¢ :return: whether this plugin is persistent (stored in the /plugins directory, instead of /app/media/plugins which are transient) z..)rr ÚrelpathrrrrrrÚ is_persistentzszPluginBase.is_persistentcCs,| ¡rd | ¡|¡Sd | ¡|¡SdS)zt :param path: unix-style path :return: path used to reference Django templates for a plugin zcoreplugins/{}/templates/{}zplugins/{}/templates/{}N)rMr(r<rKrrrÚ template_pathszPluginBase.template_pathcCstj | |¡¡Sr)rr r!rrKrrrÚ path_existsŒszPluginBase.path_existscCsgS)z¾ Should be overriden by plugins to communicate which JS files should be included in the WebODM interface All paths are relative to a plugin's /public folder. rrrrrrGszPluginBase.include_js_filescCsgS)z¿ Should be overriden by plugins to communicate which CSS files should be included in the WebODM interface All paths are relative to a plugin's /public folder. rrrrrrI—szPluginBase.include_css_filescCsgS)z¶ Experimental Should be overriden by plugins that want to automatically build JSX files. All paths are relative to a plugin's /public folder. rrrrrÚbuild_jsx_componentsŸszPluginBase.build_jsx_componentscCst| ¡ƒdkS)zY Whether the plugin requires an app restart to function properly r)ÚlenÚroot_mount_pointsrrrrÚrequires_restart¨szPluginBase.requires_restartcCsgS)z… Should be overriden by plugins that want to add items to the side menu. :return: [] of Menu objects rrrrrÚ main_menu¯szPluginBase.main_menucCsgS)a˜ Should be overriden by plugins that want to add routes to the root view controller. CAUTION: this should be used sparingly, as routes could conflict with other plugins and future versions of WebODM might break the routes. It's recommended to use app_mount_points, unless you know what you are doing. :return: [] of MountPoint objects rrrrrrR·s zPluginBase.root_mount_pointscCsgS)z‹ Should be overriden by plugins that want to connect custom Django views :return: [] of MountPoint objects rrrrrÚapp_mount_pointsÄszPluginBase.app_mount_pointscCsgS)zˆ Should be overriden by plugins that want to add new API mount points :return: [] of MountPoint objects rrrrrÚapi_mount_pointsÌszPluginBase.api_mount_pointscCsdS)aG Should be overriden by plugins that want to control which users have access to the public assets. By default anyone can access them, including anonymous users. :param request: HTTP request :return: boolean (whether the plugin's public assets should be exposed for this request) Tr)rÚrequestrrrÚserve_public_assetsÔszPluginBase.serve_public_assetsNcKs$ddlm}|| |¡|fi|¤ŽS)a± Retrieves a view handler that serves a dynamic script from the plugin's directory. Dynamic scripts are normal Javascript files that optionally support Template variable substitution via ${vars}, computed on the server. :param script_path: path to script relative to plugin's directory. :param callback: optional callback. The callback can prevent the script from being returned if it returns False. If it returns a dictionary, the dictionary items are used for variable substitution. :param template_args: Parameters to use for variable substitution (unless a callback is specified) :return: Django view r)Úget_dynamic_script_handler)Ú app.pluginsrYr)rZ script_pathÚcallbackZ template_argsrYrrrÚget_dynamic_scriptÞs zPluginBase.get_dynamic_scriptcCsP|jr |jS| d¡}t|ƒ}t |¡|_Wdƒn1s@0Y|jS)Nz manifest.json)rrr#ÚjsonÚload)rZ manifest_pathZ manifest_filerrrÚ get_manifestís    *zPluginBase.get_manifestcCsd | ¡¡S)Nz[{}])r(r rrrrÚ__str__ùszPluginBase.__str__)N)!Ú__name__rAÚ __qualname__rrrr3r"rr7rr<r>r?r rHrJrCrMrNrOrGrIrPrSrTrRrUrVrXr\r_r`rrrrr s<(      r )r]Úloggingrr4r*ÚabcrrZrrZapp.plugins.functionsrÚ contextlibrZapp.plugins.pyutilsrrÚ getLoggerr&r rrrrÚs