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
9408f48d
Commit
9408f48d
authored
Jul 23, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress for memoryfs
parent
af923a7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
4 deletions
+54
-4
fs/memoryfs.py
+54
-4
No files found.
fs/memoryfs.py
View file @
9408f48d
...
@@ -52,8 +52,7 @@ class MemoryFile(object):
...
@@ -52,8 +52,7 @@ class MemoryFile(object):
def
readline
(
self
,
*
args
,
**
kwargs
):
def
readline
(
self
,
*
args
,
**
kwargs
):
return
self
.
mem_file
.
readline
(
*
args
,
**
kwargs
)
return
self
.
mem_file
.
readline
(
*
args
,
**
kwargs
)
def
close
():
def
close
(
self
):
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
)
...
@@ -94,6 +93,19 @@ class MemoryFS(FS):
...
@@ -94,6 +93,19 @@ class MemoryFS(FS):
self
.
contents
=
contents
self
.
contents
=
contents
self
.
num_reading
=
0
self
.
num_writing
=
0
self
.
data
=
None
self
.
locks
=
0
def
lock
(
self
):
self
.
locks
+=
1
def
unlock
(
self
):
self
.
locks
-=
1
assert
self
.
locks
>=
0
,
"Lock / Unlock mismatch!"
def
desc_contents
(
self
):
def
desc_contents
(
self
):
if
self
.
isfile
():
if
self
.
isfile
():
return
"<file
%
s>"
%
self
.
name
return
"<file
%
s>"
%
self
.
name
...
@@ -106,6 +118,9 @@ class MemoryFS(FS):
...
@@ -106,6 +118,9 @@ class MemoryFS(FS):
def
isfile
(
self
):
def
isfile
(
self
):
return
self
.
type
==
"file"
return
self
.
type
==
"file"
def
islocked
(
self
):
return
self
.
locks
>
0
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s:
%
s"
%
(
self
.
name
,
self
.
desc_contents
())
return
"
%
s:
%
s"
%
(
self
.
name
,
self
.
desc_contents
())
...
@@ -218,21 +233,56 @@ class MemoryFS(FS):
...
@@ -218,21 +233,56 @@ class MemoryFS(FS):
return
self
return
self
def
_lock_dir
(
self
,
dirpath
):
dir_entry
=
self
.
_get_dir_entry
(
path
)
dir_entry
.
lock
()
def
_unlock_dir
(
self
,
dirpath
):
dir_entry
=
self
.
_get_dir_entry
(
path
)
dir_entry
.
unlock
()
def
is_dir_locked
(
self
,
dirpath
):
dir_entry
=
self
.
_get_dir_entry
(
path
)
return
dir_entry
.
islocked
()
def
open
(
self
,
path
,
mode
,
**
kwargs
):
def
open
(
self
,
path
,
mode
,
**
kwargs
):
dir_entry
=
self
.
_get_dir_entry
(
path
)
dir_entry
=
self
.
_get_dir_entry
(
path
)
if
dir_entry
is
None
:
if
dir_entry
is
None
:
dirpath
,
dir
name
=
pathsplit
(
path
)
dirpath
,
file
name
=
pathsplit
(
path
)
parent_dir_entry
=
self
.
_get_dir_entry
(
dir
path
)
parent_dir_entry
=
self
.
_get_dir_entry
(
file
path
)
if
'r'
in
mode
or
'a'
in
mode
:
if
filename
not
in
parent_dir_entry
:
raise
FSError
(
"FILE_DOES_NOT_EXIST"
,
"Can not open file that does not exist:
%(path)
s"
,
path
)
parent_dir
.
lock
()
file_dir_entry
=
parent_dir_entry
[
filename
]
mem_file
=
MemoryFile
(
path
,
self
,
file_dir_entry
.
value
,
mode
)
file_dir_entry
.
num_reading
+=
1
return
mem_file
else
:
self
.
_make_dir_entry
(
"file"
,
filename
)
if
parent_dir_entry
is
None
:
if
parent_dir_entry
is
None
:
raise
FSError
(
"DOES_NOT_EXIST"
,
"File does not exist"
,
path
)
raise
FSError
(
"DOES_NOT_EXIST"
,
"File does not exist"
,
path
)
def
_on_close_memory_file
(
self
,
path
,
value
):
def
_on_close_memory_file
(
self
,
path
,
value
):
self
.
_unlock_dir
(
path
)
dir_entry
=
self
.
_get_dir_entry
(
path
)
dir_entry
=
self
.
_get_dir_entry
(
path
)
dir_entry
.
data
=
value
def
listdir
(
self
,
path
=
"/"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
def
listdir
(
self
,
path
=
"/"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
...
...
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