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
fb5a4cc1
Commit
fb5a4cc1
authored
Sep 09, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress for the zip filesystem
parent
7f5736e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
fs/fs.py
+15
-0
fs/zipfs.py
+9
-5
No files found.
fs/fs.py
View file @
fb5a4cc1
...
@@ -352,6 +352,21 @@ class FS(object):
...
@@ -352,6 +352,21 @@ class FS(object):
if
f
is
not
None
:
if
f
is
not
None
:
f
.
close
()
f
.
close
()
def
createfile
(
self
,
path
,
data
):
"""A convenience method to create a new file from a string.
path -- Path of the file to create
data -- A string containing the contents of the file
"""
f
=
None
try
:
f
=
self
.
open
(
path
,
'wb'
)
f
.
write
(
data
)
finally
:
if
f
is
not
None
:
f
.
close
()
def
opendir
(
self
,
path
):
def
opendir
(
self
,
path
):
if
not
self
.
exists
(
path
):
if
not
self
.
exists
(
path
):
raise
ResourceNotFoundError
(
"NO_DIR"
,
path
)
raise
ResourceNotFoundError
(
"NO_DIR"
,
path
)
...
...
fs/zipfs.py
View file @
fb5a4cc1
...
@@ -52,6 +52,9 @@ class ZipFS(FS):
...
@@ -52,6 +52,9 @@ class ZipFS(FS):
self
.
temp_fs
=
tempfs
.
TempFS
()
self
.
temp_fs
=
tempfs
.
TempFS
()
def
close
(
self
):
def
close
(
self
):
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
if
self
.
zf
is
not
None
:
if
self
.
zf
is
not
None
:
self
.
zf
.
close
()
self
.
zf
.
close
()
self
.
zf
=
None
self
.
zf
=
None
...
@@ -66,7 +69,10 @@ class ZipFS(FS):
...
@@ -66,7 +69,10 @@ class ZipFS(FS):
if
'r'
in
mode
:
if
'r'
in
mode
:
if
self
.
zip_mode
not
in
'ra'
:
if
self
.
zip_mode
not
in
'ra'
:
raise
OperationFailedError
(
"OPEN_FAILED"
,
path
=
path
,
msg
=
"Zip file must be opened for reading ('r') or appending ('a')"
)
raise
OperationFailedError
(
"OPEN_FAILED"
,
path
=
path
,
msg
=
"Zip file must be opened for reading ('r') or appending ('a')"
)
contents
=
self
.
zf
.
read
(
path
)
try
:
contents
=
self
.
zf
.
read
(
path
)
except
KeyError
:
raise
ResourceNotFoundError
(
"NO_FILE"
,
path
)
return
StringIO
(
contents
)
return
StringIO
(
contents
)
if
'w'
in
mode
:
if
'w'
in
mode
:
...
@@ -87,12 +93,10 @@ class ZipFS(FS):
...
@@ -87,12 +93,10 @@ class ZipFS(FS):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
def
test
():
def
test
():
zfs
=
ZipFS
(
"t.zip"
,
"w"
)
zfs
=
ZipFS
(
"t.zip"
,
"w"
)
f
=
zfs
.
open
(
"t.txt"
,
'w'
)
zfs
.
createfile
(
"t.txt"
,
"Hello, World!"
)
f
.
write
(
"Hello, World!"
)
f
.
close
()
zfs
.
close
()
zfs
.
close
()
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"
)
test
()
test
()
#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