diff --git a/.gitignore b/.gitignore index 3d81a46607..8febc4c2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -5,12 +5,20 @@ dist/ output/ screenshots/ +tribler.dist-info +src/tribler/run.py src/ec_multichain.pem src/secondary_key.pem - src/state_directory/ src/venv/ - src/tribler/src/tribler/gui/screenshots/ +build/debian/tribler/debian/.debhelper/ +build/debian/tribler/debian/debhelper-build-stamp +build/debian/tribler/debian/files +build/debian/tribler/debian/*.debhelper +build/debian/tribler/debian/tribler.substvars +build/debian/tribler/debian/tribler/ +build/debian/tribler/usr/share/tribler/ +build/debian/tribler_* diff --git a/src/run_tribler.py b/src/run_tribler.py index e485332108..ce5271d646 100644 --- a/src/run_tribler.py +++ b/src/run_tribler.py @@ -11,7 +11,6 @@ import webbrowser from pathlib import Path -import pystray from aiohttp import ClientSession from PIL import Image @@ -35,10 +34,13 @@ def parse_args() -> Arguments: """ Parse the command-line arguments. """ - parser = argparse.ArgumentParser(prog='Tribler [Experimental]', description='Run Tribler BitTorrent client') - parser.add_argument('torrent', help='torrent file to download', default='', nargs='?') - parser.add_argument('--log-level', default="INFO", action="store_true", help="set the log level", + parser = argparse.ArgumentParser(prog='Tribler', description='Run Tribler BitTorrent client') + parser.add_argument('torrent', help='Torrent file to download', default='', nargs='?') + parser.add_argument('--log-level', default="INFO", action="store", nargs='?', + help="Set the log level. The default is 'INFO'", + choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'], dest="log_level") + parser.add_argument('-s', '--server', action='store_true', help="Run headless as a server without graphical pystray interface") return vars(parser.parse_args()) @@ -102,12 +104,17 @@ async def main() -> None: torrent_uri = Path(torrent_uri).read_text() server_url = await session.find_api_server() + headless = parsed_args.get('server') + if not headless: + import pystray + if server_url: logger.info("Core already running at %s", server_url) if torrent_uri: logger.info("Starting torrent using existing core") await start_download(config, server_url, torrent_uri) - webbrowser.open_new_tab(server_url + f"?key={config.get('api/key')}") + if not headless: + webbrowser.open_new_tab(server_url + f"?key={config.get('api/key')}") logger.info("Shutting down") return @@ -116,20 +123,21 @@ async def main() -> None: server_url = await session.find_api_server() if server_url and torrent_uri: await start_download(config, server_url, torrent_uri) - - image_path = tribler.get_webui_root() / "public" / "tribler.png" - image = Image.open(image_path.resolve()) - api_port = session.rest_manager.get_api_port() - url = f"http://{config.get('api/http_host')}:{api_port}/ui/#/downloads/all?key={config.get('api/key')}" - menu = (pystray.MenuItem('Open', lambda: webbrowser.open_new_tab(url)), - pystray.MenuItem('Quit', lambda: session.shutdown_event.set())) - icon = pystray.Icon("Tribler", icon=image, title="Tribler", menu=menu) - webbrowser.open_new_tab(url) - threading.Thread(target=icon.run).start() + if not headless: + image_path = tribler.get_webui_root() / "public" / "tribler.png" + image = Image.open(image_path.resolve()) + api_port = session.rest_manager.get_api_port() + url = f"http://{config.get('api/http_host')}:{api_port}/ui/#/downloads/all?key={config.get('api/key')}" + menu = (pystray.MenuItem('Open', lambda: webbrowser.open_new_tab(url)), + pystray.MenuItem('Quit', lambda: session.shutdown_event.set())) + icon = pystray.Icon("Tribler", icon=image, title="Tribler", menu=menu) + webbrowser.open_new_tab(url) + threading.Thread(target=icon.run).start() await session.shutdown_event.wait() await session.shutdown() - icon.stop() + if not headless: + icon.stop() logger.info("Tribler shutdown completed")