]> git.donarmstrong.com Git - qmk_firmware.git/blob - bin/qmk
Expose zh-cn docs, delete bad zh docs, add docs for adding translations (#6855)
[qmk_firmware.git] / bin / qmk
1 #!/usr/bin/env python3
2 """CLI wrapper for running QMK commands.
3 """
4 import os
5 import subprocess
6 import sys
7 from importlib.util import find_spec
8 from time import strftime
9
10 # Add the QMK python libs to our path
11 script_dir = os.path.dirname(os.path.realpath(__file__))
12 qmk_dir = os.path.abspath(os.path.join(script_dir, '..'))
13 python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python'))
14 sys.path.append(python_lib_dir)
15
16 # Make sure our modules have been setup
17 with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
18     for line in fd.readlines():
19         line = line.strip().replace('<', '=').replace('>', '=')
20
21         if line[0] == '#':
22             continue
23
24         if '#' in line:
25             line = line.split('#')[0]
26
27         module = line.split('=')[0] if '=' in line else line
28         if not find_spec(module):
29             print('Could not find module %s!', module)
30             print('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
31             exit(255)
32
33 # Figure out our version
34 # TODO(skullydazed/anyone): Find a method that doesn't involve git. This is slow in docker and on windows.
35 command = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags']
36 result = subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
37
38 if result.returncode == 0:
39     os.environ['QMK_VERSION'] = result.stdout.strip()
40 else:
41     os.environ['QMK_VERSION'] = 'nogit-' + strftime('%Y-%m-%d-%H:%M:%S') + '-dirty'
42
43 # Setup the CLI
44 import milc
45
46 milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
47
48
49 @milc.cli.entrypoint('QMK Helper Script')
50 def qmk_main(cli):
51     """The function that gets run when no subcommand is provided.
52     """
53     cli.print_help()
54
55
56 def main():
57     """Setup our environment and then call the CLI entrypoint.
58     """
59     # Change to the root of our checkout
60     os.environ['ORIG_CWD'] = os.getcwd()
61     os.chdir(qmk_dir)
62
63     # Import the subcommands
64     import qmk.cli
65
66     # Execute
67     return_code = milc.cli()
68
69     if return_code is False:
70         exit(1)
71
72     elif return_code is not True and isinstance(return_code, int):
73         if return_code < 0 or return_code > 255:
74             milc.cli.log.error('Invalid return_code: %d', return_code)
75             exit(255)
76
77         exit(return_code)
78
79     exit(0)
80
81
82 if __name__ == '__main__':
83     main()