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
0d2f59a5
Commit
0d2f59a5
authored
Jul 23, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress for memory fs
parent
06ddab8a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
8 deletions
+58
-8
fs/fs.py
+1
-1
fs/memoryfs.py
+57
-7
No files found.
fs/fs.py
View file @
0d2f59a5
...
@@ -39,7 +39,7 @@ class NullFile:
...
@@ -39,7 +39,7 @@ class NullFile:
def
truncate
(
self
,
*
args
,
**
kwargs
):
def
truncate
(
self
,
*
args
,
**
kwargs
):
return
0
return
0
def
write
(
self
,
str
):
def
write
(
self
,
data
):
pass
pass
def
writelines
(
self
,
*
args
,
**
kwargs
):
def
writelines
(
self
,
*
args
,
**
kwargs
):
...
...
fs/memoryfs.py
View file @
0d2f59a5
...
@@ -7,21 +7,67 @@ try:
...
@@ -7,21 +7,67 @@ try:
except
ImportError
:
except
ImportError
:
from
StringIO
import
StringIO
from
StringIO
import
StringIO
class
MemoryFile
(
StringIO
):
class
MemoryFile
(
object
):
def
__init__
(
self
,
path
,
memory_fs
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
path
,
memory_fs
,
value
,
mode
):
self
.
path
=
path
self
.
path
=
path
self
.
memory_fs
=
memory_fs
self
.
memory_fs
=
memory_fs
self
.
mode
=
mode
def
check_mode
(
mode_chars
):
for
c
in
mode_chars
:
if
c
not
in
mode
:
return
False
return
True
if
check_mode
(
'w'
):
self
.
mem_file
=
StringIO
()
if
check_mode
(
'+'
):
self
.
mem_file
.
write
(
value
)
elif
check_mode
(
'r'
):
self
.
mem_file
=
StringIO
(
value
)
self
.
mem_file
=
None
StringIO
.
__init__
(
*
args
,
**
kwargs
)
def
flush
(
self
):
pass
def
__iter__
(
self
):
return
iter
(
self
.
mem_file
)
def
next
(
self
):
return
self
.
mem_file
.
next
()
def
readline
(
self
,
*
args
,
**
kwargs
):
return
self
.
mem_file
.
readline
(
*
args
,
**
kwargs
)
def
close
():
def
close
():
value
=
self
.
get_vale
()
value
=
self
.
get_vale
()
self
.
memory_fs
.
_on_close_memory_file
(
path
,
value
)
self
.
memory_fs
.
_on_close_memory_file
(
path
,
value
)
StringIO
.
close
(
self
)
StringIO
.
close
(
self
)
def
read
(
self
,
size
=
None
):
return
self
.
mem_file
.
read
(
size
)
def
seek
(
self
,
*
args
,
**
kwargs
):
return
self
.
mem_file
.
seek
(
*
args
,
**
kwargs
)
def
tell
(
self
):
return
self
.
mem_file
.
tell
()
def
truncate
(
self
,
*
args
,
**
kwargs
):
return
self
.
mem_file
.
truncate
(
*
args
,
**
kwargs
)
def
write
(
self
,
data
):
return
self
.
mem_file
.
write
(
data
)
def
writelines
(
self
,
*
args
,
**
kwargs
):
return
self
.
mem_file
.
writelines
(
*
args
,
**
kwargs
)
...
@@ -42,7 +88,7 @@ class MemoryFS(FS):
...
@@ -42,7 +88,7 @@ class MemoryFS(FS):
def
desc_contents
(
self
):
def
desc_contents
(
self
):
if
self
.
isfile
():
if
self
.
isfile
():
return
"<file
>"
return
"<file
%
s>"
%
self
.
name
elif
self
.
isdir
():
elif
self
.
isdir
():
return
"<dir
%
s>"
%
""
.
join
(
"
%
s:
%
s"
%
(
k
,
v
.
desc_contents
())
for
k
,
v
in
self
.
contents
.
iteritems
())
return
"<dir
%
s>"
%
""
.
join
(
"
%
s:
%
s"
%
(
k
,
v
.
desc_contents
())
for
k
,
v
in
self
.
contents
.
iteritems
())
...
@@ -55,11 +101,13 @@ class MemoryFS(FS):
...
@@ -55,11 +101,13 @@ class MemoryFS(FS):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s:
%
s"
%
(
self
.
name
,
self
.
desc_contents
())
return
"
%
s:
%
s"
%
(
self
.
name
,
self
.
desc_contents
())
class
FileEntry
(
object
):
class
FileEntry
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
memory_file
=
None
self
.
memory_file
=
None
self
.
value
=
""
self
.
value
=
""
def
_make_dir_entry
(
self
,
*
args
,
**
kwargs
):
def
_make_dir_entry
(
self
,
*
args
,
**
kwargs
):
...
@@ -200,4 +248,6 @@ if __name__ == "__main__":
...
@@ -200,4 +248,6 @@ if __name__ == "__main__":
#print mem_fs.isdir("test/test2")
#print mem_fs.isdir("test/test2")
#print mem_fs.root
#print mem_fs.root
print_fs
(
mem_fs
)
print_fs
(
mem_fs
)
\ No newline at end of file
from
browsewin
import
browse
browse
(
mem_fs
)
\ 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