Esempio n. 1
0
File: fs.py Progetto: ydx2099/xnote
    def GET(self):
        fpath = xutils.get_argument("path")
        basename, ext = os.path.splitext(fpath)
        encoded_fpath = xutils.encode_uri_component(fpath)

        if ext == ".txt":
            raise web.found("/fs_text?path=%s" % encoded_fpath)

        if ext in (".html", ".htm"):
            raise web.found("/fs/%s" % encoded_fpath)

        if ext in (".md", ".csv"):
            raise web.found("/code/preview?path=%s" % encoded_fpath)

        if ext in (".key", ".numbers"):
            os.system("open %r" % fpath)
            parent_fpath = os.path.abspath(os.path.dirname(fpath))
            encoded_parent = xutils.encode_uri_component(parent_fpath)
            raise web.found("/fs/%s" % encoded_parent)

        if ext == ".db":
            raise web.found("/tools/sql?path=%s" % encoded_fpath)

        if xutils.is_text_file(fpath):
            raise web.found("/code/edit?path=%s" % encoded_fpath)

        raise web.found("/fs/%s" % encoded_fpath)
Esempio n. 2
0
def list_search_rules(user_name):
    list, count = MSG_DAO.list_by_tag(user_name, 'key', 0, 1000)

    for item in list:
        item.url = "/note/timeline?type=search&key=" + xutils.encode_uri_component(
            item.content)
    return list
Esempio n. 3
0
    def __init__(self,
                 path,
                 parent=None,
                 merge=False,
                 encode_path=True,
                 name=None):
        self.path = path
        self.name = fixed_basename(path)

        self.size = '-'
        self.cdate = '-'
        self.icon = "fa-file-o"
        _, self.ext = os.path.splitext(path)
        self.ext = self.ext.lower()

        if parent != None:
            self.name = get_relative_path(path, parent)

        # 处理Windows盘符
        if path.endswith(":"):
            self.name = path

        if encode_path:
            self.encoded_path = xutils.encode_uri_component(self.path)

        # 处理文件属性
        self.handle_file_stat(merge)

        if name != None:
            self.name = name

        if FileItem.post_handler is not None:
            FileItem.post_handler(self)
Esempio n. 4
0
File: fs.py Progetto: ydx2099/xnote
    def GET(self):
        fpath = xutils.get_argument("path")
        basename, ext = os.path.splitext(fpath)
        encoded_fpath = xutils.encode_uri_component(fpath)

        if xutils.is_text_file(fpath):
            raise web.found("/code/edit?path=%s" % encoded_fpath)

        raise web.found("/fs_hex?path=%s" % encoded_fpath)
Esempio n. 5
0
File: fs.py Progetto: 552301/xnote
    def GET(self):
        fpath = xutils.get_argument("path")
        basename, ext = os.path.splitext(fpath)
        encoded_fpath = xutils.encode_uri_component(fpath)

        if ext == ".txt":
            raise web.found("/fs_text?path=%s" % encoded_fpath)

        if ext in (".html", ".htm"):
            raise web.found("/fs/%s" % encoded_fpath)

        if ext in (".md", ".csv"):
            raise web.found("/code/preview?path=%s" % encoded_fpath)

        if xutils.is_text_file(fpath):
            raise web.found("/code/edit?path=%s" % encoded_fpath)

        raise web.found("/fs/%s" % encoded_fpath)
Esempio n. 6
0
File: fs.py Progetto: ydx2099/xnote
def assemble_file_object(item):
    item.encoded_path = xutils.encode_uri_component(item.path)
    item.icon = "fa-file-o"

    if item.type == "dir":
        item.icon = "fa-folder orange"
    elif item.ext in xconfig.FS_VIDEO_EXT_LIST:
        item.icon = "fa-file-video-o"
    elif item.ext in xconfig.FS_CODE_EXT_LIST:
        item.icon = "fa-file-code-o"
    elif item.ext in xconfig.FS_AUDIO_EXT_LIST:
        item.icon = "fa-file-audio-o"
    elif item.ext in xconfig.FS_ZIP_EXT_LIST:
        item.icon = "fa-file-zip-o"
    elif xutils.is_text_file(item.path):
        item.icon = "fa-file-text-o"
    elif xutils.is_img_file(item.path):
        item.icon = "fa-file-image-o"
    return item
Esempio n. 7
0
    def GET(self):
        key  = xutils.get_argument("key")
        page = xutils.get_argument("page", 1, type=int)
        db   = xtables.get_dict_table()
        where_sql = "key LIKE %s" % left_match_escape(key)
        items = db.select(order="key", where = where_sql, limit=PAGE_SIZE, offset=(page-1)*PAGE_SIZE)
        items = map(convert_dict_func, items)
        count = db.count(where = where_sql)
        page_max = math.ceil(count / PAGE_SIZE)

        return xtemplate.render("dict/dict_list.html", 
            show_aside = True,
            files      = list(items), 
            file_type  = "group",
            show_opts  = False,
            page       = page,
            page_max   = page_max,
            pathlist   = [Storage(name = "词典", url = "#")],
            show_pagination = True,
            page_url   = "/dict/search?key=%s&page=" % encode_uri_component(key), 
            **SEARCH_KEYWORDS)
Esempio n. 8
0
def search(ctx):
    # six.print_(xconfig)
    # 查找`handlers/tools/`目录下的工具
    if not ctx.search_tool:
        return
    name = ctx.key
    tools_path = xconfig.TOOLS_DIR
    files = []
    basename_set = set()
    for filename in os.listdir(tools_path):
        if filename[0] == '_':
            continue
        _filename, ext = os.path.splitext(filename)
        if ext in (".html", ".py"):
            basename_set.add(_filename)

    for filename in basename_set:
        if name in filename:
            f = SearchResult()
            f.icon = "fa-cube"
            f.name = filename
            f.url = "/tools/" + filename
            f.content = filename
            files.append(f)

    if url_pattern.match(name):
        f = SearchResult()
        f.name = "导入笔记 - " + name
        f.url = "/note/html_importer?url=" + xutils.encode_uri_component(name)
        files.append(f)

        f = SearchResult()
        f.name = "二维码"
        f.url = "/tools/qrcode?content=" + name
        files.append(f)
    search_menu(files, name)

    ctx.tools += files
Esempio n. 9
0
def process_file_list(pathlist, parent=None):
    filelist = [FileItem(fpath, parent, merge=True) for fpath in pathlist]
    for item in filelist:
        item.encoded_path = xutils.encode_uri_component(item.path)
        item.icon = "fa-file-o"

        if item.type == "dir":
            item.icon = "fa-folder orange"
        elif item.ext in xconfig.FS_VIDEO_EXT_LIST:
            item.icon = "fa-file-video-o"
        elif item.ext in xconfig.FS_CODE_EXT_LIST:
            item.icon = "fa-file-code-o"
        elif item.ext in xconfig.FS_AUDIO_EXT_LIST:
            item.icon = "fa-file-audio-o"
        elif item.ext in xconfig.FS_ZIP_EXT_LIST:
            item.icon = "fa-file-zip-o"
        elif xutils.is_text_file(item.path):
            item.icon = "fa-file-text-o"
        elif xutils.is_img_file(item.path):
            item.icon = "fa-file-image-o"

    filelist.sort()
    return filelist
Esempio n. 10
0
def build_search_html(content):
    fmt = u'<a href="/message?category=message&key=%s">%s</a>'
    return fmt % (xutils.encode_uri_component(content),
                  xutils.html_escape(content))
Esempio n. 11
0
def redirect_to_login():
    path = web.ctx.fullpath
    raise web.seeother("/login?target=" + xutils.encode_uri_component(path))