Update upstream source from tag 'upstream/2.5.1'
Update to upstream version '2.5.1'
with Debian dir 3938ab6b0707d793925852c772102cef08256e40
Antonio Terceiro
6 years ago
1 | 1 | ========= |
2 | 2 | |
3 | 3 | The full list of changes between each Python LiveReload release. |
4 | ||
5 | Version 2.5.1 | |
6 | ------------- | |
7 | ||
8 | Release on Jan 7, 2017 | |
9 | ||
10 | Happy New Year. | |
11 | ||
12 | 1. Fix Content-Type detection | |
13 | 2. Ensure current version of pyinotify is installed before using | |
14 | ||
15 | Version 2.5.0 | |
16 | ------------- | |
17 | ||
18 | Released on Nov 16, 2016 | |
19 | ||
20 | 1. wait parameter can be float via Todd Wolfson | |
21 | 2. Option to disable liveCSS via Yunchi Luo | |
22 | 3. Django management command via Marc-Stefan Cassola | |
23 | ||
24 | Version 2.4.1 | |
25 | ------------- | |
26 | ||
27 | Released on Jan 19, 2016 | |
28 | ||
29 | 1. Allow other hostname with JS script location.hostname | |
30 | 2. Expose delay parameter in command line tool | |
31 | 3. Server.watch accept ignore parameter | |
4 | 32 | |
5 | 33 | Version 2.4.0 |
6 | 34 | ------------- |
125 | 153 | + Static Server support index |
126 | 154 | + Dynamic watch directory changes |
127 | 155 | |
128 | .. _ver0.6: | |
129 | ||
130 | 156 | Version 0.6 |
131 | 157 | ------------ |
132 | 158 | Release on Jun 18th, 2012 |
133 | 159 | |
134 | 160 | + Add static server, 127.0.0.1:35729 |
135 | ||
136 | .. _ver0.5: | |
137 | 161 | |
138 | 162 | Version 0.5 |
139 | 163 | ----------- |
141 | 165 | |
142 | 166 | + support for python3 |
143 | 167 | |
144 | .. _ver0.4: | |
145 | ||
146 | 168 | Version 0.4 |
147 | 169 | ----------- |
148 | 170 | Release on May 8th, 2012 |
149 | 171 | |
150 | 172 | + bugfix for notify (sorry) |
151 | ||
152 | .. _ver0.3: | |
153 | 173 | |
154 | 174 | Version 0.3 |
155 | 175 | ----------- |
0 | Copyright (c) 2012-2013, Hsiaoming Yang <me@lepture.com> | |
0 | Copyright (c) 2012-2015, Hsiaoming Yang <me@lepture.com> | |
1 | 1 | |
2 | 2 | Redistribution and use in source and binary forms, with or without |
3 | 3 | modification, are permitted provided that the following conditions |
2 | 2 | |
3 | 3 | This is a brand new LiveReload in version 2.0.0. |
4 | 4 | |
5 | .. image:: https://pypip.in/d/livereload/badge.png | |
5 | .. image:: https://img.shields.io/pypi/dm/livereload.svg | |
6 | 6 | :target: https://pypi.python.org/pypi/livereload |
7 | 7 | :alt: Downloads |
8 | .. image:: https://pypip.in/v/livereload/badge.png | |
8 | .. image:: https://img.shields.io/pypi/v/livereload.svg | |
9 | 9 | :target: https://pypi.python.org/pypi/livereload |
10 | 10 | :alt: Version |
11 | 11 | |
31 | 31 | By default, it will listen to port 35729, the common port for `LiveReload browser extensions`_. :: |
32 | 32 | |
33 | 33 | $ livereload --help |
34 | usage: livereload [-h] [-p PORT] [directory] | |
34 | usage: livereload [-h] [-p PORT] [-w WAIT] [directory] | |
35 | 35 | |
36 | 36 | Start a `livereload` server |
37 | 37 | |
41 | 41 | optional arguments: |
42 | 42 | -h, --help show this help message and exit |
43 | 43 | -p PORT, --port PORT Port to run `livereload` server on |
44 | -w WAIT, --wait WAIT Time delay before reloading | |
44 | 45 | |
45 | 46 | .. _`livereload browser extensions`: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- |
46 | 47 | |
155 | 156 | Django |
156 | 157 | ~~~~~~ |
157 | 158 | |
158 | Here is a little hint on Django. Change your ``manage.py`` file to: | |
159 | ||
160 | .. code:: python | |
161 | ||
162 | #!/usr/bin/env python | |
163 | import os | |
164 | import sys | |
165 | ||
166 | if __name__ == "__main__": | |
167 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello.settings") | |
168 | ||
169 | from django.core.management import execute_from_command_line | |
170 | ||
171 | if 'livereload' in sys.argv: | |
172 | from django.core.wsgi import get_wsgi_application | |
173 | from livereload import Server | |
174 | application = get_wsgi_application() | |
175 | server = Server(application) | |
176 | ||
177 | # Add your watch | |
178 | # server.watch('path/to/file', 'your command') | |
179 | server.serve() | |
180 | else: | |
181 | execute_from_command_line(sys.argv) | |
182 | ||
183 | When you execute ``./manage.py livereload``, it will start a livereload server. | |
184 | ||
159 | For Django there is a management command included. | |
160 | ||
161 | To use simply | |
162 | ||
163 | - add ``'livereload'`` to your ``INSTALLED_APPS`` and | |
164 | - then run ``./manage.py livereload``. | |
165 | ||
166 | For available options like host and ports please refer to ``./manage.py livereload -h``. | |
167 | ||
168 | To automagically serve static files like the native ``runserver`` command you have to use `dj-static <https://github.com/kennethreitz/dj-static>`_. (follow the simple instructions there). | |
185 | 169 | |
186 | 170 | Flask |
187 | 171 | ~~~~~ |
192 | 176 | |
193 | 177 | # app is a Flask object |
194 | 178 | app = create_app() |
179 | ||
180 | # remember to use DEBUG mode for templates auto reload | |
181 | # https://github.com/lepture/python-livereload/issues/144 | |
182 | app.debug = True | |
195 | 183 | |
196 | 184 | server = Server(app.wsgi_app) |
197 | 185 | # server.watch |
38 | 38 | clean: |
39 | 39 | -rm -rf $(BUILDDIR)/* |
40 | 40 | |
41 | html: | |
41 | html: _themes/.git | |
42 | 42 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html |
43 | 43 | @echo |
44 | 44 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." |
148 | 148 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest |
149 | 149 | @echo "Testing of doctests in the sources finished, look at the " \ |
150 | 150 | "results in $(BUILDDIR)/doctest/output.txt." |
151 | ||
152 | ||
153 | _themes/.git: | |
154 | git submodule update --init |
99 | 99 | # documentation. |
100 | 100 | html_theme_options = { |
101 | 101 | 'index_logo': None, |
102 | 'github_fork': 'lepture/python-livereload', | |
102 | 103 | } |
103 | 104 | |
104 | 105 | # Add any paths that contain custom themes here, relative to this directory. |
3 | 3 | |
4 | 4 | A python version of livereload. |
5 | 5 | |
6 | :copyright: (c) 2013 by Hsiaoming Yang | |
6 | :copyright: (c) 2013 - 2017 by Hsiaoming Yang | |
7 | :license: BSD, see LICENSE for more details. | |
7 | 8 | """ |
8 | 9 | |
9 | __version__ = '2.4.0' | |
10 | __version__ = '2.5.1' | |
10 | 11 | __author__ = 'Hsiaoming Yang <me@lepture.com>' |
11 | 12 | __homepage__ = 'https://github.com/lepture/python-livereload' |
12 | 13 |
21 | 21 | default='.', |
22 | 22 | nargs='?' |
23 | 23 | ) |
24 | parser.add_argument( | |
25 | '-w', '--wait', | |
26 | help='Time delay in seconds before reloading', | |
27 | type=float, | |
28 | default=0.0 | |
29 | ) | |
24 | 30 | |
25 | 31 | |
26 | 32 | def main(argv=None): |
28 | 34 | |
29 | 35 | # Create a new application |
30 | 36 | server = Server() |
31 | server.watcher.watch(args.directory) | |
37 | server.watcher.watch(args.directory, delay=args.wait) | |
32 | 38 | server.serve(host=args.host, port=args.port, root=args.directory) |
5 | 5 | HTTP and WebSocket handlers for livereload. |
6 | 6 | |
7 | 7 | :copyright: (c) 2013 - 2015 by Hsiaoming Yang |
8 | :license: BSD, see LICENSE for more details. | |
8 | 9 | """ |
9 | 10 | |
10 | 11 | import os |
23 | 24 | class LiveReloadHandler(WebSocketHandler): |
24 | 25 | waiters = set() |
25 | 26 | watcher = None |
27 | live_css = None | |
26 | 28 | _last_reload_time = None |
27 | 29 | |
28 | 30 | def allow_draft76(self): |
96 | 98 | msg = { |
97 | 99 | 'command': 'reload', |
98 | 100 | 'path': path, |
99 | 'liveCSS': True, | |
101 | 'liveCSS': cls.live_css, | |
100 | 102 | 'liveImg': True, |
101 | 103 | } |
102 | 104 |
0 | import os | |
1 | import re | |
2 | from django.core.management.base import BaseCommand, CommandError | |
3 | from django.core.management.commands.runserver import naiveip_re | |
4 | from django.core.servers.basehttp import get_internal_wsgi_application | |
5 | from livereload import Server | |
6 | ||
7 | ||
8 | class Command(BaseCommand): | |
9 | help = 'Runs the development server with livereload enabled.' | |
10 | ||
11 | def add_arguments(self, parser): | |
12 | parser.add_argument('addrport', | |
13 | nargs='?', | |
14 | default='127.0.0.1:8000', | |
15 | help='host and optional port the django server should listen on (default: 127.0.0.1:8000)') | |
16 | parser.add_argument('-l', '--liveport', | |
17 | type=int, | |
18 | default=35729, | |
19 | help='port the livereload server should listen on (default: 35729)') | |
20 | ||
21 | def handle(self, *args, **options): | |
22 | m = re.match(naiveip_re, options['addrport']) | |
23 | if m is None: | |
24 | raise CommandError('"%s" is not a valid port number ' | |
25 | 'or address:port pair.' % options['addrport']) | |
26 | addr, _ipv4, _ipv6, _fqdn, port = m.groups() | |
27 | if not port.isdigit(): | |
28 | raise CommandError("%r is not a valid port number." % port) | |
29 | ||
30 | if addr: | |
31 | if _ipv6: | |
32 | raise CommandError('IPv6 addresses are currently not supported.') | |
33 | ||
34 | ||
35 | application = get_internal_wsgi_application() | |
36 | server = Server(application) | |
37 | ||
38 | for file in os.listdir('.'): | |
39 | if file[0] != '.' and file[:2] != '__' and os.path.isdir(file): | |
40 | server.watch(file) | |
41 | ||
42 | server.serve(host=addr, port=port, liveport=options['liveport']) |
4 | 4 | |
5 | 5 | WSGI app server for livereload. |
6 | 6 | |
7 | :copyright: (c) 2013 by Hsiaoming Yang | |
7 | :copyright: (c) 2013 - 2015 by Hsiaoming Yang | |
8 | :license: BSD, see LICENSE for more details. | |
8 | 9 | """ |
9 | 10 | |
10 | 11 | import os |
129 | 130 | |
130 | 131 | if status_code != 304: |
131 | 132 | if "content-type" not in header_set: |
132 | headers.append(("Content-Type", "text/html; charset=UTF-8")) | |
133 | headers.append(("Content-Type", "application/octet-stream; charset=UTF-8")) | |
133 | 134 | if "content-length" not in header_set: |
134 | 135 | headers.append(("Content-Length", str(len(body)))) |
135 | 136 | |
141 | 142 | ) |
142 | 143 | header_obj = httputil.HTTPHeaders() |
143 | 144 | for key, value in headers: |
144 | if key == 'Content-Length': | |
145 | if key.lower() == 'content-length': | |
145 | 146 | value = str(len(body)) |
146 | 147 | header_obj.add(key, value) |
147 | 148 | request.connection.write_headers(start_line, header_obj, chunk=body) |
172 | 173 | watcher = watcher_cls() |
173 | 174 | self.watcher = watcher |
174 | 175 | |
175 | def watch(self, filepath, func=None, delay=None): | |
176 | def watch(self, filepath, func=None, delay=None, ignore=None): | |
176 | 177 | """Add the given filepath for watcher list. |
177 | 178 | |
178 | 179 | Once you have intialized a server, watch file changes before |
192 | 193 | :param delay: Delay sending the reload message. Use 'forever' to |
193 | 194 | not send it. This is useful to compile sass files to |
194 | 195 | css, but reload on changed css files then only. |
196 | :param ignore: A function return True to ignore a certain pattern of | |
197 | filepath. | |
195 | 198 | """ |
196 | 199 | if isinstance(func, string_types): |
197 | 200 | func = shell(func) |
198 | 201 | |
199 | self.watcher.watch(filepath, func, delay) | |
200 | ||
201 | def application(self, port, host, liveport=None, debug=None): | |
202 | self.watcher.watch(filepath, func, delay, ignore=ignore) | |
203 | ||
204 | def application(self, port, host, liveport=None, debug=None, live_css=True): | |
202 | 205 | LiveReloadHandler.watcher = self.watcher |
206 | LiveReloadHandler.live_css = live_css | |
203 | 207 | if liveport is None: |
204 | 208 | liveport = port |
205 | 209 | if debug is None and self.app: |
211 | 215 | (r'/livereload.js', LiveReloadJSHandler) |
212 | 216 | ] |
213 | 217 | |
218 | # The livereload.js snippet. | |
219 | # Uses JavaScript to dynamically inject the client's hostname. | |
220 | # This allows for serving on 0.0.0.0. | |
214 | 221 | live_script = escape.utf8(( |
215 | '<script src="http://{host}:{port}/livereload.js"></script>' | |
216 | ).format(host=host, port=liveport)) | |
222 | '<script type="text/javascript">' | |
223 | 'document.write("<script src=''http://"' | |
224 | ' + window.location.hostname + ":{port}/livereload.js''>' | |
225 | ' </"+"script>");' | |
226 | '</script>' | |
227 | ).format(port=liveport)) | |
217 | 228 | |
218 | 229 | web_handlers = self.get_web_handlers(live_script) |
219 | 230 | |
250 | 261 | ] |
251 | 262 | |
252 | 263 | def serve(self, port=5500, liveport=None, host=None, root=None, debug=None, |
253 | open_url=False, restart_delay=2, open_url_delay=None): | |
264 | open_url=False, restart_delay=2, open_url_delay=None, live_css=True): | |
254 | 265 | """Start serve the server with the given port. |
255 | 266 | |
256 | 267 | :param port: serve on this port, default is 5500 |
261 | 272 | via Tornado (and causes polling). Defaults to True when |
262 | 273 | ``self.app`` is set, otherwise False. |
263 | 274 | :param open_url_delay: open webbrowser after the delay seconds |
275 | :param live_css: whether to use live css or force reload on css. Defaults to True | |
264 | 276 | """ |
265 | 277 | host = host or '127.0.0.1' |
266 | 278 | if root is not None: |
269 | 281 | self._setup_logging() |
270 | 282 | logger.info('Serving on http://%s:%s' % (host, port)) |
271 | 283 | |
272 | self.application(port, host, liveport=liveport, debug=debug) | |
284 | self.application(port, host, liveport=liveport, debug=debug, live_css=live_css) | |
273 | 285 | |
274 | 286 | # Async open web browser after 5 sec timeout |
275 | 287 | if open_url or open_url_delay: |
5 | 5 | A file watch management for LiveReload Server. |
6 | 6 | |
7 | 7 | :copyright: (c) 2013 - 2015 by Hsiaoming Yang |
8 | :license: BSD, see LICENSE for more details. | |
8 | 9 | """ |
9 | 10 | |
10 | 11 | import os |
70 | 71 | func = item['func'] |
71 | 72 | func and func() |
72 | 73 | delay = item['delay'] |
73 | if delay and isinstance(delay, int): | |
74 | if delay and isinstance(delay, float): | |
74 | 75 | delays.add(delay) |
75 | 76 | |
76 | 77 | if delays: |
164 | 165 | |
165 | 166 | |
166 | 167 | def get_watcher_class(): |
167 | if pyinotify is None: | |
168 | if pyinotify is None or not hasattr(pyinotify, 'TornadoAsyncNotifier'): | |
168 | 169 | return Watcher |
169 | 170 | return INotifyWatcher |
22 | 22 | author='Hsiaoming Yang', |
23 | 23 | author_email='me@lepture.com', |
24 | 24 | url='https://github.com/lepture/python-livereload', |
25 | packages=['livereload'], | |
25 | packages=['livereload', 'livereload.management.commands'], | |
26 | 26 | description='Python LiveReload is an awesome tool for web developers', |
27 | 27 | long_description=fread('README.rst'), |
28 | 28 | entry_points={ |