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
b202f48c
Commit
b202f48c
authored
Jan 05, 2011
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs.watch.WatchedFile: inherit from FileWrapper, send MODIFIED only on write
parent
c4bf5237
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
29 deletions
+19
-29
fs/watch.py
+19
-29
No files found.
fs/watch.py
View file @
b202f48c
...
...
@@ -39,6 +39,7 @@ from fs.path import *
from
fs.errors
import
*
from
fs.wrapfs
import
WrapFS
from
fs.base
import
FS
from
fs.filelike
import
FileWrapper
class
EVENT
(
object
):
...
...
@@ -241,50 +242,39 @@ class WatchableFSMixin(FS):
class
WatchedFile
(
object
):
class
WatchedFile
(
FileWrapper
):
"""File wrapper for use with WatchableFS.
This file wrapper provides access to a file opened from a WatchableFS
instance, and fires MODIFIED events when the file is modified.
"""
def
__init__
(
self
,
file
,
fs
,
path
,
mode
):
s
elf
.
file
=
file
def
__init__
(
self
,
file
,
fs
,
path
,
mode
=
None
):
s
uper
(
WatchedFile
,
self
)
.
__init__
(
file
,
mode
)
self
.
fs
=
fs
self
.
path
=
path
self
.
mode
=
mod
e
self
.
was_modified
=
Fals
e
def
__del__
(
self
):
# Don't bother if python if being torn down
if
Watcher
is
not
None
:
self
.
close
()
def
__getattr__
(
self
,
name
):
file
=
self
.
__dict__
[
'file'
]
a
=
getattr
(
file
,
name
)
if
callable
(
a
):
setattr
(
self
,
name
,
a
)
return
a
def
__enter__
(
self
):
self
.
file
.
__enter__
()
return
self
def
_write
(
self
,
string
,
flushing
=
False
):
self
.
was_modified
=
True
return
super
(
WatchedFile
,
self
)
.
_write
(
string
,
flushing
=
flushing
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
close
()
return
False
def
__iter__
(
self
):
return
iter
(
self
.
file
)
def
_truncate
(
self
,
size
):
self
.
was_modified
=
True
return
super
(
WatchedFile
,
self
)
.
_truncate
(
size
)
def
flush
(
self
):
self
.
file
.
flush
()
if
"w"
in
self
.
mode
or
"a"
in
self
.
mode
or
"+"
in
self
.
mode
:
super
(
WatchedFile
,
self
)
.
flush
()
# Don't bother if python if being torn down
if
Watcher
is
not
None
:
if
self
.
was_modified
:
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
def
close
(
self
):
self
.
file
.
close
()
if
"w"
in
self
.
mode
or
"a"
in
self
.
mode
or
"+"
in
self
.
mode
:
super
(
WatchedFile
,
self
)
.
close
()
# Don't bother if python if being torn down
if
Watcher
is
not
None
:
if
self
.
was_modified
:
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
...
...
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