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
2490d82a
Commit
2490d82a
authored
Nov 19, 2009
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a 'makeopendir' method which makes and opens a directory in one. Made FS objects iterable
parent
08428cd2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
fs/base.py
+26
-6
No files found.
fs/base.py
View file @
2490d82a
...
@@ -59,7 +59,7 @@ def silence_fserrors(f, *args, **kwargs):
...
@@ -59,7 +59,7 @@ def silence_fserrors(f, *args, **kwargs):
class
NullFile
(
object
):
class
NullFile
(
object
):
"""A NullFile is a file object that has no functionality.
"""A NullFile is a file object that has no functionality.
Null files are returned by the 'safeopen' method in FS objects when the
Null files are returned by the 'safeopen' method in FS objects when the
file doesn't exist. This can simplify code by negating the need to check
file doesn't exist. This can simplify code by negating the need to check
if a file exists, or handling exceptions.
if a file exists, or handling exceptions.
...
@@ -139,7 +139,7 @@ class FS(object):
...
@@ -139,7 +139,7 @@ class FS(object):
subclasses are welcome to override them if a more efficient implementation
subclasses are welcome to override them if a more efficient implementation
can be provided:
can be provided:
* getsyspath -- get a file's name in the local filesystem, if possible
* getsyspath -- get a file's name in the local filesystem, if possible
* exists -- check whether a path exists as file or directory
* exists -- check whether a path exists as file or directory
* copy -- copy a file to a new location
* copy -- copy a file to a new location
* move -- move a file to a new location
* move -- move a file to a new location
...
@@ -246,6 +246,12 @@ class FS(object):
...
@@ -246,6 +246,12 @@ class FS(object):
raise
UnsupportedError
(
"check for file"
)
raise
UnsupportedError
(
"check for file"
)
def
__iter__
(
self
):
""" Iterates over paths returned by listdir method with default params. """
for
f
in
self
.
listdir
():
yield
f
def
listdir
(
self
,
path
=
"./"
,
def
listdir
(
self
,
path
=
"./"
,
wildcard
=
None
,
wildcard
=
None
,
full
=
False
,
full
=
False
,
...
@@ -434,7 +440,7 @@ class FS(object):
...
@@ -434,7 +440,7 @@ class FS(object):
dir_wildcard -- If given, only walk directories that match the wildcard
dir_wildcard -- If given, only walk directories that match the wildcard
search -- A string dentifying the method used to walk the directories.
search -- A string dentifying the method used to walk the directories.
Can be 'breadth' for a breadth first search, or 'depth' for a
Can be 'breadth' for a breadth first search, or 'depth' for a
depth first search. Use 'depth' if you plan to create or
depth first search. Use 'depth' if you plan to create or
delete files as you go.
delete files as you go.
"""
"""
if
search
==
"breadth"
:
if
search
==
"breadth"
:
...
@@ -482,7 +488,7 @@ class FS(object):
...
@@ -482,7 +488,7 @@ class FS(object):
dir_wildcard -- If given, only walk directories that match the wildcard
dir_wildcard -- If given, only walk directories that match the wildcard
search -- A string dentifying the method used to walk the directories.
search -- A string dentifying the method used to walk the directories.
Can be 'breadth' for a breadth first search, or 'depth' for a
Can be 'breadth' for a breadth first search, or 'depth' for a
depth first search. Use 'depth' if you plan to create or
depth first search. Use 'depth' if you plan to create or
delete files as you go.
delete files as you go.
"""
"""
for
path
,
files
in
self
.
walk
(
path
,
wildcard
,
dir_wildcard
,
search
):
for
path
,
files
in
self
.
walk
(
path
,
wildcard
,
dir_wildcard
,
search
):
...
@@ -689,11 +695,26 @@ class FS(object):
...
@@ -689,11 +695,26 @@ class FS(object):
return
False
return
False
def
makeopendir
(
self
,
path
,
recursive
=
False
):
"""Makes a directory (if it doesn't exist) and returns an FS object for
the newly created directory.
path -- Path to the new directory
recursive -- If True any intermediate directories will be created
"""
self
.
makedir
(
path
,
allow_recreate
=
True
,
recursive
=
recursive
)
dir_fs
=
self
.
opendir
(
path
)
return
dir_fs
class
SubFS
(
FS
):
class
SubFS
(
FS
):
"""A SubFS represents a sub directory of another filesystem object.
"""A SubFS represents a sub directory of another filesystem object.
SubFS objects are returned by opendir, which effectively creates a
'sandbox'
SubFS objects are returned by opendir, which effectively creates a
'sandbox' filesystem that can only access files/dirs under a root path
'sandbox' filesystem that can only access files/dirs under a root path
within its 'parent' dir.
within its 'parent' dir.
"""
"""
...
@@ -825,4 +846,3 @@ def flags_to_mode(flags):
...
@@ -825,4 +846,3 @@ def flags_to_mode(flags):
else
:
else
:
mode
=
"r"
mode
=
"r"
return
mode
return
mode
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