-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_file.py
44 lines (33 loc) · 1.02 KB
/
read_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
[CN]
该 Script Filter 的功能是展示 file.txt 文件中的内容. 仅仅是和 ``write_file.py`` 模块
配合使用, 永远验证.
"""
import attrs
import afwf.api as afwf
from ..paths import dir_project_home
path_file = dir_project_home / "file.txt"
path_file.parent.mkdir(parents=True, exist_ok=True)
if path_file.exists() is False:
path_file.write_text("hello world")
@attrs.define
class Handler(afwf.Handler):
def main(self) -> afwf.ScriptFilter:
sf = afwf.ScriptFilter()
if path_file.exists():
content = path_file.read_text()
item = afwf.Item(
title=f"content of {path_file} is",
subtitle=content,
)
else:
item = afwf.Item(
title=f"{path_file} does not exist!",
)
item.set_icon(afwf.IconFileEnum.error)
sf.items.append(item)
return sf
def parse_query(self, query: str):
return {}
handler = Handler(id="read_file")