Ejemplo n.º 1
0
def on_search_plugins(ctx):
    if not xauth.is_admin():
        return
    if not ctx.search_tool:
        return
    if ctx.search_dict:
        return
    name = ctx.key
    results = []
    words = textutil.split_words(name)
    for name in xconfig.PLUGINS_DICT:
        plugin = xconfig.PLUGINS_DICT[name]
        unquote_name = xutils.unquote(plugin.fname)
        unquote_name, ext = os.path.splitext(unquote_name)
        plugin_context = plugin
        if textutil.contains_all(unquote_name, words) \
                or (textutil.contains_all(plugin_context.title, words)):
            result = SearchResult()
            result.category = "plugin"
            result.icon = "fa-cube"
            result.name = u(unquote_name)
            if plugin_context != None:
                # result.raw = u(plugin_context.title)
                # result.name = u("插件 %s (%s)") % (u(plugin_context.title), unquote_name)
                if plugin_context.title != None:
                    result.name = u(plugin_context.title + "(" + unquote_name +
                                    ")")
            result.url = u(plugin.url)
            result.edit_link = u("/code/edit?path=" + plugin.fpath)
            results.append(result)
    ctx.tools += results
Ejemplo n.º 2
0
def on_search_plugins(ctx):
    if not xauth.is_admin():
        return
    if not ctx.search_tool:
        return
    if ctx.search_dict:
        return
    name = ctx.key
    results = []
    dirname = xconfig.PLUGINS_DIR
    words = textutil.split_words(name)
    for fname in xutils.listdir(dirname):
        unquote_name = xutils.unquote(fname)
        unquote_name, ext = os.path.splitext(unquote_name)
        plugin_context = xconfig.PLUGINS.get(fname)
        if textutil.contains_all(unquote_name, words) \
                or (plugin_context != None and textutil.contains_all(plugin_context.title, words)):
            result = SearchResult()
            result.category = "plugin"
            result.name = u("[插件] " + unquote_name)
            if plugin_context != None:
                # result.raw = u(plugin_context.title)
                # result.name = u("插件 %s (%s)") % (u(plugin_context.title), unquote_name)
                if plugin_context.title != None:
                    result.name = u("[插件] " + plugin_context.title + "(" +
                                    unquote_name + ")")
            result.url = u("/plugins/" + unquote_name)
            result.edit_link = u("/code/edit?path=" +
                                 os.path.join(dirname, fname))
            results.append(result)
    ctx.tools += results
Ejemplo n.º 3
0
def search_plugins(key):
    words   = textutil.split_words(key)
    plugins = list_plugins("all")
    result  = []
    for p in plugins:
        if textutil.contains_all(p.title, words) or textutil.contains_all(p.url, words) or textutil.contains_all(p.fname, words):
            result.append(p)
    return result
Ejemplo n.º 4
0
def search_group(user_name, words):
    rows = NOTE_DAO.list_group(user_name)
    result = []
    for row in rows:
        if textutil.contains_all(row.name, words):
            result.append(row)
    return result
Ejemplo n.º 5
0
 def search_func(key, value):
     if value.tag == "key":
         return False
     if value.content is None:
         return False
     return value.user == user_name and textutil.contains_all(
         value.content.lower(), words)
Ejemplo n.º 6
0
 def search_func(key, value):
     if value.is_deleted:
         return False
     if parent_id != None and str(value.parent_id) != parent_id:
         return False
     return (value.creator == creator
             or value.is_public) and textutil.contains_all(
                 value.name.lower(), words)
Ejemplo n.º 7
0
 def list_func(key, value):
     if value.is_deleted:
         return False
     if value.name is None:
         return False
     if parent_id != None and str(
             value.parent_id) != str(parent_id):
         return False
     if words != None and not textutil.contains_all(
             value.name.lower(), words):
         return False
     return True
Ejemplo n.º 8
0
def search_plugins(name):
    results = []
    dirname = xconfig.PLUGINS_DIR
    words = textutil.split_words(name)
    for fname in xutils.listdir(dirname):
        unquote_name = xutils.unquote(fname)
        if textutil.contains_all(unquote_name, words):
            result = SearchResult()
            result.category = "plugin"
            result.name = u("插件 - " + unquote_name)
            result.url = u("/plugins/" + fname)
            result.edit_link = u("/code/edit?path=" +
                                 os.path.join(dirname, fname))
            results.append(result)
    return results
Ejemplo n.º 9
0
def search_scripts(name):
    words   = textutil.split_words(name)
    results = []
    for fname in xutils.listdir(xconfig.SCRIPTS_DIR):
        fpath = os.path.join(xconfig.SCRIPTS_DIR, fname)
        if not os.path.isfile(fpath):
            continue
        if fname.endswith(".zip"):
            continue
        if textutil.contains_all(fname, words):
            result         = xutils.SearchResult()
            result.icon    = "icon-script"
            result.name    = xutils.u(fname)
            result.raw     = xutils.u("搜索到可执行脚本 - ") + fname
            result.url     = xutils.u("/code/edit?path=%s") % fpath
            result.command = xutils.u("/system/script_admin/execute?name=%s") % fname
            results.append(result)
    return results
Ejemplo n.º 10
0
 def search_func(key, value):
     if value.content is None:
         return False
     return (value.creator == creator
             or value.is_public) and textutil.contains_all(
                 value.content.lower(), words)
Ejemplo n.º 11
0
 def search_func(key, value):
     if value.is_deleted:
         return False
     return (value.creator == creator
             or value.is_public) and textutil.contains_all(
                 value.name.lower(), words)
Ejemplo n.º 12
0
 def search_func(key, value):
     if value.content is None:
         return False
     return textutil.contains_all(value.content.lower(), words)
Ejemplo n.º 13
0
Archivo: dao.py Proyecto: chernic/xnote
 def search_func(key, value):
     return value.user == user_name and textutil.contains_all(value.content, words)
Ejemplo n.º 14
0
def is_plugin_matched(p, words):
    return textutil.contains_all(p.title, words) \
        or textutil.contains_all(p.url, words) \
        or textutil.contains_all(p.fname, words)