-
Notifications
You must be signed in to change notification settings - Fork 0
/
pudatabase.txt
212 lines (193 loc) · 6.61 KB
/
pudatabase.txt
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import os,time
def install():
print("\n*PuDatabase Version1.0*")
print("*" + time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
print("*" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("*成功安装!")
def uninstall():
print("*成功卸载!")
def icheckpath(path):
if path[-1] == "/":
path = path[:-1]
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
for line in dball:
if line.find(path + " ") != -1:
return 1
return 0
def iread(path):
if path[-1] == "/":
path = path[:-1]
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
for line in dball:
if line.find(path + " ") != -1:
line = line.split(" ",1)
line = line[1]
return line[3:-3]
def iset(path,text):
if path[-1] == "/":
path = path[:-1]
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
new = ""
for line in dball:
if line.find(path + " ") != -1:
line = line.split(" ",1)
line = line[0] + " " + text
new = new + line + "\n"
new = new[:-1]
db.close()
db = open(file_path,mode="w")
db.write(new)
db.close()
return "*成功设置内容"
def imkdir(path,dirname):
if path[-1] == "/":
path = path[:-1]
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
new = ""
for line in dball:
if line.find(path + " ") != -1:
ident = line.split(".",1)
ident = ident[0]
line = line + "\n" + ident + "~" + path + "/" + dirname + " ''''''"
new = new + line + "\n"
new = new[:-1]
db.close()
db = open(file_path,mode="w")
db.write(new)
db.close()
return "*成功创建路径"
def ils(path,method):
if path[-1] != "/":
path = path + "/"
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
pathls = ""
for line in dball:
if line.find(path) != -1:
line = line.split(path)
line = line[1]
line = line.split(" ")
line = line[0]
if method == "0" and line.find("/") == -1:
pathls = pathls + line + "\n"
elif method == "1" and line.find("/") == -1:
pathls = pathls + path + line + "\n"
elif method == "2":
pathls = pathls + line + "\n"
elif method == "3":
pathls = pathls + path + line + "\n"
return pathls[:-1]
def idel(path):
if path[-1] == "/":
path = path[:-1]
db = open(file_path,mode="r")
dball = db.read()
dball = dball.split("\n")
new = ""
for line in dball:
if line.find(path) != -1:
line = line.split(" ",1)
line = line[0]
if line.find(path) == -1:
new = new + line + "\n"
else:
new = new + line + "\n"
new = new[:-1]
db.close()
db = open(file_path,mode="w")
db.write(new)
db.close()
return "*成功删除路径"
print("\n*PuDatabase Version1.0*")
print("*" + time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
print("*" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
def path(in_path):
global file_path
file_path = in_path
if os.path.isfile(file_path) == False:
db = open(file_path,mode="w")
db.write(". ''''''")
db.close()
return "*ERROR*未找到数据库文件,已新建数据库*\n"
else:
return "*已导入数据库'" + file_path + "'*\n"
def command(ins):
if ins == "":
ins = "pass"
if ins[0] == ".":
lins = ins.split(" ",2)
if len(lins) == 1:
return("*ERROR*请在路径后输入指令")
elif lins[1] == "read":
if icheckpath(lins[0]) == 0:
return("*ERROR*未找到目标路径")
else:
return(iread(lins[0]))
elif lins[1] == "set":
if len(lins) < 3:
return("*ERROR*未找到参数,请输入完整的参数")
elif icheckpath(lins[0]) == 0:
return("*ERROR*未找到目标路径")
else:
text = lins[2]
if len(text.split("'''")) > 3:
return("*ERROR*一个文本最多可使用两个三单引号")
elif len(text) < 6:
return("*ERROR*请使用三单引号括起文本,如:'''example'''")
elif text[:3] != "'''" or text[-3:] != "'''":
return("*ERROR*请使用三单引号括起文本,如:'''example'''")
else:
return(iset(lins[0],text))
elif lins[1] == "mkdir":
if len(lins) < 3:
return("*ERROR*未找到参数,请输入完整的参数")
elif icheckpath(lins[0]) == 0:
return("*ERROR*未找到目标路径")
else:
dirname =lins[2]
if dirname.find(" ") > -1 or dirname.find("/") > -1:
return("*ERROR*路径名不应含有' '或'/'")
elif dirname == "":
return("*ERROR*路径名不应为空")
elif dirname[-1] == ".":
return("*ERROR*路径名不应以根路径'.'结尾")
else:
return(imkdir(lins[0],dirname))
elif lins[1] == "ls":
if len(lins) < 3:
return("*ERROR*未找到参数,请输入完整的参数")
elif icheckpath(lins[0]) == 0:
return("*ERROR*未找到目标路径")
else:
method =lins[2]
if method != "0" and method != "1" and method != "2" and method != "3":
return("*ERROR*无效的参数\n0-列出下一级路径名 1-列出下一级完整路径名 2-列出所有子路径路径名 3-列出所有子路径完整路径名")
else:
return(ils(lins[0],method))
elif lins[1] == "del":
if icheckpath(lins[0]) == 0:
return("*ERROR*未找到目标路径")
elif lins[0] == "." or lins[0] == "./":
return("*ERROR*根路径不能被删除")
else:
return(idel(lins[0]))
else:
return("*ERROR*未知命令")
def cmd():
file_path = input("*请输入数据库文件路径:")
print(path(file_path))
while 1:
ins = input("*请输入指令:")
if ins == "exit":
break
else:
print(command(ins))