Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
OpenEdx
pyfs
Commits
8d890abf
Commit
8d890abf
authored
Sep 10, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes to add listdir capabilities to ZipFS
parent
fb5a4cc1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletions
+29
-1
fs/zipfs.py
+29
-1
No files found.
fs/zipfs.py
View file @
8d890abf
...
@@ -51,6 +51,13 @@ class ZipFS(FS):
...
@@ -51,6 +51,13 @@ class ZipFS(FS):
if
mode
in
'wa'
:
if
mode
in
'wa'
:
self
.
temp_fs
=
tempfs
.
TempFS
()
self
.
temp_fs
=
tempfs
.
TempFS
()
self
.
resource_list
=
None
if
mode
==
'r'
:
self
.
resource_list
=
self
.
zf
.
namelist
()
def
_get_resource_list
(
self
):
return
self
.
resource_list
or
self
.
zf
.
namelist
()
def
close
(
self
):
def
close
(
self
):
"""Finalizes the zip file so that it can be read.
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
No further operations will work after this method is called."""
...
@@ -90,6 +97,21 @@ class ZipFS(FS):
...
@@ -90,6 +97,21 @@ class ZipFS(FS):
sys_path
=
self
.
temp_fs
.
getsyspath
(
filename
)
sys_path
=
self
.
temp_fs
.
getsyspath
(
filename
)
self
.
zf
.
write
(
sys_path
,
filename
)
self
.
zf
.
write
(
sys_path
,
filename
)
def
listdir
(
self
,
path
=
"/"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
path
=
normpath
(
path
)
def
indir
(
p
):
p
=
makeabsolute
(
p
)
list_dir
=
makeabsolute
(
path
)
sub_path
=
normpath
(
p
[
len
(
list_dir
)
+
1
:])
return
sub_path
and
'/'
not
in
sub_path
paths
=
[
getresourcename
(
p
.
rstrip
(
'/'
))
for
p
in
self
.
_get_resource_list
()
if
indir
(
p
.
rstrip
(
'/'
))]
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
def
test
():
def
test
():
zfs
=
ZipFS
(
"t.zip"
,
"w"
)
zfs
=
ZipFS
(
"t.zip"
,
"w"
)
...
@@ -98,5 +120,11 @@ if __name__ == "__main__":
...
@@ -98,5 +120,11 @@ if __name__ == "__main__":
rfs
=
ZipFS
(
"t.zip"
,
'r'
)
rfs
=
ZipFS
(
"t.zip"
,
'r'
)
print
rfs
.
getcontents
(
"t.txt"
)
print
rfs
.
getcontents
(
"t.txt"
)
print
rfs
.
getcontents
(
"w.txt"
)
print
rfs
.
getcontents
(
"w.txt"
)
test
()
def
test2
():
zfs
=
ZipFS
(
"t2.zip"
,
"r"
)
print
zfs
.
listdir
(
"/tagging-trunk"
)
print
zfs
.
listdir
(
"/"
)
test2
()
#zfs.close()
#zfs.close()
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