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
349ba37b
Commit
349ba37b
authored
Jun 30, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0ab79981
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
85 deletions
+76
-85
tools/README.md
tools/README.md
+9
-0
tools/modules/file-manager/main.py
tools/modules/file-manager/main.py
+55
-85
tools/modules/file-manager/result.json
tools/modules/file-manager/result.json
+12
-0
No files found.
tools/README.md
View file @
349ba37b
<!--
*
@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:
\e
vm-store
\t
ools
\R
EADME.md
-->
# 代码生成工具
# 代码生成工具
使用Python Jinja2模板引擎,自动生成代码。
使用Python Jinja2模板引擎,自动生成代码。
...
@@ -12,6 +20,7 @@
...
@@ -12,6 +20,7 @@
-
https://flask-marshmallow.readthedocs.io/en/latest/
-
https://flask-marshmallow.readthedocs.io/en/latest/
-
https://docs.pyfilesystem.org/en/latest/index.html
-
https://docs.pyfilesystem.org/en/latest/index.html
-
https://jinja.palletsprojects.com/en/3.0.x/
-
https://jinja.palletsprojects.com/en/3.0.x/
-
https://www.jb51.net/article/205786.htm
# 问题
# 问题
...
...
tools/modules/file-manager/main.py
View file @
349ba37b
'''
'''
Author: your name
Author: your name
Date: 2021-06-21 14:52:24
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
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
...
@@ -49,10 +49,11 @@ class FileManager(object):
...
@@ -49,10 +49,11 @@ class FileManager(object):
}
}
# 这里需要过滤,有些目录只能管理员才能查看
# 这里需要过滤,有些目录只能管理员才能查看
for
d
in
os
.
listdir
(
disk_root
):
p
=
Path
(
disk_root
)
if
os
.
path
.
isdir
(
os
.
sep
.
join
([
disk_root
,
d
])):
for
child
in
p
.
iterdir
():
if
child
.
is_dir
():
result
[
"disks"
]
.
update
({
result
[
"disks"
]
.
update
({
d
:
{
"driver"
:
"local"
}
child
.
name
:
{
"driver"
:
"local"
}
})
})
return
result
return
result
...
@@ -93,65 +94,45 @@ class FileManager(object):
...
@@ -93,65 +94,45 @@ class FileManager(object):
}
}
'''
'''
sys_str
=
platform
.
system
()
target_path
=
Path
(
target_path
)
# disk = "uploads" # 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
=
Path
(
disk_root
)
.
joinpath
(
disk
)
if
not
os
.
path
.
exists
(
disk_path
):
if
not
disk_path
.
exists
():
return
result
if
not
os
.
path
.
exists
(
os
.
path
.
normpath
(
os
.
sep
.
join
([
disk_path
,
target_path
]))):
return
result
return
result
os
.
chdir
(
disk_path
)
target_path
=
disk_path
.
joinpath
(
target_path
)
home_fs
=
open_fs
(
'.'
)
if
not
target_path
.
exists
():
return
result
for
file
in
home_fs
.
scandir
(
target_path
,
namespaces
=
[
'details'
]
):
for
child
in
target_path
.
iterdir
(
):
if
file
.
is_dir
:
if
child
.
is_dir
()
:
tmp
=
{
result
[
"directories"
]
.
append
(
{
"basename"
:
file
.
name
,
"basename"
:
child
.
name
,
"dirname"
:
os
.
path
.
basename
(
target_path
),
"dirname"
:
child
.
parent
.
relative_to
(
disk_path
)
.
as_posix
(
),
"path"
:
os
.
path
.
normpath
(
os
.
sep
.
join
([
target_path
,
file
.
name
])
),
"path"
:
child
.
resolve
()
.
relative_to
(
disk_path
)
.
as_posix
(
),
"timestamp"
:
int
(
file
.
raw
.
get
(
"details"
)
.
get
(
"modified"
)
),
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"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
)
result
[
"files"
]
.
append
({
tmp
=
{
"basename"
:
child
.
name
,
"basename"
:
file
.
name
,
"dirname"
:
child
.
parent
,
"dirname"
:
os
.
path
.
basename
(
target_path
),
"extension"
:
child
.
suffix
[
1
:],
"extension"
:
ex
[
1
:],
"filename"
:
child
.
stem
,
"filename"
:
fn
,
"path"
:
child
.
resolve
()
.
relative_to
(
disk_path
)
.
as_posix
(),
"path"
:
os
.
path
.
normpath
(
os
.
sep
.
join
([
target_path
,
file
.
name
])),
"size"
:
child
.
stat
()
.
st_size
,
"size"
:
file
.
size
,
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"timestamp"
:
int
(
file
.
raw
.
get
(
"details"
)
.
get
(
"modified"
)),
"type"
:
"file"
"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
:
with
open
(
"result.json"
,
"w"
)
as
f
:
json
.
dump
(
result
,
f
)
json
.
dump
(
result
,
f
)
f
.
seek
(
0
)
f
.
truncate
()
f
.
write
(
json
.
dumps
(
result
,
ensure_ascii
=
True
))
f
.
write
(
json
.
dumps
(
result
,
ensure_ascii
=
True
))
pprint
.
pprint
(
result
)
pprint
.
pprint
(
result
)
...
@@ -176,42 +157,31 @@ class FileManager(object):
...
@@ -176,42 +157,31 @@ class FileManager(object):
}
}
'''
'''
if
not
target_path
.
startswith
(
"/"
):
target_path
=
Path
(
target_path
)
target_path
=
"/"
+
target_path
result
=
[]
result
=
[]
rp
=
Path
(
disk_root
)
disk_path
=
os
.
sep
.
join
([
disk_root
,
disk
])
disk_path
=
rp
/
disk
if
not
os
.
path
.
exists
(
disk_path
):
if
not
disk_path
.
exists
():
return
result
if
not
os
.
path
.
exists
(
os
.
path
.
normpath
(
os
.
sep
.
join
([
disk_path
,
target_path
]))):
return
result
return
result
os
.
chdir
(
disk_path
)
temp_path
=
disk_path
.
joinpath
(
target_path
)
home_fs
=
OSFS
(
os
.
getcwd
())
if
not
temp_path
.
exists
():
return
result
rp
=
Path
(
disk_root
)
print
(
"
%%%%
"
,
rp
)
p
=
Path
(
disk_path
)
p
=
Path
(
disk_path
)
for
child
in
p
.
iterdir
():
for
child
in
p
.
iterdir
():
print
(
"//////////"
,
child
.
is_dir
(),
child
.
resolve
(),
child
.
name
,
child
.
parent
,
child
.
root
,
child
.
drive
,
child
.
relative_to
(
rp
))
if
child
.
is_dir
():
print
(
"------------------->"
,
p
)
# 获取当前目录下所有目录、文件、子目录以及子文件的信息。递归获取
for
step
in
home_fs
.
walk
():
result
.
append
({
result
.
append
({
"basename"
:
os
.
path
.
basename
(
step
.
path
)
,
"basename"
:
child
.
name
,
"dirname"
:
os
.
path
.
dirname
(
step
.
path
),
"dirname"
:
child
.
parent
.
relative_to
(
rp
)
.
as_posix
(
),
"path"
:
step
.
path
,
"path"
:
child
.
relative_to
(
rp
)
.
as_posix
()
,
"props"
:
{
"props"
:
{
"hasSubdirectories"
:
True
if
len
(
step
.
files
)
else
False
"hasSubdirectories"
:
True
if
os
.
listdir
(
child
.
resolve
()
)
else
False
},
},
# "timestamp": int(os.path.getatime(os.sep.join([target_path, step.path]))
),
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"type"
:
"dir"
"type"
:
"dir"
})
})
# print("//////////", child.is_dir(), child.resolve(), child.name, child.parent, child.root, child.relative_to(rp))
home_fs
.
close
()
pprint
.
pprint
(
result
)
pprint
.
pprint
(
result
)
return
result
return
result
...
@@ -227,11 +197,11 @@ if __name__ == "__main__":
...
@@ -227,11 +197,11 @@ if __name__ == "__main__":
# def test():
# def test():
# pass
# pass
#
result = fileManager.initialize()
result
=
fileManager
.
initialize
()
# print(
result)
print
(
"----->"
,
result
)
#
result = fileManager.content("uploads", "evueapps/evm")
result
=
fileManager
.
content
(
"uploads"
,
"evueapps/evm"
)
# print(
result)
print
(
">>>>>>"
,
result
)
result
=
fileManager
.
tree
(
"uploads"
,
"evueapps/evm"
)
result
=
fileManager
.
tree
(
"uploads"
,
"evueapps/evm"
)
print
(
result
)
print
(
"=====>"
,
result
)
\ No newline at end of file
\ No newline at end of file
tools/modules/file-manager/result.json
0 → 100644
View file @
349ba37b
{
"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
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