-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·50 lines (36 loc) · 1.45 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Anki Add-on: Anki Context
Please do not edit this file unless you know what you are doing.
Copyright: (c) 2019 Henrik Giesel <https://github.com/hgiesel>
License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl.html>
"""
import importlib.util
import os
def check_for_ark(addon_path):
home = os.path.expanduser('~')
install_dir = os.path.join(home, '.local/bin')
install_path = os.path.join(install_dir, 'ark')
if os.path.isdir(install_dir) and not os.path.isfile(install_path):
os.symlink('%s/__init__.py' % addon_path, install_path)
os.chmod(install_path, 0o755)
if importlib.util.find_spec('aqt') is not None:
from aqt import mw
from .lib.context import main
CONFIG = mw.addonManager.getConfig(__name__)
ADDON_PATH = os.path.abspath(os.path.dirname(__file__))
ICON_PATH = os.path.join(ADDON_PATH, "icons")
ICONS = [os.path.join(ICON_PATH, "looks_%i.png" % i) for i in range(0, 6)]
check_for_ark(ADDON_PATH)
main(CONFIG, ICONS)
elif __name__ == '__main__':
from lib.parser import setup_parser, setup_config
from lib.main import FUNCTION_DICT
CONFIG = setup_config(os.path.dirname(os.readlink(__file__)))
PARSER, SUBPARSER_DICT = setup_parser(CONFIG)
ARGV = PARSER.parse_args()
if ARGV.cmd is not None:
FUNCTION_DICT[ARGV.cmd](CONFIG,
ARGV,
SUBPARSER_DICT[ARGV.cmd].error) # error printer for parser