Commit 4d128676 authored by wanli's avatar wanli

update

parent cbb728ad
''' '''
Author: your name Author: your name
Date: 2021-06-21 14:52:24 Date: 2021-06-21 14:52:24
LastEditTime: 2021-06-22 12:08:31 LastEditTime: 2021-06-23 11:51:02
LastEditors: Please set LastEditors LastEditors: Please set LastEditors
Description: In User Settings Edit Description: In User Settings Edit
FilePath: \evm-store\tools\modules\file-manager\main.py FilePath: \evm-store\tools\modules\file-manager\main.py
...@@ -10,6 +10,8 @@ FilePath: \evm-store\tools\modules\file-manager\main.py ...@@ -10,6 +10,8 @@ FilePath: \evm-store\tools\modules\file-manager\main.py
import os import os
import shutil import shutil
import pprint import pprint
from pathlib import PurePosixPath, PureWindowsPath
import platform
import json import json
from fs.osfs import OSFS from fs.osfs import OSFS
from fs import open_fs from fs import open_fs
...@@ -90,80 +92,62 @@ class FileManager(object): ...@@ -90,80 +92,62 @@ class FileManager(object):
type: "file" type: "file"
} }
''' '''
sys_str = platform.system()
# disk = "uploads" # disk就是文件根目录,只能以某个目录为根目录,浏览这个目录下面的所有文件 # disk = "uploads" # disk就是文件根目录,只能以某个目录为根目录,浏览这个目录下面的所有文件
# target_path = None # 就是以disk为根目录的路径 # target_path = None # 就是以disk为根目录的路径,判断是否以**/**或者**\\**开头
if not target_path.startswith("/"):
target_path = "/" + target_path
result = { result = {
"directories": [], "directories": [],
"files": [] "files": []
} }
disk_path = os.sep.join([disk_root, disk]) disk_path = os.sep.join([disk_root, disk])
if not os.path.exists(disk_path): if not os.path.exists(disk_path):
return result return result
if not os.path.exists(os.path.normpath(os.sep.join([disk_path, target_path]))): if not os.path.exists(os.path.normpath(os.sep.join([disk_path, target_path]))):
return result return result
os.chdir(disk_path) os.chdir(disk_path)
print(os.getcwd())
home_fs = open_fs('.') home_fs = open_fs('.')
print(home_fs.tree())
for file in home_fs.scandir(target_path, namespaces=['details']): for file in home_fs.scandir(target_path, namespaces=['details']):
if file.is_dir: if file.is_dir:
result["directories"].append({ tmp = {
"basename": file.name, "basename": file.name,
"dirname": os.path.basename(target_path), "dirname": os.path.basename(target_path),
"path": os.sep.join([target_path, file.name]), "path": os.path.normpath(os.sep.join([target_path, file.name])),
"timestamp": int(file.raw.get("details").get("modified")), "timestamp": int(file.raw.get("details").get("modified")),
"type": "dir" "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: else:
fn, ex = os.path.splitext(file.name) fn, ex = os.path.splitext(file.name)
result["files"].append({ tmp = {
"basename": file.name, "basename": file.name,
"dirname": os.path.basename(target_path), "dirname": os.path.basename(target_path),
"extension": ex[1:], "extension": ex[1:],
"filename": fn, "filename": fn,
"path": os.sep.join([target_path, file.name]), "path": os.path.normpath(os.sep.join([target_path, file.name])),
"size": file.size, "size": file.size,
"timestamp": int(file.raw.get("details").get("modified")), "timestamp": int(file.raw.get("details").get("modified")),
"type": "file" "type": "file"
}) }
print("//////////////////>>>>>>", file.name, file.size, file.suffix, file.path, dir(file)) if (sys_str == "Windows"):
p = PureWindowsPath(tmp.get("path"))
# for file in os.listdir(target_path): tmp["path"] = str(p.relative_to("\\"))
# print(">>>>>>>>>>>>>>>", os.getcwd(), os.path.relpath(target_path, os.getcwd())) else:
# if os.path.isdir(os.sep.join([target_path, file])): p = PurePosixPath(tmp.get("path"))
# result["directories"].append({ tmp["path"] = str(p.relative_to('/'))
# "basename": os.path.basename(file), result["files"].append(tmp)
# "dirname": os.path.basename(target_path),
# "path": os.path.relpath(os.getcwd(), target_path),
# "timestamp": int(os.path.getatime(os.sep.join([target_path, file]))),
# "type": "dir"
# })
# else:
# fn, ex = os.path.splitext(file)
# result["files"].append({
# "basename": file,
# "dirname": os.path.basename(target_path),
# "extension": ex,
# "filename": fn,
# "path": os.path.relpath(os.getcwd(), os.sep.join([target_path, file])),
# "size": os.path.getsize(os.sep.join([target_path, file])),
# "timestamp": int(os.path.getmtime(os.sep.join([target_path, file]))),
# "type": "file"
# })
# print("file", file)
# for root, dirs, files in os.walk(os.getcwd(), topdown=False):
# for name in dirs:
# print(os.path.join(root, name), name)
# for name in files:
# print(os.path.join(root, name), name)
home_fs.close() home_fs.close()
with open("result.json", "w") as f: with open("result.json", "w") as f:
...@@ -193,8 +177,14 @@ class FileManager(object): ...@@ -193,8 +177,14 @@ class FileManager(object):
} }
''' '''
target_path = "./" # for root, dirs, files in os.walk(os.getcwd(), topdown=False):
# for name in dirs:
# print(os.path.join(root, name), name)
# for name in files:
# print(os.path.join(root, name), name)
target_path = "./"
home_fs = OSFS(os.getcwd()) home_fs = OSFS(os.getcwd())
# 获取当前目录下所有目录、文件、子目录以及子文件的信息。递归获取 # 获取当前目录下所有目录、文件、子目录以及子文件的信息。递归获取
...@@ -243,5 +233,5 @@ if __name__ == "__main__": ...@@ -243,5 +233,5 @@ if __name__ == "__main__":
result = fileManager.initialize() result = fileManager.initialize()
print(result) print(result)
result = fileManager.content("uploads") result = fileManager.content("uploads", "evueapps/evm")
print(result) print(result)
\ 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