Ejemplo n.º 1
0
def main():
    arg_parser = get_args()
    args = arg_parser.parse_args()

    dir_path = create_dir(os.path.abspath(args.dir))

    if len(list(os.walk(dir_path))) > 0:
        copy_files(get_file(Constants.COALA_HTML_BASE), dir_path)

    if not args.noupdate:
        log_printer = ListLogPrinter()
        results, exitcode, file_dict = run_coala(
            log_printer=log_printer, autoapply=False, arg_parser=arg_parser)

        result_data = {"results": results}
        result_data["logs"] = log_printer.logs
        JSONEncoder = create_json_encoder(use_relpath=False)

        result_file = get_file(Constants.CONFIGS['results_file'], dir_path)
        file_data = get_file(Constants.CONFIGS['file_data'], dir_path)
        file_tree_data = get_file(Constants.CONFIGS['files'], dir_path)

        with open(file_tree_data, 'w') as fp:
            file_graph = build_file_graph(file_dict, dir_path)
            json.dump(file_graph, fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))

        with open(result_file, 'w') as fp:
            json.dump(result_data, fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))
        with open(file_data, 'w') as fp:
            json.dump(parse_file_dict(file_dict), fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))
    if not args.nolaunch:
        # Launch server with reference point dir_path
        os.chdir(dir_path)
        if not os.path.exists('bower_components'):
            res = call(['bower', 'install'])
            if res != 0:
                print("Bower is required. Install from `http://bower.io/`")
                sys.exit(1)

        Handler = http.server.SimpleHTTPRequestHandler
        httpd = socketserver.TCPServer(("", Constants.PORT), Handler)
        print("serving at ", Constants.URL)
        print("Press Ctrl+C to end the coala-html session")
        httpd.serve_forever()
        webbrowser.open(Constants.URL, new=2)
Ejemplo n.º 2
0
    def test_copy_files(self):
        s_dir = create_dir(os.path.abspath('S99'))
        d_dir = create_dir(os.path.abspath('D99'))
        s_test_file = os.path.join(s_dir, 'test.json')
        d_test_file = os.path.join(d_dir, 'test.json')

        with open(s_test_file, 'w') as sfp:
            json.dump({'key': 'value'}, sfp, separators=(',', ': '))

        copy_files(s_dir, d_dir)
        self.assertTrue(os.path.exists(d_test_file))
        shutil.rmtree(s_dir)
        shutil.rmtree(d_dir)
Ejemplo n.º 3
0
    def test_copy_files(self):
        s_dir = create_dir(os.path.abspath('S99'))
        d_dir = create_dir(os.path.abspath('D99'))
        s_test_file = os.path.join(s_dir, 'test.json')
        d_test_file = os.path.join(d_dir, 'test.json')

        with open(s_test_file, 'w') as sfp:
            json.dump({'key': 'value'}, sfp, separators=(',', ': '))

        copy_files(s_dir, d_dir)
        self.assertTrue(os.path.exists(d_test_file))
        shutil.rmtree(s_dir)
        shutil.rmtree(d_dir)
Ejemplo n.º 4
0
def main():
    arg_parser = get_args()
    args = arg_parser.parse_args()

    dir_path = create_dir(os.path.abspath(args.dir))

    main_package = gen_file_set(get_file(Constants.COALA_HTML_BASE))
    local_package = gen_file_set(dir_path)

    if not main_package.issubset(local_package):  # pragma: no cover
        copy_files(get_file(Constants.COALA_HTML_BASE), dir_path)

    if not args.noupdate:
        log_printer = ListLogPrinter()
        results, exitcode, file_dict = run_coala(log_printer=log_printer,
                                                 arg_parser=arg_parser)

        result_data = {"results": results}
        result_data["logs"] = log_printer.logs
        JSONEncoder = create_json_encoder(use_relpath=False)

        result_file = get_file(Constants.CONFIGS['results_file'], dir_path)
        file_data = get_file(Constants.CONFIGS['file_data'], dir_path)
        file_tree_data = get_file(Constants.CONFIGS['files'], dir_path)

        with open(file_tree_data, 'w') as fp:
            file_graph = build_file_graph(file_dict, dir_path)
            json.dump(file_graph,
                      fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))

        with open(result_file, 'w') as fp:
            json.dump(result_data,
                      fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))
        with open(file_data, 'w') as fp:
            json.dump(parse_file_dict(file_dict),
                      fp,
                      cls=JSONEncoder,
                      sort_keys=True,
                      indent=2,
                      separators=(',', ': '))
    if not args.nolaunch:
        # Launch server with reference point dir_path
        os.chdir(dir_path)
        if not os.path.exists('bower_components'):
            res = call(['bower', 'install'])
            if res != 0:  # pragma: no cover
                print("Bower is required. Install from `http://bower.io/`")
                sys.exit(1)

        Handler = http.server.SimpleHTTPRequestHandler
        socketserver.TCPServer.allow_reuse_address = True
        httpd = socketserver.TCPServer(("", Constants.PORT), Handler)
        print("serving at ", Constants.URL)
        print("Press Ctrl+C to end the coala-html session")
        webbrowser.open(Constants.URL, new=2)
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            httpd.server_close()