This repository was archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevserver
More file actions
executable file
·85 lines (72 loc) · 3.1 KB
/
devserver
File metadata and controls
executable file
·85 lines (72 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#--------------------------------------------------------------------------------------------------
# Program Name: vitrail
# Program Description: HTML/CSS/JavaScript user agent for the Cantus API.
#
# Filename: devserver
# Purpose: Script to concurrently run "babel" and the SimpleHTTPServer module.
#
# Copyright (C) 2015 Christopher Antila
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#--------------------------------------------------------------------------------------------------
'''
Script to concurrently run "watchify" and the SimpleHTTPServer module.
'''
from http import server
import pathlib
import subprocess
# list of the JS files that must be compiled with Watchify; it's input filename, then output filename
_COMPILE_WITH_WATCHIFY = [
('js/vitrail-init.js', 'js/vitrail.js'),
]
_PATH_TO_WATCHIFY = 'node_modules/watchify/bin/cmd.js'
def the_script():
# see if we can find/use watchify
watchify = pathlib.Path(_PATH_TO_WATCHIFY)
if not watchify.exists():
print('Could not find Watchify. Is it installed?')
raise SystemExit(1)
del watchify # because this will be a long-running script
# hold the Popen instances
subprocesses = []
try:
# set up some Watchify instances
for each_file in _COMPILE_WITH_WATCHIFY:
print('Starting Watchify for {}'.format(each_file[0]))
try:
kummand = [_PATH_TO_WATCHIFY, each_file[0], '-o', each_file[1], '--debug']
subprocesses.append(subprocess.Popen(kummand))
except subprocess.CalledProcessError as cperr:
print('Encountered the following error while starting Watchify:\n{}'.format(cperr))
raise SystemExit(1)
# now run the SimpleHTTPServer
# we'll catch KeyboardInterrupt so we can try killing babel on the way out
try:
print('Starting the HTTPServer')
server_address = ('', 8000)
httpd = server.HTTPServer(server_address, server.SimpleHTTPRequestHandler)
httpd.serve_forever()
except KeyboardInterrupt:
print('')
finally:
for each_instance in subprocesses:
print('Terminating subprocess with PID {}'.format(each_instance.pid))
each_instance.terminate()
each_instance.wait(timeout=30)
if '__main__' == __name__:
the_script()
else:
print('This script is only intended to be run from a commandline.')