Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
evm-store
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanli
evm-store
Commits
4d128676
Commit
4d128676
authored
Jun 23, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
cbb728ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
47 deletions
+37
-47
tools/modules/file-manager/main.py
tools/modules/file-manager/main.py
+37
-47
No files found.
tools/modules/file-manager/main.py
View file @
4d128676
'''
'''
Author: your name
Author: your name
Date: 2021-06-21 14:52:24
Date: 2021-06-21 14:52:24
LastEditTime: 2021-06-2
2 12:08:31
LastEditTime: 2021-06-2
3 11:51:02
LastEditors: Please set LastEditors
LastEditors: Please set LastEditors
Description: In User Settings Edit
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\
modules
\f
ile-manager
\
main.py
FilePath:
\
evm-store
\t
ools
\
modules
\f
ile-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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment