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
dc82b110
Commit
dc82b110
authored
Sep 05, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress
parent
1865b55d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
fs/fs.py
+23
-2
fs/osfs.py
+1
-1
fs/tests.py
+1
-0
No files found.
fs/fs.py
View file @
dc82b110
...
@@ -58,7 +58,7 @@ class FSError(Exception):
...
@@ -58,7 +58,7 @@ class FSError(Exception):
"""A catch all exception for FS objects."""
"""A catch all exception for FS objects."""
def
__init__
(
self
,
code
,
path
=
None
,
path2
=
None
,
msg
=
None
,
details
=
None
):
def
__init__
(
self
,
code
,
path
=
None
,
path2
=
None
,
msg
=
None
,
details
=
None
):
"""
"""
A unified exception class that represents Filesystem errors.
code -- A short identifier for the error
code -- A short identifier for the error
path -- A path associated with the error
path -- A path associated with the error
...
@@ -269,7 +269,7 @@ def _iteratepath(path, numsplits=None):
...
@@ -269,7 +269,7 @@ def _iteratepath(path, numsplits=None):
return
filter
(
lambda
p
:
bool
(
p
),
path
.
split
(
'/'
,
numsplits
))
return
filter
(
lambda
p
:
bool
(
p
),
path
.
split
(
'/'
,
numsplits
))
def
print_fs
(
fs
,
path
=
"/"
,
max_levels
=
None
,
indent
=
' '
*
2
):
def
print_fs
(
fs
,
path
=
"/"
,
max_levels
=
2
,
indent
=
' '
*
2
):
"""Prints a filesystem listing to stdout (including sub dirs). Useful as a debugging aid.
"""Prints a filesystem listing to stdout (including sub dirs). Useful as a debugging aid.
Be careful about printing a OSFS, or any other large filesystem.
Be careful about printing a OSFS, or any other large filesystem.
Without max_levels set, this function will traverse the entire directory tree.
Without max_levels set, this function will traverse the entire directory tree.
...
@@ -295,6 +295,9 @@ def print_fs(fs, path="/", max_levels=None, indent=' '*2):
...
@@ -295,6 +295,9 @@ def print_fs(fs, path="/", max_levels=None, indent=' '*2):
print
indent
*
level
+
'[
%
s]'
%
item
print
indent
*
level
+
'[
%
s]'
%
item
if
max_levels
is
None
or
level
<
max_levels
:
if
max_levels
is
None
or
level
<
max_levels
:
print_dir
(
fs
,
pathjoin
(
path
,
item
),
level
+
1
)
print_dir
(
fs
,
pathjoin
(
path
,
item
),
level
+
1
)
if
max_levels
is
not
None
:
if
level
>=
max_levels
:
print
indent
*
(
level
+
1
)
+
"[...]"
else
:
else
:
print
indent
*
level
+
'
%
s'
%
item
print
indent
*
level
+
'
%
s'
%
item
print_dir
(
fs
,
path
,
0
)
print_dir
(
fs
,
path
,
0
)
...
@@ -555,6 +558,17 @@ class FS(object):
...
@@ -555,6 +558,17 @@ class FS(object):
def
copyfile
(
self
,
src
,
dst
,
overwrite
=
False
,
chunk_size
=
1024
*
16384
):
def
copyfile
(
self
,
src
,
dst
,
overwrite
=
False
,
chunk_size
=
1024
*
16384
):
"""Copies a file from src to dst.
src -- The source path
dst -- The destination path
overwrite -- If True, then the destination may be overwritten
(if a file exists at that location). If False then an exception will be
thrown if the destination exists
chunk_size -- Size of chunks to use in copy, if a simple copy is required
"""
src_syspath
=
self
.
getsyspath
(
src
,
allow_none
=
True
)
src_syspath
=
self
.
getsyspath
(
src
,
allow_none
=
True
)
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
...
@@ -587,6 +601,13 @@ class FS(object):
...
@@ -587,6 +601,13 @@ class FS(object):
def
movefile
(
self
,
src
,
dst
):
def
movefile
(
self
,
src
,
dst
):
"""Moves a file from one location to another.
src -- Source path
dst -- Destination path
"""
src_syspath
=
self
.
getsyspath
(
src
,
allow_none
=
True
)
src_syspath
=
self
.
getsyspath
(
src
,
allow_none
=
True
)
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
...
...
fs/osfs.py
View file @
dc82b110
...
@@ -147,7 +147,7 @@ if __name__ == "__main__":
...
@@ -147,7 +147,7 @@ if __name__ == "__main__":
import
browsewin
import
browsewin
browsewin
.
browse
(
osfs
)
browsewin
.
browse
(
osfs
)
#
print_fs(osfs)
print_fs
(
osfs
)
#print osfs.listdir("/projects/fs")
#print osfs.listdir("/projects/fs")
...
...
fs/tests.py
View file @
dc82b110
...
@@ -232,6 +232,7 @@ class TestOSFS(unittest.TestCase):
...
@@ -232,6 +232,7 @@ class TestOSFS(unittest.TestCase):
self
.
assertEqual
(
len
(
d4
),
4
)
self
.
assertEqual
(
len
(
d4
),
4
)
self
.
assertEqual
(
sorted
(
d4
),
[
"p/1/2/3/a"
,
"p/1/2/3/b"
,
"p/1/2/3/bar"
,
"p/1/2/3/foo"
])
self
.
assertEqual
(
sorted
(
d4
),
[
"p/1/2/3/a"
,
"p/1/2/3/b"
,
"p/1/2/3/bar"
,
"p/1/2/3/foo"
])
def
test_rename
(
self
):
def
test_rename
(
self
):
check
=
self
.
check
check
=
self
.
check
self
.
fs
.
open
(
"foo.txt"
,
'wt'
)
.
write
(
"Hello, World!"
)
self
.
fs
.
open
(
"foo.txt"
,
'wt'
)
.
write
(
"Hello, World!"
)
...
...
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