Mercurial > repos > bgruening > jbrowse2
annotate jb2_webserver.py @ 0:53c2be00bb6f draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
author | bgruening |
---|---|
date | Wed, 05 Jun 2024 08:15:49 +0000 |
parents | |
children |
rev | line source |
---|---|
0
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
2 # spec: simplest python web server with range support and multithreading that takes root path, |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
3 # port and bind address as command line arguments; by default uses the current dir as webroot, |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
4 # port 8000 and bind address of 0.0.0.0 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
5 # borrowed from https://github.com/danvk/RangeHTTPServer |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
6 # and reborrowed from https://gist.github.com/glowinthedark/b99900abe935e4ab4857314d647a9068 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
7 # |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
8 # The Apache 2.0 license copy in this repository is distributed with this code in accordance with that licence. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
9 # https://www.apache.org/licenses/LICENSE-2.0.txt |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
10 # This part is not MIT licenced like the other components. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
11 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
12 # APPENDIX: How to apply the Apache License to your work. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
13 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
14 # To apply the Apache License to your work, attach the following |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
15 # boilerplate notice, with the fields enclosed by brackets "[]" |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
16 # replaced with your own identifying information. (Don't include |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
17 # the brackets!) The text should be enclosed in the appropriate |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
18 # comment syntax for the file format. We also recommend that a |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
19 # file or class name and description of purpose be included on the |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
20 # same "printed page" as the copyright notice for easier |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
21 # identification within third-party archives. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
22 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
23 # Licensed under the Apache License, Version 2.0 (the "License"); |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
24 # you may not use this file except in compliance with the License. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
25 # You may obtain a copy of the License at |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
26 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
27 # http://www.apache.org/licenses/LICENSE-2.0 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
28 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
29 # Unless required by applicable law or agreed to in writing, software |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
30 # distributed under the License is distributed on an "AS IS" BASIS, |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
31 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
32 # See the License for the specific language governing permissions and |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
33 # limitations under the License. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
34 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
35 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
36 import argparse |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
37 import functools |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
38 import os |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
39 import re |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
40 import socketserver |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
41 import webbrowser |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
42 from http.server import SimpleHTTPRequestHandler |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
43 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
44 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
45 DEFAULT_PORT = 8081 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
46 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
47 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
48 def copy_byte_range(infile, outfile, start=None, stop=None, bufsize=16 * 1024): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
49 """Like shutil.copyfileobj, but only copy a range of the streams. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
50 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
51 Both start and stop are inclusive. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
52 """ |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
53 if start is not None: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
54 infile.seek(start) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
55 while 1: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
56 to_read = min(bufsize, stop + 1 - infile.tell() if stop else bufsize) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
57 buf = infile.read(to_read) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
58 if not buf: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
59 break |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
60 outfile.write(buf) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
61 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
62 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
63 BYTE_RANGE_RE = re.compile(r"bytes=(\d+)-(\d+)?$") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
64 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
65 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
66 def parse_byte_range(byte_range): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
67 """Returns the two numbers in 'bytes=123-456' or throws ValueError. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
68 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
69 The last number or both numbers may be None. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
70 """ |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
71 if byte_range.strip() == "": |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
72 return None, None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
73 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
74 m = BYTE_RANGE_RE.match(byte_range) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
75 if not m: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
76 raise ValueError("Invalid byte range %s" % byte_range) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
77 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
78 first, last = [x and int(x) for x in m.groups()] |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
79 if last and last < first: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
80 raise ValueError("Invalid byte range %s" % byte_range) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
81 return first, last |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
82 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
83 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
84 class RangeRequestHandler(SimpleHTTPRequestHandler): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
85 """Adds support for HTTP 'Range' requests to SimpleHTTPRequestHandler |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
86 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
87 The approach is to: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
88 - Override send_head to look for 'Range' and respond appropriately. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
89 - Override copyfile to only transmit a range when requested. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
90 """ |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
91 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
92 def handle(self): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
93 try: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
94 SimpleHTTPRequestHandler.handle(self) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
95 except Exception: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
96 # ignored, thrown whenever the client aborts streaming (broken pipe) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
97 pass |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
98 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
99 def send_head(self): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
100 if "Range" not in self.headers: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
101 self.range = None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
102 return SimpleHTTPRequestHandler.send_head(self) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
103 try: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
104 self.range = parse_byte_range(self.headers["Range"]) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
105 except ValueError: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
106 self.send_error(400, "Invalid byte range") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
107 return None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
108 first, last = self.range |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
109 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
110 # Mirroring SimpleHTTPServer.py here |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
111 path = self.translate_path(self.path) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
112 f = None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
113 ctype = self.guess_type(path) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
114 try: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
115 f = open(path, "rb") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
116 except IOError: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
117 self.send_error(404, "File not found") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
118 return None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
119 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
120 fs = os.fstat(f.fileno()) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
121 file_len = fs[6] |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
122 if first >= file_len: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
123 self.send_error(416, "Requested Range Not Satisfiable") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
124 return None |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
125 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
126 self.send_response(206) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
127 self.send_header("Content-type", ctype) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
128 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
129 if last is None or last >= file_len: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
130 last = file_len - 1 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
131 response_length = last - first + 1 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
132 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
133 self.send_header("Content-Range", "bytes %s-%s/%s" % (first, last, file_len)) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
134 self.send_header("Content-Length", str(response_length)) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
135 self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
136 self.end_headers() |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
137 return f |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
138 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
139 def end_headers(self): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
140 self.send_header("Accept-Ranges", "bytes") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
141 return SimpleHTTPRequestHandler.end_headers(self) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
142 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
143 def copyfile(self, source, outputfile): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
144 if not self.range: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
145 return SimpleHTTPRequestHandler.copyfile(self, source, outputfile) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
146 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
147 # SimpleHTTPRequestHandler uses shutil.copyfileobj, which doesn't let |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
148 # you stop the copying before the end of the file. |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
149 start, stop = self.range # set in send_head() |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
150 copy_byte_range(source, outputfile, start, stop) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
151 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
152 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
153 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
154 allow_reuse_address = True |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
155 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
156 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
157 if __name__ == "__main__": |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
158 parser = argparse.ArgumentParser( |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
159 description="Tiny Python Web Server supporting range requests, for local viewing of unzipped Galaxy JBrowse2 configurations" |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
160 ) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
161 parser.add_argument( |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
162 "--root", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
163 default=os.getcwd(), |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
164 help="Root path to serve files from (default: current working directory)", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
165 ) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
166 parser.add_argument( |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
167 "--port", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
168 type=int, |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
169 default=DEFAULT_PORT, |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
170 help=f"Port to listen on (default: {DEFAULT_PORT})", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
171 ) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
172 parser.add_argument( |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
173 "--bind", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
174 default="127.0.0.1", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
175 help="IP address to bind to (default: 127.0.0.1 - use 0.0.0.0 to allow access on your network)", |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
176 ) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
177 args = parser.parse_args() |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
178 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
179 handler = functools.partial(RangeRequestHandler, directory=args.root) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
180 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
181 webbrowser.open(f"http://{args.bind}:{args.port}") |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
182 |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
183 with ThreadedTCPServer((args.bind, args.port), handler) as httpd: |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
184 print( |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
185 f"Serving HTTP on {args.bind} port {args.port} (http://{args.bind}:{args.port}/)" |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
186 ) |
53c2be00bb6f
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff
changeset
|
187 httpd.serve_forever() |