Exemplo n.º 1
0
 def uninstall(self, pkg):
     log("Uninstalling {}".format(pkg.name))
     try:
         if hasattr(pkg, 'installFile') and pkg.type == 'Macro':
             uninstall_macro(pkg.installFile)
         elif hasattr(pkg, 'installDir') and pkg.type == 'Workbench':
             shutil.rmtree(pkg.installDir, ignore_errors=True)                
     except BaseException as e:
         log_err(str(e))
Exemplo n.º 2
0
def run_macro(path, session, params, request, response):
    """
    Execute macro
    """

    path = Path(params['macro'])
    try:
        Gui.doCommandGui("exec(open(\"{0}\").read())".format(path.as_posix()))
    except Exception as ex:
        log_err(tr("Error in macro:"), path, str(ex))

    response.html_ok()
Exemplo n.º 3
0
def message_handler(message):
    """
    Process Javascript messages from webview
    """

    try:
        handler_name = message['handler']
    except KeyError:
        log_err("Invalid handler: None")
    else:
        try:
            handler = message_handlers[handler_name]
        except KeyError:
            log_err("Invalid handler {0}".format(handler_name))
        else:
            return handler(message, get_updated_browser_session())
Exemplo n.º 4
0
def request_handler(path, action, params, request, response):
    """
    Process extman:// requests from webview
    """

    # Restore state
    session = get_updated_browser_session()

    # Call action logic if any
    if action:
        response_wrapper = TemplateResponseWrapper(response)
        try:
            handler = actions[action]
        except KeyError:
            log_err("Invalid action {0}".format(action))
        else:
            handler(path, session, params, request, response_wrapper)

    # Default action is render template.
    else:
        html, url = render(path, model=session.model)
        response.write(html)
        response.send()
Exemplo n.º 5
0
def build_macro_package(path,
                        macro_name,
                        is_core=False,
                        is_git=False,
                        is_wiki=False,
                        install_path=None,
                        base_path=""):

    with open(path, 'r', encoding='utf-8') as f:

        try:
            tags = get_macro_tags(f.read(), path)
        except:  # !TODO: Handle encoding problems in old windows platforms
            tags = {k: None for k in MACRO_TAG_FILTER}
            log_err(tr('Macro {0} contains invalid characters').format(path))

        install_dir = get_macro_path()
        base = dict(key=str(install_path) if install_path else str(path),
                    type='Macro',
                    isCore=is_core,
                    installDir=install_dir,
                    installFile=Path(install_dir, path.name),
                    isGit=is_git,
                    isWiki=is_wiki,
                    basePath=base_path)
        tags.update(base)

        if not tags['title']:
            tags['title'] = tags['name'] or macro_name

        tags['name'] = macro_name  # Always override name with actual file name

        if not tags['icon']:
            tags['icon'] = get_resource_path('html', 'img',
                                             'package_macro.svg')

        try:
            if not Path(tags['icon']).exists():
                tags['icon'] = get_resource_path('html', 'img',
                                                 'package_macro.svg')
        except:
            tags['icon'] = get_resource_path('html', 'img',
                                             'package_macro.svg')

        tags['icon'] = utils.path_to_url(tags['icon'])

        if tags['comment']:
            tags['description'] = tags['comment']

        if not tags['description']:
            tags['description'] = tr('Warning! No description')

        if tags['categories']:
            cats = COMMA_SEP_LIST_PATTERN.split(tags['categories'])
            tags['categories'] = [tr(c) for c in cats]
        else:
            tags['categories'] = [tr('Uncategorized')]

        if tags['files']:
            tags['files'] = COMMA_SEP_LIST_PATTERN.split(tags['files'])

        if tags['readme']:
            tags['readmeUrl'] = tags['readme']
            tags['readmeFormat'] = 'html'
        elif tags['wiki']:
            tags['readmeUrl'] = tags['wiki']
            tags['readmeFormat'] = 'html'
        elif tags['web']:
            tags['readmeUrl'] = tags['web']
            tags['readmeFormat'] = 'html'

        return PackageInfo(**tags)