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
1cde4462
Commit
1cde4462
authored
Jul 28, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress
parent
338423c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
36 deletions
+113
-36
fs/fs.py
+13
-13
fs/multifs.py
+100
-23
No files found.
fs/fs.py
View file @
1cde4462
...
@@ -194,10 +194,10 @@ class FS(object):
...
@@ -194,10 +194,10 @@ class FS(object):
return
pathname
return
pathname
def
getsyspath
(
self
,
path
):
def
getsyspath
(
self
,
path
):
raise
FSError
(
"NO_SYS_PATH"
,
path
)
raise
FSError
(
"NO_SYS_PATH"
,
path
)
def
open
(
self
,
path
name
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
def
open
(
self
,
path
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
pass
pass
...
@@ -265,17 +265,17 @@ class FS(object):
...
@@ -265,17 +265,17 @@ class FS(object):
yield
path
yield
path
def
walk
(
self
,
path
=
"/"
,
wildcard
=
None
,
dir_wildcard
=
None
):
def
walk
(
self
,
path
=
"/"
,
wildcard
=
None
,
dir_wildcard
=
None
):
dirs
=
[
path
]
dirs
=
[
path
]
while
dirs
:
while
dirs
:
current_path
=
dirs
.
pop
()
current_path
=
dirs
.
pop
()
paths
=
[]
paths
=
[]
for
path
in
self
.
listdir
(
current_path
,
full
=
True
):
for
path
in
self
.
listdir
(
current_path
,
full
=
True
):
if
self
.
isdir
(
path
):
if
self
.
isdir
(
path
):
if
dir_wildcard
is
not
None
:
if
dir_wildcard
is
not
None
:
if
fnmatch
.
fnmatch
(
path
,
dir_wilcard
):
if
fnmatch
.
fnmatch
(
path
,
dir_wilcard
):
...
@@ -288,7 +288,7 @@ class FS(object):
...
@@ -288,7 +288,7 @@ class FS(object):
paths
.
append
(
path
)
paths
.
append
(
path
)
else
:
else
:
paths
.
append
(
path
)
paths
.
append
(
path
)
yield
(
current_path
,
paths
)
yield
(
current_path
,
paths
)
...
@@ -320,7 +320,7 @@ class SubFS(FS):
...
@@ -320,7 +320,7 @@ class SubFS(FS):
def
open
(
self
,
pathname
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
def
open
(
self
,
pathname
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
return
self
.
parent
.
open
(
self
.
_delegate
(
pathname
),
mode
,
buffering
)
return
self
.
parent
.
open
(
self
.
_delegate
(
pathname
),
mode
,
buffering
)
def
open_dir
(
self
,
path
):
def
open_dir
(
self
,
path
):
if
not
self
.
exists
(
dirname
):
if
not
self
.
exists
(
dirname
):
...
@@ -407,9 +407,9 @@ class OSFS(FS):
...
@@ -407,9 +407,9 @@ class OSFS(FS):
sys_path
=
self
.
getsyspath
(
path
)
sys_path
=
self
.
getsyspath
(
path
)
if
recursive
:
if
recursive
:
makedirs
(
sys_path
,
mode
)
os
.
makedirs
(
sys_path
,
mode
)
else
:
else
:
makedir
(
sys_path
,
mode
)
os
.
makedir
(
sys_path
,
mode
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
...
@@ -421,7 +421,7 @@ class OSFS(FS):
...
@@ -421,7 +421,7 @@ class OSFS(FS):
raise
FSError
(
"FILE_DELETE_FAILED"
,
path
,
details
=
e
)
raise
FSError
(
"FILE_DELETE_FAILED"
,
path
,
details
=
e
)
def
remove
_
dir
(
self
,
path
,
recursive
=
False
):
def
removedir
(
self
,
path
,
recursive
=
False
):
sys_path
=
self
.
getsyspath
(
path
)
sys_path
=
self
.
getsyspath
(
path
)
...
...
fs/multifs.py
View file @
1cde4462
#!/usr/
b
in/env python
#!/usr/in/env python
from
fs
import
FS
from
fs
import
FS
,
FSError
class
MultiFS
(
FS
):
class
MultiFS
(
FS
):
def
__init__
(
self
):
def
__init__
(
self
):
FS
.
__init__
(
self
)
FS
.
__init__
(
self
)
self
.
fs_sequence
=
[]
self
.
fs_sequence
=
[]
self
.
fs_lookup
=
{}
self
.
fs_lookup
=
{}
def
__str__
(
self
):
return
"<MultiFS:
%
s>"
%
", "
.
join
(
str
(
fs
)
for
fs
in
self
.
fs_sequence
)
def
add_fs
(
self
,
name
,
fs
):
def
add_fs
(
self
,
name
,
fs
):
self
.
fs_sequence
.
append
(
name
,
fs
)
if
name
in
self
.
fs_lookup
:
raise
ValueError
(
"Name already exists."
)
self
.
fs_sequence
.
append
(
fs
)
self
.
fs_lookup
[
name
]
=
fs
self
.
fs_lookup
[
name
]
=
fs
def
remove_fs
(
self
,
name
):
def
remove_fs
(
self
,
name
):
fs
=
self
.
fs_lookup
[
name
]
fs
=
self
.
fs_lookup
[
name
]
self
.
fs_sequence
.
remove
(
fs
)
self
.
fs_sequence
.
remove
(
fs
)
del
self
.
fs_lookup
[
name
]
del
self
.
fs_lookup
[
name
]
def
__getitem__
(
self
,
name
):
def
__getitem__
(
self
,
name
):
return
self
.
fs_lookup
[
name
]
return
self
.
fs_lookup
[
name
]
def
__iter__
(
self
):
def
__iter__
(
self
):
return
iter
(
self
.
fs_sequence
)
return
iter
(
self
.
fs_sequence
)
def
_delegate_search
(
self
,
path
):
def
_delegate_search
(
self
,
path
):
for
fs
in
self
:
for
fs
in
self
:
if
self
.
exists
(
path
):
if
self
.
exists
(
path
):
return
fs
return
fs
return
None
return
None
def
getsyspath
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
getsyspath
(
path
)
raise
FSError
(
"NO_FILE"
,
path
)
def
open
(
self
,
path
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
for
fs
in
self
:
if
fs
.
exists
(
path
):
fs_file
=
fs
.
open
(
path
,
mode
,
buffering
,
**
kwargs
)
return
fs_file
raise
FSError
(
"NO_FILE"
,
path
)
def
exists
(
self
,
path
):
def
exists
(
self
,
path
):
return
self
.
_delegate_search
(
path
)
is
not
None
return
self
.
_delegate_search
(
path
)
is
not
None
\ No newline at end of file
def
isdir
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isdir
()
return
False
def
isfile
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isfile
()
return
False
def
ishidden
(
self
,
path
):
fs
=
self
.
_delegate_search
(
path
)
if
fs
is
not
None
:
return
fs
.
isfile
()
return
False
def
listdir
(
self
,
path
=
"./"
,
*
args
,
**
kwargs
):
paths
=
[]
for
fs
in
self
:
try
:
paths
+=
fs
.
listdir
(
path
,
*
args
,
**
kwargs
)
except
FSError
,
e
:
pass
return
list
(
set
(
paths
))
def
remove
(
self
,
path
):
for
fs
in
self
:
if
fs
.
exist
(
path
):
fs
.
remove
(
path
)
return
raise
FSError
(
"NO_FILE"
,
path
)
def
removedir
(
self
,
path
,
recursive
=
False
):
for
fs
in
self
:
if
fs
.
isdir
(
path
):
fs
.
removedir
(
path
,
recursive
)
return
raise
FSError
(
"NO_DIR"
,
path
)
def
getinfo
(
self
,
path
):
for
fs
in
self
:
if
fs
.
exist
(
path
):
return
fs
.
getinfo
(
path
)
raise
FSError
(
"NO_FILE"
,
path
)
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