Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
63765165
Commit
63765165
authored
Jul 25, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding script that restarts django when content in the data directories changes.
parent
dde48f12
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
run_watch_data.py
+51
-0
No files found.
run_watch_data.py
0 → 100755
View file @
63765165
#! ../python/bin/python
# This script requires that you have watchdog installed. You can install
# watchdog via 'pip install watchdog'
import
sys
import
time
import
logging
import
os
from
subprocess
import
Popen
from
signal
import
SIGTERM
from
watchdog.observers
import
Observer
from
watchdog.events
import
LoggingEventHandler
,
FileSystemEventHandler
# To watch more (or more specific) directories, change WATCH_DIRS to include the
# directories you want to watch. Note that this is recursive. If you want to
# watch fewer or more extensions, you can change EXTENSIONS.
WATCH_DIRS
=
[
"../data"
]
EXTENSIONS
=
[
"xml"
,
"js"
,
"css"
,
"coffee"
,
"scss"
,
"html"
]
WATCH_DIRS
=
[
os
.
path
.
abspath
(
os
.
path
.
normpath
(
dir
))
for
dir
in
WATCH_DIRS
]
class
DjangoEventHandler
(
FileSystemEventHandler
):
def
__init__
(
self
,
process
):
FileSystemEventHandler
.
__init__
(
self
)
self
.
process
=
process
def
on_any_event
(
self
,
event
):
for
extension
in
EXTENSIONS
:
if
event
.
src_path
.
endswith
(
extension
):
print
"
%
s changed: restarting server."
%
event
.
src_path
self
.
process
.
terminate
()
os
.
system
(
"ps aux | grep 'django' | grep -v grep | awk '{print $2}' | xargs kill"
)
time
.
sleep
(
0.25
)
self
.
process
=
Popen
([
'rake'
,
'lms'
])
if
__name__
==
"__main__"
:
event_handler
=
DjangoEventHandler
(
Popen
([
'rake'
,
'lms'
]))
observer
=
Observer
()
for
dir
in
WATCH_DIRS
:
observer
.
schedule
(
event_handler
,
dir
,
recursive
=
True
)
observer
.
start
()
try
:
while
True
:
time
.
sleep
(
1
)
except
KeyboardInterrupt
:
observer
.
stop
()
observer
.
join
()
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