aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 13:25:41 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 13:25:41 +0200
commit9b9dd12a0253f2e65c5934068d91b544f7679f12 (patch)
treeccc7c762c877a6b6447936317ed20510ac69ed92 /helpers
parent60979de4e9f5f3f249f4887b8fecfe94f233b3d4 (diff)
downloadMusicSampler-9b9dd12a0253f2e65c5934068d91b544f7679f12.tar.gz
MusicSampler-9b9dd12a0253f2e65c5934068d91b544f7679f12.tar.zst
MusicSampler-9b9dd12a0253f2e65c5934068d91b544f7679f12.zip
Add config file option to the command line
Diffstat (limited to 'helpers')
-rw-r--r--helpers/__init__.py14
-rw-r--r--helpers/mapping.py3
2 files changed, 16 insertions, 1 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index f3e5967..2131c2a 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -2,6 +2,13 @@
2import sys 2import sys
3import os 3import os
4 4
5class Config:
6 def __init__(self, **kwargs):
7 for arg in kwargs:
8 setattr(self, arg, kwargs[arg])
9
10config = Config(yml_file="config.yml")
11
5def path(): 12def path():
6 if getattr(sys, 'frozen', False): 13 if getattr(sys, 'frozen', False):
7 return sys._MEIPASS + "/" 14 return sys._MEIPASS + "/"
@@ -11,6 +18,10 @@ def path():
11 18
12def parse_args(): 19def parse_args():
13 for arg in sys.argv: 20 for arg in sys.argv:
21 if arg[0:2] == "-c":
22 sys.argv.remove(arg)
23 config.yml_file = arg[2:]
24
14 if arg == "-v": 25 if arg == "-v":
15 sys.argv.remove(arg) 26 sys.argv.remove(arg)
16 27
@@ -22,6 +33,9 @@ def parse_args():
22 print("option '-v' can only be used in bundled package") 33 print("option '-v' can only be used in bundled package")
23 sys.exit() 34 sys.exit()
24 35
36def yml_file():
37 return config.yml_file
38
25def duration_to_min_sec(duration): 39def duration_to_min_sec(duration):
26 minutes = int(duration / 60) 40 minutes = int(duration / 60)
27 seconds = int(duration) % 60 41 seconds = int(duration) % 60
diff --git a/helpers/mapping.py b/helpers/mapping.py
index e800778..dd51246 100644
--- a/helpers/mapping.py
+++ b/helpers/mapping.py
@@ -10,6 +10,7 @@ import sys
10 10
11from .lock import * 11from .lock import *
12from .music_file import * 12from .music_file import *
13from . import yml_file
13 14
14class Mapping(RelativeLayout): 15class Mapping(RelativeLayout):
15 expected_keys = NumericProperty(0) 16 expected_keys = NumericProperty(0)
@@ -83,7 +84,7 @@ class Mapping(RelativeLayout):
83 self.running.remove((key, start_time)) 84 self.running.remove((key, start_time))
84 85
85 def parse_config(self): 86 def parse_config(self):
86 stream = open("config.yml", "r") 87 stream = open(yml_file(), "r")
87 config = yaml.load(stream) 88 config = yaml.load(stream)
88 stream.close() 89 stream.close()
89 90