更新文件: 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
|
/a.txt 7
|
||||||
/b/b.txt
|
/b/b.txt 7
|
||||||
|
@ -12,12 +12,13 @@ import yaml
|
|||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
"""虚拟文件系统节点"""
|
"""虚拟文件系统节点"""
|
||||||
def __init__(self, name, is_dir=False):
|
def __init__(self, name, is_dir=False, size=0):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.is_dir = is_dir
|
self.is_dir = is_dir
|
||||||
self.children = {}
|
self.children = {}
|
||||||
self.content = b""
|
self.content = b""
|
||||||
self.last_modified = datetime.now()
|
self.last_modified = datetime.now()
|
||||||
|
self.size = size
|
||||||
|
|
||||||
def parse_paths(text_lines):
|
def parse_paths(text_lines):
|
||||||
"""解析完整路径配置文件"""
|
"""解析完整路径配置文件"""
|
||||||
@ -27,6 +28,14 @@ def parse_paths(text_lines):
|
|||||||
if not line:
|
if not line:
|
||||||
continue
|
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('/')
|
is_dir = line.endswith('/')
|
||||||
stripped = line.strip('/')
|
stripped = line.strip('/')
|
||||||
parts = stripped.split('/') if stripped else []
|
parts = stripped.split('/') if stripped else []
|
||||||
@ -45,7 +54,7 @@ def parse_paths(text_lines):
|
|||||||
if not parts:
|
if not parts:
|
||||||
# 根目录文件(如 /file.txt)
|
# 根目录文件(如 /file.txt)
|
||||||
if stripped not in current.children:
|
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
|
continue
|
||||||
|
|
||||||
dirs, file_name = parts[:-1], parts[-1]
|
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.children[part] = Node(part, is_dir=True)
|
||||||
current = current.children[part]
|
current = current.children[part]
|
||||||
if file_name not in current.children:
|
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
|
return root
|
||||||
|
|
||||||
class VirtualFSProvider(DAVProvider):
|
class VirtualFSProvider(DAVProvider):
|
||||||
@ -112,7 +121,14 @@ class VirtualResource(_DAVResource):
|
|||||||
def support_etag(self):
|
def support_etag(self):
|
||||||
return True if self.node.is_dir else False
|
return True if self.node.is_dir else False
|
||||||
def get_content(self):
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='WebDAV路径模拟服务器')
|
parser = argparse.ArgumentParser(description='WebDAV路径模拟服务器')
|
||||||
|
Reference in New Issue
Block a user