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
4b2f57cb
Commit
4b2f57cb
authored
Jul 29, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress with the memoryfs
parent
1cde4462
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
12 deletions
+49
-12
fs/fs.py
+13
-3
fs/memoryfs.py
+3
-1
fs/multifs.py
+33
-8
No files found.
fs/fs.py
View file @
4b2f57cb
...
...
@@ -10,7 +10,7 @@ import datetime
error_msgs
=
{
"UNKNOWN_ERROR"
:
"No information on error:
%(path)
s"
,
"UNSUPPORTED"
:
"
This filesystem does not support this action
."
,
"UNSUPPORTED"
:
"
Action is unsupported by this filesystem
."
,
"INVALID_PATH"
:
"Path is invalid:
%(path)
s"
,
"NO_DIR"
:
"Directory does not exist:
%(path)
s"
,
"NO_FILE"
:
"No such file:
%(path)
s"
,
...
...
@@ -196,12 +196,22 @@ class FS(object):
def
getsyspath
(
self
,
path
):
raise
FSError
(
"NO_SYS_PATH"
,
path
)
def
safeopen
(
self
,
*
args
,
**
kwargs
):
try
:
f
=
self
.
open
(
*
args
,
**
kwargs
)
except
FSError
,
e
:
if
e
.
code
==
"NO_FILE"
:
return
NullFile
()
raise
def
open
(
self
,
path
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
pass
def
open
_
dir
(
self
,
path
):
def
opendir
(
self
,
path
):
if
not
self
.
exists
(
path
):
raise
FSError
(
"NO_DIR"
,
path
)
...
...
@@ -487,7 +497,7 @@ if __name__ == "__main__":
osfs
=
OSFS
(
"~/projects"
)
print
osfs
for
filename
in
osfs
.
walk_files
(
"/
prettycharts
"
,
"*.pov"
):
for
filename
in
osfs
.
walk_files
(
"/"
,
"*.pov"
):
print
filename
print
osfs
.
getinfo
(
filename
)
...
...
fs/memoryfs.py
View file @
4b2f57cb
...
...
@@ -192,7 +192,7 @@ class MemoryFS(FS):
def
exists
(
self
,
path
):
return
self
.
_get
dir
(
path
)
is
not
None
return
self
.
_get
_dir_entry
(
path
)
is
not
None
def
mkdir
(
self
,
dirname
,
mode
=
0777
,
recursive
=
False
,
allow_recreate
=
False
):
...
...
@@ -339,6 +339,8 @@ class MemoryFS(FS):
def
listdir
(
self
,
path
=
"/"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
dir_entry
=
self
.
_get_dir_entry
(
path
)
if
dir_entry
is
None
:
raise
FSError
(
"NO_DIR"
,
path
)
paths
=
dir_entry
.
contents
.
keys
()
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
...
...
fs/multifs.py
View file @
4b2f57cb
...
...
@@ -15,7 +15,7 @@ class MultiFS(FS):
return
"<MultiFS:
%
s>"
%
", "
.
join
(
str
(
fs
)
for
fs
in
self
.
fs_sequence
)
def
add
_
fs
(
self
,
name
,
fs
):
def
addfs
(
self
,
name
,
fs
):
if
name
in
self
.
fs_lookup
:
raise
ValueError
(
"Name already exists."
)
...
...
@@ -24,7 +24,7 @@ class MultiFS(FS):
self
.
fs_lookup
[
name
]
=
fs
def
remove
_
fs
(
self
,
name
):
def
removefs
(
self
,
name
):
fs
=
self
.
fs_lookup
[
name
]
self
.
fs_sequence
.
remove
(
fs
)
...
...
@@ -42,7 +42,7 @@ class MultiFS(FS):
def
_delegate_search
(
self
,
path
):
for
fs
in
self
:
if
self
.
exists
(
path
):
if
fs
.
exists
(
path
):
return
fs
return
None
...
...
@@ -71,21 +71,21 @@ class MultiFS(FS):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isdir
()
return
fs
.
isdir
(
path
)
return
False
def
isfile
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isfile
()
return
fs
.
isfile
(
path
)
return
False
def
ishidden
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isfile
()
return
fs
.
isfile
(
path
)
return
False
def
listdir
(
self
,
path
=
"./"
,
*
args
,
**
kwargs
):
...
...
@@ -102,7 +102,7 @@ class MultiFS(FS):
def
remove
(
self
,
path
):
for
fs
in
self
:
if
fs
.
exist
(
path
):
if
fs
.
exist
s
(
path
):
fs
.
remove
(
path
)
return
raise
FSError
(
"NO_FILE"
,
path
)
...
...
@@ -119,7 +119,31 @@ class MultiFS(FS):
def
getinfo
(
self
,
path
):
for
fs
in
self
:
if
fs
.
exist
(
path
):
if
fs
.
exist
s
(
path
):
return
fs
.
getinfo
(
path
)
raise
FSError
(
"NO_FILE"
,
path
)
if
__name__
==
"__main__"
:
import
fs
osfs
=
fs
.
OSFS
(
'~/'
)
import
memoryfs
mem_fs
=
memoryfs
.
MemoryFS
()
mem_fs
.
mkdir
(
'projects/test2'
,
recursive
=
True
)
mem_fs
.
mkdir
(
'projects/A'
,
recursive
=
True
)
mem_fs
.
mkdir
(
'projects/A/B'
,
recursive
=
True
)
mem_fs
.
open
(
"projects/readme.txt"
,
'w'
)
.
write
(
"Hello, World!"
)
mem_fs
.
open
(
"projects/readme.txt"
,
'wa'
)
.
write
(
"
\n
Second Line"
)
multifs
=
MultiFS
()
multifs
.
addfs
(
"osfs"
,
osfs
)
multifs
.
addfs
(
"mem_fs"
,
mem_fs
)
import
browsewin
browsewin
.
browse
(
multifs
)
\ 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