Commit 349ba37b authored by wanli's avatar wanli

update

parent 0ab79981
<!--
* @Author: your name
* @Date: 2021-04-22 18:04:01
* @LastEditTime: 2021-06-30 11:24:58
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \evm-store\tools\README.md
-->
# 代码生成工具
使用Python Jinja2模板引擎,自动生成代码。
......@@ -12,6 +20,7 @@
- https://flask-marshmallow.readthedocs.io/en/latest/
- https://docs.pyfilesystem.org/en/latest/index.html
- https://jinja.palletsprojects.com/en/3.0.x/
- https://www.jb51.net/article/205786.htm
# 问题
......
'''
Author: your name
Date: 2021-06-21 14:52:24
LastEditTime: 2021-06-29 16:33:06
LastEditTime: 2021-06-30 12:27:59
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\modules\file-manager\main.py
......@@ -49,10 +49,11 @@ class FileManager(object):
}
# 这里需要过滤,有些目录只能管理员才能查看
for d in os.listdir(disk_root):
if os.path.isdir(os.sep.join([disk_root, d])):
p = Path(disk_root)
for child in p.iterdir():
if child.is_dir():
result["disks"].update({
d: { "driver": "local" }
child.name: { "driver": "local" }
})
return result
......@@ -93,65 +94,45 @@ class FileManager(object):
}
'''
sys_str = platform.system()
# disk = "uploads" # disk就是文件根目录,只能以某个目录为根目录,浏览这个目录下面的所有文件
# target_path = None # 就是以disk为根目录的路径,判断是否以**/**或者**\\**开头
if not target_path.startswith("/"):
target_path = "/" + target_path
target_path = Path(target_path)
result = {
"directories": [],
"files": []
}
disk_path = os.sep.join([disk_root, disk])
if not os.path.exists(disk_path):
disk_path = Path(disk_root).joinpath(disk)
if not disk_path.exists():
return result
if not os.path.exists(os.path.normpath(os.sep.join([disk_path, target_path]))):
target_path = disk_path.joinpath(target_path)
if not target_path.exists():
return result
os.chdir(disk_path)
home_fs = open_fs('.')
for file in home_fs.scandir(target_path, namespaces=['details']):
if file.is_dir:
tmp = {
"basename": file.name,
"dirname": os.path.basename(target_path),
"path": os.path.normpath(os.sep.join([target_path, file.name])),
"timestamp": int(file.raw.get("details").get("modified")),
for child in target_path.iterdir():
if child.is_dir():
result["directories"].append({
"basename": child.name,
"dirname": child.parent.relative_to(disk_path).as_posix(),
"path": child.resolve().relative_to(disk_path).as_posix(),
"timestamp": int(child.stat().st_mtime),
"type": "dir"
}
if (sys_str == "Windows"):
p = PureWindowsPath(tmp.get("path"))
tmp["path"] = str(p.relative_to("\\"))
else:
p = PurePosixPath(tmp.get("path"))
tmp["path"] = str(p.relative_to('/'))
result["directories"].append(tmp)
})
else:
fn, ex = os.path.splitext(file.name)
tmp = {
"basename": file.name,
"dirname": os.path.basename(target_path),
"extension": ex[1:],
"filename": fn,
"path": os.path.normpath(os.sep.join([target_path, file.name])),
"size": file.size,
"timestamp": int(file.raw.get("details").get("modified")),
result["files"].append({
"basename": child.name,
"dirname": child.parent,
"extension": child.suffix[1:],
"filename": child.stem,
"path": child.resolve().relative_to(disk_path).as_posix(),
"size": child.stat().st_size,
"timestamp": int(child.stat().st_mtime),
"type": "file"
}
if (sys_str == "Windows"):
p = PureWindowsPath(tmp.get("path"))
tmp["path"] = str(p.relative_to("\\"))
else:
p = PurePosixPath(tmp.get("path"))
tmp["path"] = str(p.relative_to('/'))
result["files"].append(tmp)
home_fs.close()
})
with open("result.json", "w") as f:
json.dump(result, f)
f.seek(0)
f.truncate()
f.write(json.dumps(result, ensure_ascii=True))
pprint.pprint(result)
......@@ -176,42 +157,31 @@ class FileManager(object):
}
'''
if not target_path.startswith("/"):
target_path = "/" + target_path
target_path = Path(target_path)
result = []
disk_path = os.sep.join([disk_root, disk])
if not os.path.exists(disk_path):
return result
if not os.path.exists(os.path.normpath(os.sep.join([disk_path, target_path]))):
rp = Path(disk_root)
disk_path = rp / disk
if not disk_path.exists():
return result
os.chdir(disk_path)
home_fs = OSFS(os.getcwd())
temp_path = disk_path.joinpath(target_path)
if not temp_path.exists():
return result
rp = Path(disk_root)
print("%%%%", rp)
p = Path(disk_path)
for child in p.iterdir():
print("//////////", child.is_dir(), child.resolve(), child.name, child.parent, child.root, child.drive, child.relative_to(rp))
print("------------------->", p)
# 获取当前目录下所有目录、文件、子目录以及子文件的信息。递归获取
for step in home_fs.walk():
result.append({
"basename": os.path.basename(step.path),
"dirname": os.path.dirname(step.path),
"path": step.path,
"props": {
"hasSubdirectories": True if len(step.files) else False
},
# "timestamp": int(os.path.getatime(os.sep.join([target_path, step.path]))),
"type": "dir"
})
home_fs.close()
if child.is_dir():
result.append({
"basename": child.name,
"dirname": child.parent.relative_to(rp).as_posix(),
"path": child.relative_to(rp).as_posix(),
"props": {
"hasSubdirectories": True if os.listdir(child.resolve()) else False
},
"timestamp": int(child.stat().st_mtime),
"type": "dir"
})
# print("//////////", child.is_dir(), child.resolve(), child.name, child.parent, child.root, child.relative_to(rp))
pprint.pprint(result)
return result
......@@ -227,11 +197,11 @@ if __name__ == "__main__":
# def test():
# pass
# result = fileManager.initialize()
# print(result)
result = fileManager.initialize()
print("----->", result)
# result = fileManager.content("uploads", "evueapps/evm")
# print(result)
result = fileManager.content("uploads", "evueapps/evm")
print(">>>>>>", result)
result = fileManager.tree("uploads", "evueapps/evm")
print(result)
\ No newline at end of file
print("=====>", result)
\ No newline at end of file
{
"directories": [
{
"basename": "evue_launcher-1.0-20210420145404",
"dirname": "evueapps/evm",
"path": "evueapps/evm/evue_launcher-1.0-20210420145404",
"timestamp": 1618901645,
"type": "dir"
}
],
"files": []
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment