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
9886401f
Commit
9886401f
authored
Jul 31, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fleshed out the subdir fs and added a few methods to the osfs
parent
9457a3c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
20 deletions
+99
-20
fs/fs.py
+90
-19
fs/osfs.py
+9
-1
No files found.
fs/fs.py
View file @
9886401f
...
...
@@ -17,6 +17,7 @@ error_msgs = {
"NO_RESOURCE"
:
"No path to:
%(path)
s"
,
"LISTDIR_FAILED"
:
"Unable to get directory listing:
%(path)
s"
,
"DELETE_FAILED"
:
"Unable to delete file:
%(path)
s"
,
"RENAME_FAILED"
:
"Unable to rename file:
%(path)
s"
,
"NO_SYS_PATH"
:
"No mapping to OS filesytem:
%(path)
s,"
,
"DIR_EXISTS"
:
"Directory exists (try allow_recreate=True):
%(path)
s"
,
"OPEN_FAILED"
:
"Unable to open file:
%(path)
s"
,
...
...
@@ -231,7 +232,7 @@ class FS(object):
return
resolved_path
def
abspath
(
self
,
pathname
):
def
_
abspath
(
self
,
pathname
):
pathname
=
normpath
(
pathname
)
...
...
@@ -269,7 +270,7 @@ class FS(object):
def
open
(
self
,
path
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
pass
raise
FSError
(
"UNSUPPORTED"
)
def
opendir
(
self
,
path
):
...
...
@@ -306,7 +307,7 @@ class FS(object):
if
full
:
paths
=
[
pathjoin
(
path
,
p
)
for
p
in
paths
]
elif
absolute
:
paths
=
[
self
.
abspath
(
pathjoin
(
path
,
p
))
for
p
in
paths
]
paths
=
[
self
.
_
abspath
(
pathjoin
(
path
,
p
))
for
p
in
paths
]
return
paths
...
...
@@ -373,40 +374,97 @@ class SubFS(FS):
def
__init__
(
self
,
parent
,
sub_dir
):
self
.
parent
=
parent
self
.
sub_dir
=
parent
.
abspath
(
sub_dir
)
self
.
sub_dir
=
parent
.
_
abspath
(
sub_dir
)
def
__str__
(
self
):
return
"<SubFS
\"
%
s
\"
of
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
def
_delegate
(
self
,
dirname
):
return
"<SubFS
\"
%
s
\"
in
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
def
desc
(
self
,
path
):
if
self
.
isdir
(
path
):
return
"Sub dir of
%
s"
%
str
(
self
.
parent
)
else
:
return
"File in sub dir of
%
s"
%
str
(
self
.
parent
)
def
_delegate
(
self
,
path
):
return
pathjoin
(
self
.
sub_dir
,
resolvepath
(
makerelative
(
path
)))
def
getsyspath
(
self
,
path
):
delegate_path
=
pathjoin
(
self
.
sub_dir
,
resolvepath
(
makerelative
(
dirname
)))
return
delegate_path
return
self
.
parent
.
getsyspath
(
self
.
_delegate
(
path
))
def
getsyspath
(
self
,
pathname
):
def
open
(
self
,
path
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
return
self
.
parent
.
getsyspath
(
self
.
_delegate
(
pathname
)
)
return
self
.
parent
.
open
(
self
.
_delegate
(
path
),
mode
,
buffering
)
def
open
(
self
,
pathname
,
mode
=
"r"
,
buffering
=-
1
,
**
kwargs
):
def
exists
(
self
,
path
):
return
self
.
parent
.
open
(
self
.
_delegate
(
pathname
),
mode
,
buffering
)
return
self
.
parent
.
exists
(
self
.
_delegate
(
path
)
)
def
open
_
dir
(
self
,
path
):
def
opendir
(
self
,
path
):
if
not
self
.
exists
(
dirname
):
raise
FSError
(
"NO_DIR"
,
dirname
)
if
not
self
.
exists
(
path
):
raise
FSError
(
"NO_DIR"
,
path
)
path
=
self
.
_delegate
(
path
)
sub_fs
=
self
.
parent
.
open
_
dir
(
path
)
sub_fs
=
self
.
parent
.
opendir
(
path
)
return
sub_fs
def
isdir
(
self
,
pathname
):
def
isdir
(
self
,
path
):
return
self
.
parent
.
isdir
(
self
.
_delegate
(
path
))
return
self
.
parent
.
isdir
(
self
.
_delegate
(
pathname
))
def
isfile
(
self
,
path
):
return
self
.
parent
.
isdir
(
self
.
_delegate
(
path
))
def
ishidden
(
self
,
path
):
return
self
.
parent
.
ishidden
(
self
.
_delegate
(
path
))
def
listdir
(
self
,
path
=
"./"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
return
self
.
parent
.
listdir
(
self
.
_delegate
(
path
),
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
paths
=
self
.
parent
.
listdir
(
self
.
_delegate
(
path
),
wildcard
,
False
,
False
,
hidden
,
dirs_only
,
files_only
)
if
absolute
:
listpath
=
resolvepath
(
path
)
paths
=
[
makeabsolute
(
pathjoin
(
listpath
,
path
))
for
path
in
paths
]
elif
full
:
listpath
=
resolvepath
(
path
)
paths
=
[
makerelative
(
pathjoin
(
listpath
,
path
))
for
path
in
paths
]
return
paths
def
mkdir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
return
self
.
parent
.
mkdir
(
self
.
_delegate
(
path
),
mode
=
mode
,
recursive
=
False
)
def
remove
(
self
,
path
):
return
self
.
parent
.
remove
(
self
.
_delegate
(
path
))
def
removedir
(
self
,
path
,
recursive
=
False
):
self
.
parent
.
removedir
(
self
.
_delegate
(
path
),
recursive
=
False
)
def
getinfo
(
self
,
path
):
return
self
.
parent
.
getinfo
(
self
.
_delegate
(
path
))
def
getsize
(
self
,
path
):
return
self
.
parent
.
getsize
(
self
.
_delegate
(
path
))
def
rename
(
self
,
src
,
dst
):
return
self
.
parent
.
rename
(
self
.
_delegate
(
src
),
self
.
_delegate
(
dst
))
def
validatefs
(
fs
):
...
...
@@ -424,6 +482,7 @@ def validatefs(fs):
"removedir"
,
"getinfo"
,
"getsize"
,
"rename"
,
]
pad_size
=
len
(
max
(
expected_methods
,
key
=
str
.
__len__
))
...
...
@@ -437,3 +496,14 @@ def validatefs(fs):
count
+=
1
print
print
"
%
i out of
%
i methods"
%
(
count
,
len
(
expected_methods
))
if
__name__
==
"__main__"
:
import
osfs
import
browsewin
fs1
=
osfs
.
OSFS
(
'~/'
)
fs2
=
fs1
.
opendir
(
"projects"
)
.
opendir
(
'prettycharts'
)
#browsewin.browse(fs1)
browsewin
.
browse
(
fs2
)
\ No newline at end of file
fs/osfs.py
View file @
9886401f
...
...
@@ -19,7 +19,6 @@ class OSFS(FS):
return
"<OSFS
\"
%
s
\"
>"
%
self
.
root_path
def
getsyspath
(
self
,
pathname
):
sys_path
=
os
.
path
.
join
(
self
.
root_path
,
makerelative
(
self
.
_resolve
(
pathname
)))
...
...
@@ -102,6 +101,15 @@ class OSFS(FS):
except
OSError
,
e
:
raise
FSError
(
"DIR_DELETE_FAILED"
,
path
,
details
=
e
)
def
rename
(
self
,
src
,
dst
):
path_src
=
self
.
getsyspath
(
src
)
path_dst
=
self
.
getsyspath
(
dst
)
try
:
os
.
rename
(
path_src
,
path_dst
)
except
OSError
,
e
:
raise
FSError
(
"RENAME_FAILED"
,
src
)
def
getinfo
(
self
,
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