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
aece1874
Commit
aece1874
authored
Jul 26, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refinements to the memoryfs class, and added a 'walk' generator to the base class
parent
36b626d8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
18 deletions
+42
-18
fs/browsewin.py
+8
-8
fs/fs.py
+34
-10
fs/memoryfs.py
+0
-0
No files found.
fs/browsewin.py
View file @
aece1874
...
@@ -9,7 +9,7 @@ import fs
...
@@ -9,7 +9,7 @@ import fs
class
BrowseFrame
(
wx
.
Frame
):
class
BrowseFrame
(
wx
.
Frame
):
def
__init__
(
self
,
fs
):
def
__init__
(
self
,
fs
):
wx
.
Frame
.
__init__
(
self
,
None
)
wx
.
Frame
.
__init__
(
self
,
None
)
self
.
fs
=
fs
self
.
fs
=
fs
...
@@ -44,7 +44,7 @@ class BrowseFrame(wx.Frame):
...
@@ -44,7 +44,7 @@ class BrowseFrame(wx.Frame):
if
not
self
.
fs
.
isdir
(
path
):
if
not
self
.
fs
.
isdir
(
path
):
return
return
if
item_data
[
'expanded'
]:
if
item_data
[
'expanded'
]:
return
return
paths
=
[(
self
.
fs
.
isdir
(
p
),
p
)
for
p
in
self
.
fs
.
listdir
(
path
,
absolute
=
True
)]
paths
=
[(
self
.
fs
.
isdir
(
p
),
p
)
for
p
in
self
.
fs
.
listdir
(
path
,
absolute
=
True
)]
...
@@ -55,16 +55,16 @@ class BrowseFrame(wx.Frame):
...
@@ -55,16 +55,16 @@ class BrowseFrame(wx.Frame):
return
return
paths
.
sort
(
key
=
lambda
p
:(
not
p
[
0
],
p
[
1
]
.
lower
()))
paths
.
sort
(
key
=
lambda
p
:(
not
p
[
0
],
p
[
1
]
.
lower
()))
for
is_dir
,
new_path
in
paths
:
for
is_dir
,
new_path
in
paths
:
name
=
fs
.
pathsplit
(
new_path
)[
-
1
]
name
=
fs
.
pathsplit
(
new_path
)[
-
1
]
if
not
is_dir
and
name
.
endswith
(
'.txt'
):
if
not
is_dir
and
name
.
endswith
(
'.txt'
):
txt
=
self
.
fs
.
open
(
new_path
)
.
read
(
50
)
txt
=
self
.
fs
.
open
(
new_path
)
.
read
line
()[:
50
]
.
rstrip
(
)
name
+=
" - "
+
txt
name
+=
" - "
+
txt
new_item
=
self
.
tree
.
AppendItem
(
item_id
,
name
,
data
=
wx
.
TreeItemData
({
'path'
:
new_path
,
'expanded'
:
False
}))
new_item
=
self
.
tree
.
AppendItem
(
item_id
,
name
,
data
=
wx
.
TreeItemData
({
'path'
:
new_path
,
'expanded'
:
False
}))
if
is_dir
:
if
is_dir
:
...
...
fs/fs.py
View file @
aece1874
...
@@ -13,7 +13,8 @@ error_msgs = {
...
@@ -13,7 +13,8 @@ error_msgs = {
"LISTDIR_FAILED"
:
"Unable to get directory listing:
%(path)
s"
,
"LISTDIR_FAILED"
:
"Unable to get directory listing:
%(path)
s"
,
"NO_SYS_PATH"
:
"No mapping to OS filesytem:
%(path)
s,"
,
"NO_SYS_PATH"
:
"No mapping to OS filesytem:
%(path)
s,"
,
"DIR_EXISTS"
:
"Directory exists (try allow_recreate=True):
%(path)
s"
,
"DIR_EXISTS"
:
"Directory exists (try allow_recreate=True):
%(path)
s"
,
"OPEN_FAILED"
:
"Unable to open file:
%(path)
s"
"OPEN_FAILED"
:
"Unable to open file:
%(path)
s"
,
"FILE_LOCKED"
:
"File is locked:
%(path)
s"
,
}
}
error_codes
=
error_msgs
.
keys
()
error_codes
=
error_msgs
.
keys
()
...
@@ -29,9 +30,9 @@ class FSError(Exception):
...
@@ -29,9 +30,9 @@ class FSError(Exception):
def
__str__
(
self
):
def
__str__
(
self
):
msg
=
self
.
msg
%
dict
((
k
,
str
(
v
))
for
k
,
v
in
self
.
__dict__
.
iteritems
())
msg
=
self
.
msg
%
dict
((
k
,
str
(
v
))
for
k
,
v
in
self
.
__dict__
.
iteritems
())
return
'
%
s
%
s'
%
(
self
.
code
,
msg
)
return
'
%
s
.
%
s'
%
(
self
.
code
,
msg
)
class
NullFile
:
class
NullFile
:
...
@@ -224,17 +225,40 @@ class FS(object):
...
@@ -224,17 +225,40 @@ class FS(object):
elif
absolute
:
elif
absolute
:
paths
=
[
self
.
abspath
(
pathjoin
(
path
,
p
))
for
p
in
paths
]
paths
=
[
self
.
abspath
(
pathjoin
(
path
,
p
))
for
p
in
paths
]
return
paths
return
paths
def
walk_files
(
self
,
path
=
"/"
,
wildcard
=
None
,
dir_wildcard
=
None
):
dirs
=
[
path
]
files
=
[]
while
dirs
:
path
=
dirs
.
pop
()
for
path
in
self
.
listdir
(
path
,
full
=
True
):
if
self
.
isdir
(
path
):
if
dir_wildcard
is
not
None
:
if
fnmatch
.
fnmatch
(
path
,
dir_wilcard
):
dirs
.
append
(
path
)
else
:
dirs
.
append
(
path
)
else
:
if
wildcard
is
not
None
:
if
fnmatch
.
fnmatch
(
path
,
wildcard
):
yield
path
else
:
yield
path
class
SubFS
(
FS
):
class
SubFS
(
FS
):
def
__init__
(
self
,
parent
,
sub_dir
):
def
__init__
(
self
,
parent
,
sub_dir
):
self
.
parent
=
parent
self
.
parent
=
parent
self
.
sub_dir
=
parent
.
abspath
(
sub_dir
)
self
.
sub_dir
=
parent
.
abspath
(
sub_dir
)
#print "sub_dir", self.sub_dir
def
__str__
(
self
):
def
__str__
(
self
):
return
"<SubFS
\"
%
s
\"
of
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
return
"<SubFS
\"
%
s
\"
of
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
...
@@ -242,7 +266,6 @@ class SubFS(FS):
...
@@ -242,7 +266,6 @@ class SubFS(FS):
def
_delegate
(
self
,
dirname
):
def
_delegate
(
self
,
dirname
):
delegate_path
=
pathjoin
(
self
.
sub_dir
,
resolvepath
(
makerelative
(
dirname
)))
delegate_path
=
pathjoin
(
self
.
sub_dir
,
resolvepath
(
makerelative
(
dirname
)))
#print "delegate path", delegate_path
return
delegate_path
return
delegate_path
def
getsyspath
(
self
,
pathname
):
def
getsyspath
(
self
,
pathname
):
...
@@ -274,7 +297,6 @@ class OSFS(FS):
...
@@ -274,7 +297,6 @@ class OSFS(FS):
raise
FSError
(
"NO_DIR"
,
expanded_path
,
msg
=
"Root path is not a directory:
%(path)
s"
)
raise
FSError
(
"NO_DIR"
,
expanded_path
,
msg
=
"Root path is not a directory:
%(path)
s"
)
self
.
root_path
=
normpath
(
os
.
path
.
abspath
(
expanded_path
))
self
.
root_path
=
normpath
(
os
.
path
.
abspath
(
expanded_path
))
#print "Root path", self.root_path
def
__str__
(
self
):
def
__str__
(
self
):
return
"<OSFS
\"
%
s
\"
>"
%
self
.
root_path
return
"<OSFS
\"
%
s
\"
>"
%
self
.
root_path
...
@@ -320,7 +342,7 @@ class OSFS(FS):
...
@@ -320,7 +342,7 @@ class OSFS(FS):
try
:
try
:
paths
=
os
.
listdir
(
self
.
getsyspath
(
path
))
paths
=
os
.
listdir
(
self
.
getsyspath
(
path
))
except
IOError
,
e
:
except
(
OSError
,
IOError
)
,
e
:
raise
FSError
(
"LISTDIR_FAILED"
,
path
,
details
=
e
,
msg
=
"Unable to get directory listing:
%(path)
s - (
%(details)
s)"
)
raise
FSError
(
"LISTDIR_FAILED"
,
path
,
details
=
e
,
msg
=
"Unable to get directory listing:
%(path)
s - (
%(details)
s)"
)
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
...
@@ -470,9 +492,11 @@ class MountFS(FS):
...
@@ -470,9 +492,11 @@ class MountFS(FS):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
osfs
=
OSFS
(
"~/"
)
osfs
=
OSFS
(
"~/
projects
"
)
print
osfs
print
osfs
#print osfs
for
filename
in
osfs
.
walk_files
(
"/prettycharts"
,
"*.pov"
):
print
filename
import
browsewin
import
browsewin
browsewin
.
browse
(
osfs
)
browsewin
.
browse
(
osfs
)
...
...
fs/memoryfs.py
View file @
aece1874
This diff is collapsed.
Click to expand it.
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