更新文件: webdav_simulator/115.txt, webdav_simulator/sim.txt, webdav_simulator/get115list.py, webdav_simulator/run.sh, webdav_simulator/webdav_simulator.py
This commit is contained in:
70160
webdav_simulator/115.txt
Normal file
70160
webdav_simulator/115.txt
Normal file
File diff suppressed because it is too large
Load Diff
36
webdav_simulator/get115list.py
Normal file
36
webdav_simulator/get115list.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from p115 import P115Client, P115FileSystem
|
||||
import time
|
||||
import traceback
|
||||
|
||||
count=0
|
||||
|
||||
def walk_dir(fs):
|
||||
dirlist=list()
|
||||
file_list = fs.listdir_attr()
|
||||
for file_obj in file_list:
|
||||
if not file_obj.is_directory:
|
||||
print(file_obj.path+"\t"+str(file_obj.size))
|
||||
else:
|
||||
dirlist.append(file_obj.path)
|
||||
for dirItem in dirlist:
|
||||
fs.chdir(dirItem)
|
||||
global count
|
||||
count=count+1
|
||||
if count%5==0:
|
||||
time.sleep(1)
|
||||
walk_dir(fs)
|
||||
return
|
||||
|
||||
def main():
|
||||
cookie="UID=; SEID=; CID="
|
||||
client=P115Client(cookie)
|
||||
|
||||
fs = client.get_share_fs("https://115.com/s/swh9ej13zmi?password=50io")
|
||||
|
||||
count=0
|
||||
walk_dir(fs)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1 +1 @@
|
||||
python webdav_simulator.py sim.txt
|
||||
python webdav_simulator.py 115.txt
|
||||
|
@ -1,2 +1,2 @@
|
||||
/a.txt
|
||||
/b/b.txt
|
||||
/a.txt 7
|
||||
/b/b.txt 7
|
||||
|
@ -12,12 +12,13 @@ import yaml
|
||||
|
||||
class Node:
|
||||
"""虚拟文件系统节点"""
|
||||
def __init__(self, name, is_dir=False):
|
||||
def __init__(self, name, is_dir=False, size=0):
|
||||
self.name = name
|
||||
self.is_dir = is_dir
|
||||
self.children = {}
|
||||
self.content = b""
|
||||
self.last_modified = datetime.now()
|
||||
self.size = size
|
||||
|
||||
def parse_paths(text_lines):
|
||||
"""解析完整路径配置文件"""
|
||||
@ -27,6 +28,14 @@ def parse_paths(text_lines):
|
||||
if not line:
|
||||
continue
|
||||
|
||||
arr = line.split('\t')
|
||||
line = arr[0]
|
||||
size = 0
|
||||
if len(arr)>1:
|
||||
try:
|
||||
size = int(arr[1])
|
||||
except:
|
||||
print("error line:"+line)
|
||||
is_dir = line.endswith('/')
|
||||
stripped = line.strip('/')
|
||||
parts = stripped.split('/') if stripped else []
|
||||
@ -45,7 +54,7 @@ def parse_paths(text_lines):
|
||||
if not parts:
|
||||
# 根目录文件(如 /file.txt)
|
||||
if stripped not in current.children:
|
||||
current.children[stripped] = Node(stripped, is_dir=False)
|
||||
current.children[stripped] = Node(stripped, is_dir=False, size=size)
|
||||
continue
|
||||
|
||||
dirs, file_name = parts[:-1], parts[-1]
|
||||
@ -56,7 +65,7 @@ def parse_paths(text_lines):
|
||||
current.children[part] = Node(part, is_dir=True)
|
||||
current = current.children[part]
|
||||
if file_name not in current.children:
|
||||
current.children[file_name] = Node(file_name, is_dir=False)
|
||||
current.children[file_name] = Node(file_name, is_dir=False, size=size)
|
||||
return root
|
||||
|
||||
class VirtualFSProvider(DAVProvider):
|
||||
@ -112,7 +121,14 @@ class VirtualResource(_DAVResource):
|
||||
def support_etag(self):
|
||||
return True if self.node.is_dir else False
|
||||
def get_content(self):
|
||||
return BytesIO("VIRTUAL".encode())
|
||||
content = "VIRTUAL".encode('utf-8')
|
||||
buf = BytesIO(content)
|
||||
buf.seek(0)
|
||||
return buf
|
||||
def get_content_type(self):
|
||||
return "application/octet-stream"
|
||||
def get_content_length(self):
|
||||
return self.node.size
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='WebDAV路径模拟服务器')
|
||||
|
Reference in New Issue
Block a user