1
|
|
|
# This program is free software: you can redistribute it and/or modify it |
2
|
|
|
# under the terms of the GNU Affero General Public License as published by the |
3
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your |
4
|
|
|
# option) any later version. |
5
|
|
|
# |
6
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
7
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
9
|
|
|
# for more details. |
10
|
|
|
# |
11
|
|
|
# You should have received a copy of the GNU Affero General Public License |
12
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
13
|
|
|
|
14
|
|
|
import http.server |
15
|
|
|
import json |
16
|
|
|
import os |
17
|
|
|
import socketserver |
18
|
|
|
import webbrowser |
19
|
|
|
|
20
|
|
|
from coalib.coala_main import run_coala |
21
|
|
|
from coalib.output.JSONEncoder import create_json_encoder |
22
|
|
|
from coalib.output.printers.ListLogPrinter import ListLogPrinter |
23
|
|
|
from coalib.parsing.DefaultArgParser import default_arg_parser |
24
|
|
|
from coalib.misc import Constants |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
def get_file(file_name): |
28
|
|
|
return os.path.join(os.path.dirname(__file__), file_name) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def main(): |
32
|
|
|
arg_parser = default_arg_parser() |
33
|
|
|
args = arg_parser.parse_args() |
34
|
|
|
if args.noupdate is False: |
35
|
|
|
log_printer = ListLogPrinter() |
36
|
|
|
results, exitcode, file_dict = run_coala( |
37
|
|
|
log_printer=log_printer, autoapply=False) |
38
|
|
|
retval = {"results": results} |
39
|
|
|
retval["logs"] = log_printer.logs |
40
|
|
|
JSONEncoder = create_json_encoder(use_relpath=False) |
41
|
|
|
result_file = get_file(Constants.CONFIGS['results_file']) |
42
|
|
|
file_data = get_file(Constants.CONFIGS['file_data']) |
43
|
|
|
with open(result_file, 'w+') as fp: |
44
|
|
|
json.dump(retval, fp, |
45
|
|
|
cls=JSONEncoder, |
46
|
|
|
sort_keys=True, |
47
|
|
|
indent=2, |
48
|
|
|
separators=(',', ': ')) |
49
|
|
|
with open(file_data, 'w+') as fp: |
50
|
|
|
json.dump(file_dict, fp, |
51
|
|
|
cls=JSONEncoder, |
52
|
|
|
sort_keys=True, |
53
|
|
|
indent=2, |
54
|
|
|
separators=(',', ': ')) |
55
|
|
|
if args.nolaunch is False: |
56
|
|
|
Handler = http.server.SimpleHTTPRequestHandler |
57
|
|
|
httpd = socketserver.TCPServer(("", Constants.PORT), Handler) |
58
|
|
|
print("serving at ", Constants.URL) |
59
|
|
|
print("Press Ctrl+C to end the coala-html session") |
60
|
|
|
try: |
61
|
|
|
httpd.serve_forever() |
62
|
|
|
except Exception as e: |
63
|
|
|
print(e) |
64
|
|
|
webbrowser.open(Constants.URL, new=2) |
65
|
|
|
|