]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - helpers/__init__.py
Make 'wait' action interruptible
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / __init__.py
CommitLineData
1df30f07 1# -*- coding: utf-8 -*-
bb69f62e
IB
2import sys
3import os
4
9b9dd12a
IB
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
bb69f62e
IB
12def path():
13 if getattr(sys, 'frozen', False):
14 return sys._MEIPASS + "/"
15 else:
16 path = os.path.dirname(os.path.realpath(__file__))
17 return path + "/../"
18
cc008de4
IB
19def parse_args():
20 for arg in sys.argv:
9b9dd12a
IB
21 if arg[0:2] == "-c":
22 sys.argv.remove(arg)
23 config.yml_file = arg[2:]
24
cc008de4
IB
25 if arg == "-v":
26 sys.argv.remove(arg)
27
28 if getattr(sys, 'frozen', False):
29 f = open(path() + ".pyinstaller_commit", "r")
30 print(f.read(), end="")
31 f.close()
32 else:
33 print("option '-v' can only be used in bundled package")
34 sys.exit()
35
9b9dd12a
IB
36def yml_file():
37 return config.yml_file
38
98ff4305
IB
39def duration_to_min_sec(duration):
40 minutes = int(duration / 60)
41 seconds = int(duration) % 60
42 if minutes < 100:
43 return "{:2}:{:0>2}".format(minutes, seconds)
44 else:
45 return "{}:{:0>2}".format(minutes, seconds)