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
42e2c078
Commit
42e2c078
authored
May 29, 2012
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HideFS
parent
98aa6c9e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
fs/base.py
+1
-1
fs/wrapfs/hidedotfilesfs.py
+2
-1
fs/wrapfs/hidefs.py
+46
-0
No files found.
fs/base.py
View file @
42e2c078
...
@@ -174,7 +174,7 @@ class FS(object):
...
@@ -174,7 +174,7 @@ class FS(object):
return
self
.
__str__
()
return
self
.
__str__
()
def
__del__
(
self
):
def
__del__
(
self
):
if
not
getattr
(
self
,
'closed'
,
Fals
e
):
if
not
getattr
(
self
,
'closed'
,
Tru
e
):
try
:
try
:
self
.
close
()
self
.
close
()
except
:
except
:
...
...
fs/wrapfs/hidedotfilesfs.py
View file @
42e2c078
...
@@ -8,6 +8,7 @@ An FS wrapper class for hiding dot-files in directory listings.
...
@@ -8,6 +8,7 @@ An FS wrapper class for hiding dot-files in directory listings.
from
fs.wrapfs
import
WrapFS
from
fs.wrapfs
import
WrapFS
from
fs.path
import
*
from
fs.path
import
*
from
fnmatch
import
fnmatch
class
HideDotFilesFS
(
WrapFS
):
class
HideDotFilesFS
(
WrapFS
):
...
@@ -59,7 +60,7 @@ class HideDotFilesFS(WrapFS):
...
@@ -59,7 +60,7 @@ class HideDotFilesFS(WrapFS):
path
=
pathjoin
(
current_path
,
filename
)
path
=
pathjoin
(
current_path
,
filename
)
if
self
.
isdir
(
path
):
if
self
.
isdir
(
path
):
if
dir_wildcard
is
not
None
:
if
dir_wildcard
is
not
None
:
if
fnmatch
(
path
,
dir_wilcard
):
if
fnmatch
(
path
,
dir_wil
d
card
):
dirs
.
append
(
path
)
dirs
.
append
(
path
)
else
:
else
:
dirs
.
append
(
path
)
dirs
.
append
(
path
)
...
...
fs/wrapfs/hidefs.py
0 → 100644
View file @
42e2c078
"""
fs.wrapfs.hidefs
================
Removes resources from a directory listing if they match a given set of wildcards
"""
from
fs.wrapfs
import
WrapFS
from
fs.path
import
basename
import
re
import
fnmatch
class
HideFS
(
WrapFS
):
"""FS wrapper that hides resources if they match a wildcard(s).
For example, to hide all pyc file and subversion directories from a filesystem::
HideFS(my_fs, "*.pyc", ".svn")
"""
def
__init__
(
self
,
wrapped_fs
,
*
hide_wildcards
):
self
.
_hide_wildcards
=
[
re
.
compile
(
fnmatch
.
translate
(
wildcard
))
for
wildcard
in
hide_wildcards
]
super
(
HideFS
,
self
)
.
__init__
(
wrapped_fs
)
def
_should_hide
(
self
,
name
):
name
=
basename
(
name
)
return
any
(
wildcard
.
match
(
name
)
for
wildcard
in
self
.
_hide_wildcards
)
def
_encode
(
self
,
path
):
return
path
def
_decode
(
self
,
path
):
return
path
def
listdir
(
self
,
path
=
""
,
*
args
,
**
kwargs
):
entries
=
super
(
HideFS
,
self
)
.
listdir
(
path
,
*
args
,
**
kwargs
)
entries
=
[
entry
for
entry
in
entries
if
not
self
.
_should_hide
(
entry
)]
return
entries
if
__name__
==
"__main__"
:
from
fs.osfs
import
OSFS
hfs
=
HideFS
(
OSFS
(
'~/projects/pyfilesystem'
),
"*.pyc"
,
".svn"
)
hfs
.
tree
()
\ 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