-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
120 lines (100 loc) · 3.31 KB
/
generate.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import argparse
import pathlib
import constants
from configuration import Configuration
from helper import Helper
from fileProcessor import FileProcessor
from musicGenerator import MusicGenerator
def __buildArgumentParser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description='Generate and process lilypond and musescore files.')
# use an alternative config file
parser.add_argument(
'--config', '-c',
type=open,
default='config.json',
help='The name of the configuration file. [Default = \'json.config\']')
# positional argument: what to generate musescore files
parser.add_argument(
'{0}'.format(constants.argumentTarget),
choices=['all', 'musescore', 'lilypond'],
help='Type of files to generate'
)
# skip converting files
parser.add_argument(
'--{0}'.format(constants.argumentGenerateOnly), '-g',
action='store_true',
help='Do not process generated files'
)
# output directory
parser.add_argument(
'--{0}'.format(constants.argumentOutputDir), '-o',
type=pathlib.Path,
help='The output directory. If not provided reading the value from the configuratiomn file. [Default = \'.\out\']'
)
# skip converting files
parser.add_argument(
'--{0}'.format(constants.argumentForce), '-f',
action='store_true',
help='Force creation of the output directory if it does not exist'
)
# standard picht (Kammerton)
parser.add_argument(
'--{0}'.format(constants.argumentStandardPitch), '-s',
type=int,
help='The standard pitch (a.k.a. Kammerton) when generating mp3-files. [Default = 443]'
)
group = parser.add_mutually_exclusive_group()
# regenerate
group.add_argument(
'--{0}'.format(constants.argumentRegenerate), '-r',
action='store_true',
help='Regenerate existing files'
)
# purge
group.add_argument(
'--{0}'.format(constants.argumentPurge), '-p',
action='store_true',
help='Purge targetted outputdirectories before generation'
)
# TODO add selection noten, tonleiter, intervalle
# verbose
parser.add_argument(
'--{0}'.format(constants.argumentVerbose), '-v',
action='store_true',
help='Verbose'
)
return parser
# end __setupArgParser
def main():
parsed: argparse.Namespace = None
parser = __buildArgumentParser()
configOk = False
try:
parsed = parser.parse_args()
config = Configuration()
configOk = config.initialize(parsed)
if (configOk != True):
parser.print_usage()
# end if
except OSError as err:
parser.print_usage()
print('{0}: error: {1}: {2}'.format(parser.prog, err.strerror, err.filename))
finally:
if (parsed is not None and parsed.config is not None):
parsed.config.close()
#end try-except-finally
if (configOk == True):
try:
helper = Helper()
files = MusicGenerator(config, helper).generate()
if (config.process):
FileProcessor(config).processFiles(files)
except BaseException as err:
print(err)
#end try except
#end if
# end main
if __name__ == '__main__':
main()
exit(0)