-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
70 lines (45 loc) · 1.3 KB
/
util.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
def is_install():
return "bookmark" in set(os.listdir("/usr/local/bin"))
def root_path():
util_path = os.path.realpath(__file__)
util_path_list = util_path.split("/")
return "/".join(util_path_list[:-1])
def path_join(*args):
arg_list = list(args)
arg_list.insert(0, root_path())
return os.path.join(*arg_list)
def storage_path():
return path_join("pages")
def file_exist(path):
return os.path.exists(path)
def system(command):
return os.system(command)
def create_storage_dir():
path = storage_path()
if not os.path.exists(path):
os.mkdir(path)
def pages():
path = storage_path()
if not os.path.isdir(path):
return set()
file_list = os.listdir(storage_path())
page_set = set()
for file in file_list:
if not is_json_file(file):
continue
name_list = file.split(".")
name_list.pop(-1)
page_set.add(".".join(name_list))
return page_set
def is_json_file(filename):
filename = filename.strip(".")
if "." not in filename:
return False
filename_list = filename.split(".")
return filename_list[-1] == "json"
def delete_file(path):
if not os.path.isfile(path):
return
command = "rm -rf %s" % path
return os.system(command) == 0