1
0
Fork 0
mirror of synced 2024-06-08 21:54:40 +12:00
Rare/rare/__main__.py

111 lines
3 KiB
Python
Raw Normal View History

#!/usr/bin/python
2021-04-15 01:14:06 +12:00
import os
import pathlib
import sys
from argparse import ArgumentParser
2021-03-26 10:58:32 +13:00
2021-03-26 10:52:36 +13:00
def main():
2021-09-14 08:44:59 +12:00
# fix cx_freeze
import multiprocessing
2021-12-24 22:09:50 +13:00
2021-09-14 08:44:59 +12:00
multiprocessing.freeze_support()
# insert legendary for installed via pip/setup.py submodule to path
if not __name__ == "__main__":
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "legendary"))
2021-09-06 08:00:14 +12:00
2021-09-14 08:44:59 +12:00
# CLI Options
parser = ArgumentParser()
2021-12-24 22:09:50 +13:00
parser.add_argument(
"-V", "--version", action="store_true", help="Shows version and exits"
)
parser.add_argument(
"-S",
"--silent",
action="store_true",
help="Launch Rare in background. Open it from System Tray Icon",
)
2021-06-21 07:07:56 +12:00
parser.add_argument("--debug", action="store_true", help="Launch in debug mode")
2021-12-24 22:09:50 +13:00
parser.add_argument(
"--offline", action="store_true", help="Launch Rare in offline mode"
)
parser.add_argument(
"--test-start", action="store_true", help="Quit immediately after launch"
)
parser.add_argument(
"--desktop-shortcut",
action="store_true",
dest="desktop_shortcut",
help="Use this, if there is no link on desktop to start Rare",
)
parser.add_argument(
"--startmenu-shortcut",
action="store_true",
dest="startmenu_shortcut",
help="Use this, if there is no link in start menu to launch Rare",
)
2021-04-14 02:56:44 +12:00
subparsers = parser.add_subparsers(title="Commands", dest="subparser")
launch_parser = subparsers.add_parser("launch")
2021-12-24 22:09:50 +13:00
launch_parser.add_argument("app_name", help="Name of the app", metavar="<App Name>")
2021-02-20 00:57:55 +13:00
args = parser.parse_args()
2021-04-14 02:56:44 +12:00
if args.desktop_shortcut:
from rare.utils import utils
2021-12-24 22:09:50 +13:00
utils.create_rare_desktop_link("desktop")
print("Link created")
2021-09-19 02:34:43 +12:00
if args.startmenu_shortcut:
from rare.utils import utils
2021-12-24 22:09:50 +13:00
utils.create_rare_desktop_link("start_menu")
print("link created")
if args.version:
from rare import __version__, code_name
2021-12-24 22:09:50 +13:00
print(f"Rare {__version__} Codename: {code_name}")
return
2021-09-19 02:34:43 +12:00
from rare.utils import singleton
2021-12-24 22:09:50 +13:00
2021-04-09 22:32:41 +12:00
try:
2021-08-23 08:22:17 +12:00
# this object only allows one instance per machine
2021-09-19 02:34:43 +12:00
2021-04-09 22:32:41 +12:00
me = singleton.SingleInstance()
except singleton.SingleInstanceException:
print("Rare is already running")
2021-09-19 02:34:43 +12:00
from rare import data_dir
2021-12-24 22:09:50 +13:00
with open(os.path.join(data_dir, "lockfile"), "w") as file:
2021-04-15 01:14:06 +12:00
if args.subparser == "launch":
file.write("launch " + args.app_name)
else:
file.write("start")
file.close()
return
2021-02-10 23:48:25 +13:00
if args.subparser == "launch":
args.silent = True
from rare.app import start
2021-12-24 22:09:50 +13:00
start(args)
2021-03-26 10:58:32 +13:00
2021-12-24 22:09:50 +13:00
if __name__ == "__main__":
# run from source
# insert raw legendary submodule
2021-12-24 22:09:50 +13:00
sys.path.insert(
0, os.path.join(pathlib.Path(__file__).parent.absolute(), "legendary")
)
# insert source directory
2021-12-14 10:05:05 +13:00
sys.path.insert(0, str(pathlib.Path(__file__).parents[1].absolute()))
2021-02-10 23:48:25 +13:00
main()