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
e7a81d2a
Commit
e7a81d2a
authored
Sep 16, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WatchableFS: generate more events in move() and movedir()
parent
b8b5c62a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
9 deletions
+44
-9
fs/path.py
+4
-4
fs/watch.py
+40
-5
No files found.
fs/path.py
View file @
e7a81d2a
...
...
@@ -84,14 +84,14 @@ def recursepath(path, reverse=False):
"""
if
reverse
:
paths
=
[]
path
=
abspath
(
path
)
.
rstrip
(
"/"
)
path
=
abspath
(
normpath
(
path
)
)
.
rstrip
(
"/"
)
while
path
:
paths
.
append
(
path
)
path
=
dirname
(
path
)
.
rstrip
(
"/"
)
return
paths
+
[
"/"
]
return
paths
+
[
u
"/"
]
else
:
paths
=
[
""
]
+
list
(
iteratepath
(
path
))
return
[
"/"
]
+
[
u'/'
.
join
(
paths
[:
i
+
1
])
for
i
in
xrange
(
1
,
len
(
paths
))]
paths
=
[
u
""
]
+
list
(
iteratepath
(
path
))
return
[
u
"/"
]
+
[
u'/'
.
join
(
paths
[:
i
+
1
])
for
i
in
xrange
(
1
,
len
(
paths
))]
def
abspath
(
path
):
"""Convert the given path to an absolute path.
...
...
fs/watch.py
View file @
e7a81d2a
...
...
@@ -47,6 +47,14 @@ class EVENT(object):
def
__unicode__
(
self
):
return
u"<fs.watch.
%
s object (path='
%
s') at
%
s>"
%
(
self
.
__class__
.
__name__
,
self
.
path
,
hex
(
id
(
self
)))
def
clone
(
self
,
fs
=
None
,
path
=
None
):
if
fs
is
None
:
fs
=
self
.
fs
if
path
is
None
:
path
=
self
.
path
return
self
.
__class__
(
fs
,
path
)
class
ACCESSED
(
EVENT
):
"""Event fired when a file's contents are accessed."""
pass
...
...
@@ -65,22 +73,43 @@ class MODIFIED(EVENT):
super
(
MODIFIED
,
self
)
.
__init__
(
fs
,
path
)
self
.
data_changed
=
data_changed
def
clone
(
self
,
fs
=
None
,
path
=
None
,
data_changed
=
None
):
evt
=
super
(
MODIFIED
,
self
)
.
clone
()
if
data_changed
is
None
:
data_changed
=
self
.
data_changed
evt
.
data_changd
=
data_changed
return
evt
class
MOVED_DST
(
EVENT
):
"""Event fired when a file or directory is the target of a move."""
def
__init__
(
self
,
fs
,
path
,
source
):
def
__init__
(
self
,
fs
,
path
,
source
=
None
):
super
(
MOVED_DST
,
self
)
.
__init__
(
fs
,
path
)
if
source
is
not
None
:
source
=
abspath
(
normpath
(
source
))
self
.
source
=
source
def
clone
(
self
,
fs
=
None
,
path
=
None
,
source
=
None
):
evt
=
super
(
MOVED_DST
,
self
)
.
clone
()
if
source
is
None
:
source
=
self
.
source
evt
.
source
=
source
return
evt
class
MOVED_SRC
(
EVENT
):
"""Event fired when a file or directory is the source of a move."""
def
__init__
(
self
,
fs
,
path
,
destination
):
def
__init__
(
self
,
fs
,
path
,
destination
=
None
):
super
(
MOVED_SRC
,
self
)
.
__init__
(
fs
,
path
)
if
destination
is
not
None
:
destination
=
abspath
(
normpath
(
destination
))
self
.
destination
=
destination
def
clone
(
self
,
fs
=
None
,
path
=
None
,
destination
=
None
):
evt
=
super
(
MOVED_SRC
,
self
)
.
clone
()
if
destination
is
None
:
destination
=
self
.
destination
evt
.
destination
=
destination
return
evt
class
CLOSED
(
EVENT
):
"""Event fired when the filesystem is closed."""
pass
...
...
@@ -302,8 +331,8 @@ class WatchableFS(WrapFS,WatchableFSMixin):
super
(
WatchableFS
,
self
)
.
rename
(
src
,
dst
)
if
d_existed
:
self
.
notify_watchers
(
REMOVED
,
dst
)
self
.
notify_watchers
(
MOVED_SRC
,
src
,
dst
)
self
.
notify_watchers
(
MOVED_DST
,
dst
,
src
)
self
.
notify_watchers
(
MOVED_SRC
,
src
,
dst
)
def
copy
(
self
,
src
,
dst
,
**
kwds
):
d
=
self
.
_pre_copy
(
src
,
dst
)
...
...
@@ -319,13 +348,13 @@ class WatchableFS(WrapFS,WatchableFSMixin):
d
=
self
.
_pre_copy
(
src
,
dst
)
super
(
WatchableFS
,
self
)
.
move
(
src
,
dst
,
**
kwds
)
self
.
_post_copy
(
src
,
dst
,
d
)
self
.
notify_watchers
(
REMOVED
,
src
)
self
.
_post_move
(
src
,
dst
,
d
)
def
movedir
(
self
,
src
,
dst
,
**
kwds
):
d
=
self
.
_pre_copy
(
src
,
dst
)
super
(
WatchableFS
,
self
)
.
movedir
(
src
,
dst
,
**
kwds
)
self
.
_post_copy
(
src
,
dst
,
d
)
self
.
notify_watchers
(
REMOVED
,
src
)
self
.
_post_move
(
src
,
dst
,
d
)
def
_pre_copy
(
self
,
src
,
dst
):
dst_paths
=
{}
...
...
@@ -365,6 +394,12 @@ class WatchableFS(WrapFS,WatchableFSMixin):
if
not
self
.
wrapped_fs
.
exists
(
path
):
self
.
notify_watchers
(
REMOVED
,
path
)
def
_post_move
(
self
,
src
,
dst
,
data
):
(
src_paths
,
dst_paths
)
=
data
for
src_path
,
isdir
in
sorted
(
src_paths
.
items
(),
reverse
=
True
):
path
=
pathjoin
(
src
,
src_path
)
self
.
notify_watchers
(
REMOVED
,
path
)
def
setxattr
(
self
,
path
,
name
,
value
):
super
(
WatchableFS
,
self
)
.
setxattr
(
path
,
name
,
value
)
self
.
notify_watchers
(
MODIFIED
,
path
,
False
)
...
...
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