aboutsummaryrefslogtreecommitdiff
path: root/helpers/__init__.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 16:04:32 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 16:04:32 +0200
commit71715c049145a074b0f2b8d90c8c8c47830323c3 (patch)
tree63fee2b79b8e5b532fa57366590853dda18bb006 /helpers/__init__.py
parent0deb82a57ae3abefd44509dc88c546f6e5a94d1b (diff)
downloadMusicSampler-71715c049145a074b0f2b8d90c8c8c47830323c3.tar.gz
MusicSampler-71715c049145a074b0f2b8d90c8c8c47830323c3.tar.zst
MusicSampler-71715c049145a074b0f2b8d90c8c8c47830323c3.zip
Use argparse for parser
Diffstat (limited to 'helpers/__init__.py')
-rw-r--r--helpers/__init__.py47
1 files changed, 32 insertions, 15 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index 2131c2a..3b97f2f 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -1,4 +1,5 @@
1# -*- coding: utf-8 -*- 1# -*- coding: utf-8 -*-
2import argparse
2import sys 3import sys
3import os 4import os
4 5
@@ -17,21 +18,37 @@ def path():
17 return path + "/../" 18 return path + "/../"
18 19
19def parse_args(): 20def parse_args():
20 for arg in sys.argv: 21 argv = sys.argv[1:]
21 if arg[0:2] == "-c": 22 sys.argv = sys.argv[:1]
22 sys.argv.remove(arg) 23 if "--" in argv:
23 config.yml_file = arg[2:] 24 index = argv.index("--")
24 25 kivy_args = argv[index+1:]
25 if arg == "-v": 26 argv = argv[:index]
26 sys.argv.remove(arg) 27
27 28 sys.argv.extend(kivy_args)
28 if getattr(sys, 'frozen', False): 29
29 f = open(path() + ".pyinstaller_commit", "r") 30 parser = argparse.ArgumentParser(description="A Music Sampler application.")
30 print(f.read(), end="") 31 parser.add_argument("-c", "--config",
31 f.close() 32 default="config.yml",
32 else: 33 required=False,
33 print("option '-v' can only be used in bundled package") 34 help="Config file to load")
34 sys.exit() 35 parser.add_argument("-V", "--version",
36 action="version",
37 help="Displays the current version and exits. Only use in bundled package",
38 version=show_version())
39 parser.add_argument('--',
40 dest="args",
41 help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
42 args = parser.parse_args(argv)
43
44 config.yml_file = args.config
45
46def show_version():
47 if getattr(sys, 'frozen', False):
48 with open(path() + ".pyinstaller_commit", "r") as f:
49 return f.read()
50 else:
51 return "option '-v' can only be used in bundled package"
35 52
36def yml_file(): 53def yml_file():
37 return config.yml_file 54 return config.yml_file