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
3038fbda
Commit
3038fbda
authored
Jul 21, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started work on the memory filesystem
parent
b69bf455
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
21 deletions
+156
-21
fs/browsewin.py
+8
-11
fs/fs.py
+26
-10
fs/memoryfs.py
+122
-0
No files found.
fs/browsewin.py
View file @
3038fbda
...
@@ -9,6 +9,7 @@ import fs
...
@@ -9,6 +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
...
@@ -46,22 +47,19 @@ class BrowseFrame(wx.Frame):
...
@@ -46,22 +47,19 @@ class BrowseFrame(wx.Frame):
if
item_data
[
'expanded'
]:
if
item_data
[
'expanded'
]:
return
return
paths
=
self
.
fs
.
listdir
(
path
,
absolute
=
True
)
paths
=
[(
self
.
fs
.
isdir
(
p
),
p
)
for
p
in
self
.
fs
.
listdir
(
path
,
absolute
=
True
)]
if
not
paths
:
if
not
paths
:
self
.
tree
.
SetItemHasChildren
(
item_id
,
False
)
self
.
tree
.
SetItemHasChildren
(
item_id
,
False
)
self
.
tree
.
Collapse
(
item_id
)
self
.
tree
.
Collapse
(
item_id
)
return
return
paths
.
sort
(
key
=
lambda
p
:(
not
p
[
0
],
p
[
1
]
.
lower
()))
paths
.
sort
(
key
=
lambda
p
:(
not
self
.
fs
.
isdir
(
p
),
p
.
lower
()))
for
is_dir
,
new_path
in
paths
:
for
new_path
in
paths
:
name
=
fs
.
pathsplit
(
new_path
)[
-
1
]
new_item
=
self
.
tree
.
AppendItem
(
item_id
,
name
,
data
=
wx
.
TreeItemData
({
'path'
:
new_path
,
'expanded'
:
False
}))
is_dir
=
self
.
fs
.
isdir
(
new_path
)
name
=
fs
.
pathsplit
(
new_path
)[
-
1
]
new_item
=
self
.
tree
.
AppendItem
(
item_id
,
name
,
data
=
wx
.
TreeItemData
(
{
'path'
:
new_path
,
'expanded'
:
False
}))
if
is_dir
:
if
is_dir
:
self
.
tree
.
SetItemHasChildren
(
new_item
)
self
.
tree
.
SetItemHasChildren
(
new_item
)
...
@@ -70,7 +68,6 @@ class BrowseFrame(wx.Frame):
...
@@ -70,7 +68,6 @@ class BrowseFrame(wx.Frame):
else
:
else
:
self
.
tree
.
SetItemImage
(
new_item
,
self
.
fileidx
,
wx
.
TreeItemIcon_Normal
)
self
.
tree
.
SetItemImage
(
new_item
,
self
.
fileidx
,
wx
.
TreeItemIcon_Normal
)
item_data
[
'expanded'
]
=
True
item_data
[
'expanded'
]
=
True
self
.
tree
.
Expand
(
item_id
)
self
.
tree
.
Expand
(
item_id
)
...
...
fs/fs.py
View file @
3038fbda
...
@@ -63,11 +63,6 @@ class FSError(Exception):
...
@@ -63,11 +63,6 @@ class FSError(Exception):
return
'
%
s -
%
s'
%
(
self
.
code
,
msg
)
return
'
%
s -
%
s'
%
(
self
.
code
,
msg
)
class
PathError
(
FSError
):
pass
def
_isabsolute
(
path
):
def
_isabsolute
(
path
):
if
path
:
if
path
:
return
path
[
1
]
in
'
\\
/'
return
path
[
1
]
in
'
\\
/'
...
@@ -106,8 +101,12 @@ def pathjoin(*paths):
...
@@ -106,8 +101,12 @@ def pathjoin(*paths):
else
:
else
:
return
"/"
.
join
(
pathstack
)
return
"/"
.
join
(
pathstack
)
def
pathsplit
(
path
):
def
pathsplit
(
path
):
return
path
.
rsplit
(
'/'
,
1
)
split
=
normpath
(
path
)
.
rsplit
(
'/'
,
1
)
if
len
(
split
)
==
1
:
return
(
''
,
split
[
0
])
return
split
def
resolvepath
(
path
):
def
resolvepath
(
path
):
...
@@ -118,9 +117,13 @@ def makerelative(path):
...
@@ -118,9 +117,13 @@ def makerelative(path):
return
path
[
1
:]
return
path
[
1
:]
return
path
return
path
def
split
path
(
path
,
numsplits
=
None
):
def
_iterate
path
(
path
,
numsplits
=
None
):
path
=
resolvepath
(
path
)
path
=
resolvepath
(
path
)
if
not
path
:
return
[]
if
numsplits
==
None
:
if
numsplits
==
None
:
return
path
.
split
(
'/'
)
return
path
.
split
(
'/'
)
else
:
else
:
...
@@ -269,7 +272,6 @@ class OSFS(FS):
...
@@ -269,7 +272,6 @@ class OSFS(FS):
return
pathjoin
(
'/'
,
pathname
)
return
pathjoin
(
'/'
,
pathname
)
return
pathname
return
pathname
def
open
(
self
,
pathname
,
mode
=
"r"
,
buffering
=-
1
):
def
open
(
self
,
pathname
,
mode
=
"r"
,
buffering
=-
1
):
try
:
try
:
...
@@ -298,7 +300,6 @@ class OSFS(FS):
...
@@ -298,7 +300,6 @@ class OSFS(FS):
return
pathname
.
startswith
(
'.'
)
return
pathname
.
startswith
(
'.'
)
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
):
try
:
try
:
...
@@ -309,6 +310,21 @@ class OSFS(FS):
...
@@ -309,6 +310,21 @@ class OSFS(FS):
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
)
def
mkdir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
sys_path
=
self
.
getsyspath
(
path
)
if
recursive
:
makedirs
(
sys_path
,
mode
)
else
:
makedir
(
sys_path
,
mode
)
def
remove
(
self
,
path
):
sys_path
=
self
.
getsyspath
(
path
)
os
.
remove
(
sys_path
)
...
...
fs/memoryfs.py
0 → 100644
View file @
3038fbda
#!/usr/bin/env python
from
fs
import
FS
,
pathsplit
,
_iteratepath
,
FSError
class
MemoryFS
(
FS
):
class
DirEntry
(
object
):
def
__init__
(
self
,
type
,
name
,
contents
=
None
):
self
.
type
=
type
self
.
name
=
name
self
.
permissions
=
None
if
contents
is
None
and
type
==
"dir"
:
contents
=
{}
self
.
contents
=
contents
def
isdir
(
self
):
return
self
.
type
==
"dir"
def
isfile
(
self
):
return
self
.
type
==
"file"
def
_make_dir_entry
(
self
,
*
args
,
**
kwargs
):
return
self
.
dir_entry_factory
(
*
args
,
**
kwargs
)
def
__init__
(
self
):
self
.
dir_entry_factory
=
MemoryFS
.
DirEntry
self
.
root
=
self
.
_make_dir_entry
(
'dir'
,
'root'
)
def
_get_dir_entry
(
self
,
dirpath
):
current_dir
=
self
.
root
for
path_component
in
_iteratepath
(
dirpath
):
dir_entry
=
current_dir
.
contents
.
get
(
path_component
,
None
)
if
dir_entry
is
None
:
return
None
if
not
dir_entry
.
isdir
():
return
None
current_dir
=
dir_entry
return
current_dir
def
isdir
(
path
):
dir_item
=
self
.
_get_dir_entry
(
path
)
if
dir_item
is
None
:
return
False
return
dir_item
.
isdir
()
def
isfile
(
path
):
dir_item
=
self
.
_get_dir_entry
(
path
)
if
dir_item
is
None
:
return
False
return
dir_item
.
isfile
()
def
exists
(
path
):
return
self
.
_getdir
(
path
)
is
not
None
def
mkdir
(
self
,
dirname
,
mode
=
0777
,
recursive
=
False
,
allow_recreate
=
False
):
if
not
recursive
:
dirpath
,
dirname
=
pathsplit
(
dirname
)
parent_dir
=
self
.
_get_dir_entry
(
dirpath
)
if
parent_dir
is
None
:
raise
FSError
(
"NO_DIR"
,
"Could not make dir, as parent dir does not exist:
%(path)
s"
,
dirname
)
dir_item
=
parent_dir
.
contents
.
get
(
dirname
,
None
)
if
dir_item
is
not
None
:
if
dir_item
.
isdir
():
if
not
allow_recreate
:
raise
FSError
(
"CANNOT_RECREATE_DIR"
,
"Can not create a directory that already exists (try allow_recreate=True):
%(path)
s"
,
dirname
)
else
:
raise
FSError
(
"CANNOT_CREATE_DIR"
,
"Can not create a directory, because path references a file:
%(path)
s"
,
dirname
)
if
dir_item
is
None
:
dir_item
.
contents
[
dirname
]
=
self
.
_make_dir_entry
(
"dir"
,
dirname
)
else
:
dirpath
,
dirname
=
pathsplit
(
dirname
)
parent_dir
=
self
.
_get_dir_entry
(
dirpath
)
if
parent_dir
is
not
None
:
if
parent_dir
.
isfile
():
raise
FSError
(
"CANNOT_CREATE_DIR"
,
"Can not create a directory, because path references a file:
%(path)
s"
,
dirname
)
else
:
if
not
allow_recreate
:
raise
FSError
(
"CANNOT_RECREATE_DIR"
,
"Can not create a directory that already exists (try allow_recreate=True):
%(path)
s"
,
dirname
)
current_dir
=
self
.
root
for
path_component
in
list
(
_iteratepath
(
dirname
))[:
-
2
]:
dir_item
=
current_dir
.
contents
.
get
(
path_component
,
None
)
if
dir_item
is
None
:
break
if
not
dir_item
.
isdir
():
raise
FSError
(
"CANNOT_CREATE_DIR"
,
"Can not create a directory, because path references a file:
%(path)
s"
,
dirname
)
current_dir
=
dir_item
.
contents
current_dir
=
self
.
root
for
path_component
in
_iteratepath
(
dirname
):
dir_item
=
current_dir
.
contents
.
get
(
path_component
,
None
)
if
dir_item
is
None
:
new_dir
=
self
.
_make_dir_entry
(
"dir"
,
path_component
)
current_dir
.
contents
[
path_component
]
=
new_dir
current_dir
=
new_dir
return
self
if
__name__
==
"__main__"
:
mem_fs
=
MemoryFS
()
mem_fs
.
mkdir
(
'test'
)
\ 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