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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
31 deletions
+21
-31
fs/watch.py
+21
-31
No files found.
fs/watch.py
View file @
b202f48c
...
@@ -39,6 +39,7 @@ from fs.path import *
...
@@ -39,6 +39,7 @@ from fs.path import *
from
fs.errors
import
*
from
fs.errors
import
*
from
fs.wrapfs
import
WrapFS
from
fs.wrapfs
import
WrapFS
from
fs.base
import
FS
from
fs.base
import
FS
from
fs.filelike
import
FileWrapper
class
EVENT
(
object
):
class
EVENT
(
object
):
...
@@ -241,51 +242,40 @@ class WatchableFSMixin(FS):
...
@@ -241,51 +242,40 @@ class WatchableFSMixin(FS):
class
WatchedFile
(
object
):
class
WatchedFile
(
FileWrapper
):
"""File wrapper for use with WatchableFS.
"""File wrapper for use with WatchableFS.
This file wrapper provides access to a file opened from a WatchableFS
This file wrapper provides access to a file opened from a WatchableFS
instance, and fires MODIFIED events when the file is modified.
instance, and fires MODIFIED events when the file is modified.
"""
"""
def
__init__
(
self
,
file
,
fs
,
path
,
mode
):
def
__init__
(
self
,
file
,
fs
,
path
,
mode
=
None
):
s
elf
.
file
=
file
s
uper
(
WatchedFile
,
self
)
.
__init__
(
file
,
mode
)
self
.
fs
=
fs
self
.
fs
=
fs
self
.
path
=
path
self
.
path
=
path
self
.
mode
=
mod
e
self
.
was_modified
=
Fals
e
def
__del__
(
self
):
def
_write
(
self
,
string
,
flushing
=
False
):
# Don't bother if python if being torn down
self
.
was_modified
=
True
if
Watcher
is
not
None
:
return
super
(
WatchedFile
,
self
)
.
_write
(
string
,
flushing
=
flushing
)
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
):
def
_truncate
(
self
,
size
):
self
.
file
.
__enter__
()
self
.
was_modified
=
True
return
self
return
super
(
WatchedFile
,
self
)
.
_truncate
(
size
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
close
()
return
False
def
__iter__
(
self
):
return
iter
(
self
.
file
)
def
flush
(
self
):
def
flush
(
self
):
self
.
file
.
flush
()
super
(
WatchedFile
,
self
)
.
flush
()
if
"w"
in
self
.
mode
or
"a"
in
self
.
mode
or
"+"
in
self
.
mode
:
# Don't bother if python if being torn down
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
if
Watcher
is
not
None
:
if
self
.
was_modified
:
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
def
close
(
self
):
def
close
(
self
):
self
.
file
.
close
()
super
(
WatchedFile
,
self
)
.
close
()
if
"w"
in
self
.
mode
or
"a"
in
self
.
mode
or
"+"
in
self
.
mode
:
# Don't bother if python if being torn down
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
if
Watcher
is
not
None
:
if
self
.
was_modified
:
self
.
fs
.
notify_watchers
(
MODIFIED
,
self
.
path
,
True
)
class
WatchableFS
(
WatchableFSMixin
,
WrapFS
):
class
WatchableFS
(
WatchableFSMixin
,
WrapFS
):
...
...
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