2021-02-12 19:01:42 +01:00
|
|
|
import argparse
|
2021-05-13 01:25:50 +02:00
|
|
|
import logging
|
2021-02-12 19:01:42 +01:00
|
|
|
|
2021-03-28 18:28:35 +02:00
|
|
|
from bebop.browser.browser import Browser
|
2021-04-18 02:27:05 +02:00
|
|
|
from bebop.config import load_config
|
2021-04-19 02:04:18 +02:00
|
|
|
from bebop.fs import ensure_bebop_files_exist, get_config_path
|
|
|
|
from bebop.tofu import get_cert_stash_path, load_cert_stash, save_cert_stash
|
2021-02-12 19:01:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-06-02 00:33:19 +02:00
|
|
|
argparser = argparse.ArgumentParser(description="Gemini browser")
|
2021-04-16 19:30:14 +02:00
|
|
|
argparser.add_argument("url", nargs="?", default=None)
|
2021-05-13 01:25:50 +02:00
|
|
|
argparser.add_argument("-d", "--debug", action="store_true")
|
2021-02-12 19:01:42 +01:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2021-05-13 01:25:50 +02:00
|
|
|
if args.debug:
|
|
|
|
logging.basicConfig(
|
|
|
|
filename="bebop.log",
|
|
|
|
level=logging.DEBUG,
|
|
|
|
format="%(asctime)s %(levelname)-8s %(message)s"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
logging.disable()
|
|
|
|
|
2021-02-12 19:01:42 +01:00
|
|
|
if args.url:
|
|
|
|
start_url = args.url
|
|
|
|
else:
|
|
|
|
start_url = None
|
|
|
|
|
2021-04-18 02:27:05 +02:00
|
|
|
config_path = get_config_path()
|
|
|
|
config = load_config(config_path)
|
|
|
|
|
2021-05-12 22:29:03 +02:00
|
|
|
bebop_files_error = ensure_bebop_files_exist()
|
|
|
|
if bebop_files_error:
|
2021-05-13 01:25:50 +02:00
|
|
|
logging.critical(f"Failed to create files: {bebop_files_error}")
|
2021-05-12 22:29:03 +02:00
|
|
|
return
|
2021-03-13 16:33:04 +01:00
|
|
|
|
2021-04-19 02:04:18 +02:00
|
|
|
cert_stash_path = get_cert_stash_path()
|
2021-03-28 18:28:54 +02:00
|
|
|
cert_stash = load_cert_stash(cert_stash_path) or {}
|
2021-03-13 16:33:04 +01:00
|
|
|
try:
|
2021-04-18 02:27:05 +02:00
|
|
|
Browser(config, cert_stash).run(start_url=start_url)
|
2021-03-13 16:33:04 +01:00
|
|
|
finally:
|
|
|
|
save_cert_stash(cert_stash, cert_stash_path)
|
2021-02-12 19:01:42 +01:00
|
|
|
|
|
|
|
|
2021-05-29 17:17:04 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|