-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
troi.py
executable file
·100 lines (74 loc) · 2.46 KB
/
troi.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
#!/usr/bin/env python3
import os
import sys
import click
import troi
import troi.playlist
import troi.utils
@click.group()
def cli():
pass
@cli.command()
@click.argument("patch", nargs=1)
@click.argument('args', nargs=-1)
@click.option('--debug', '-d', is_flag=True, default=False)
def playlist(patch, args, debug):
if debug:
print("- debug mode on")
patches = troi.utils.discover_patches("patches")
if not patch in patches:
print("Cannot load patch '%s'. Use the list command to get a list of available patches." % patch)
quit()
patch = patches[patch]()
inputs = patch.inputs()
checked_args = []
for i, input in enumerate(inputs):
if not input['optional'] and args[i] == None:
print("%s: argument '%s' is required." % (patch.slug(), inputs['name']))
quit()
try:
value = input['type'](args[i])
except IndexError:
continue
except ValueError as err:
print("%s: Argument '%s' with type %s is invalid: %s" % (patch.slug(), input['name'], input['type'], err))
quit()
checked_args.append(value)
pipeline = patch.create(checked_args)
try:
playlist = troi.playlist.PlaylistElement()
playlist.set_sources(pipeline)
playlist.generate(debug)
except RuntimeError as err:
print("Failed to generate playlist: %s" % err)
return
playlist.print()
print("-- generated playlist with %d recordings. Open playlist by opening playlist.html in your browser." % len(playlist.entities))
playlist.launch()
@cli.command()
def list():
patches = troi.utils.discover_patches("patches")
print("Available patches:")
for slug in patches:
print(" %s: %s" % (slug, patches[slug]().description()))
@cli.command()
@click.argument("patch", nargs=1)
def info(patch):
patches = troi.util.discover_patches("patches")
if not patch in patches:
print("Cannot load patch '%s'. Use the list command to get a list of available patches." % patch)
quit()
patch = patches[patch]()
inputs = patch.inputs()
print("patch %s" % patch.slug())
print(" %s" % patch.description())
print()
print(" expected inputs:")
for input in inputs:
print(" %s, type %s" % (input[1], input[0]))
def usage(command):
with click.Context(command) as ctx:
click.echo(command.get_help(ctx))
if __name__ == "__main__":
cli()
sys.exit(0)