1
0
Fork 0
mirror of synced 2024-05-20 04:22:58 +12:00
Rare/rare/__main__.py

68 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/python
2021-04-15 01:14:06 +12:00
import os
from argparse import ArgumentParser
from rare import __version__
from rare.utils import singleton, utils
2021-04-09 22:32:41 +12:00
2021-03-26 10:58:32 +13:00
2021-03-26 10:52:36 +13:00
def main():
parser = ArgumentParser()
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")
parser.add_argument("--offline", action="store_true", help="Launch Rare in offline mode")
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")
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:
utils.create_rare_desktop_link("desktop")
print("Link created")
if args.startmenu_shortcut:
utils.create_rare_desktop_link("start_menu")
print("link created")
if args.version:
2021-03-18 02:16:33 +13:00
print(__version__)
return
2021-04-09 22:32:41 +12:00
try:
# this object only allows one instance pre machine
me = singleton.SingleInstance()
except singleton.SingleInstanceException:
print("Rare is already running")
2021-04-15 01:14:06 +12:00
with open(os.path.expanduser("~/.cache/rare/lockfile"), "w") as file:
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
# fix error in cx_freeze
from rare.app import start
start(args)
2021-03-26 10:58:32 +13:00
2021-03-26 10:52:36 +13:00
if __name__ == '__main__':
import multiprocessing
multiprocessing.freeze_support()
2021-02-10 23:48:25 +13:00
main()