-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·206 lines (193 loc) · 5.92 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import os
import click
from cyberpunk import __version__
from cyberpunk.config import CyberpunkConfig
from cyberpunk.server import create_app
app = create_app()
@click.group()
@click.version_option(__version__)
def cli():
return
@cli.command()
@click.option(
"-D",
"--debug",
is_flag=True,
help="enables debug mode",
)
@click.option(
"--port",
type=click.INT,
default=lambda: os.environ.get("PORT", 8080),
help="Server port number",
)
@click.option(
"--cyberpunk-secret",
default=lambda: os.environ.get("CYBERPUNK_SECRET", "mysecret"),
help="Secret used for the URL signature",
)
@click.option(
"--audio-path",
default=lambda: os.environ.get("AUDIO_PATH", "local"),
help="Sources for audio files and in which order to search for them",
)
@click.option(
"--local-storage-base-dir",
default=lambda: os.environ.get("LOCAL_STORAGE_BASE_DIR", "testdata/"),
help="Local directory contains the audio library",
)
@click.option(
"--local-results-base-dir",
default=lambda: os.environ.get("LOCAL_RESULTS_BASE_DIR", "testdata/"),
help="Local directory where processed audio files will be stored",
)
@click.option(
"--s3-loader-bucket",
default=lambda: os.environ.get("S3_LOADER_BUCKET", None),
help="S3 bucket containing audio needing to be pre-loaded",
)
@click.option(
"--s3-loader-base-dir",
default=lambda: os.environ.get("S3_LOADER_BASE_DIR", ""),
help="Prefix in loader s3 bucket where the audio files are located",
)
@click.option(
"--s3-storage-bucket",
default=lambda: os.environ.get("S3_STORAGE_BUCKET", None),
help="S3 bucket containing the audio files to be processed",
)
@click.option(
"--s3-storage-base-dir",
default=lambda: os.environ.get("S3_STORAGE_BASE_DIR", ""),
help="Prefix in storage s3 bucket where the audio files are located",
)
@click.option(
"--s3-results-bucket",
default=lambda: os.environ.get("S3_RESULTS_BUCKET", None),
help="S3 bucket where the processed audio is stored",
)
@click.option(
"--s3-results-base-dir",
default=lambda: os.environ.get("S3_RESULTS_BASE_DIR", ""),
help="Prefix in results s3 bucket where the audio files should be stored",
)
@click.option(
"--google_application_credentials",
default=lambda: os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", None),
help="Google Cloud service account credentials path",
)
@click.option(
"--gcs-loader-bucket",
default=lambda: os.environ.get("GCS_LOADER_BUCKET", None),
help="GCS bucket containing audio needing to be pre-loaded",
)
@click.option(
"--gcs-loader-base-dir",
default=lambda: os.environ.get("GCS_LOADER_BASE_DIR", ""),
help="Prefix in loader gcs bucket where the audio files are located",
)
@click.option(
"--gcs-storage-bucket",
default=lambda: os.environ.get("GCS_STORAGE_BUCKET", None),
help="GCS bucket containing the audio files to be processed",
)
@click.option(
"--gcs-storage-base-dir",
default=lambda: os.environ.get("GCS_STORAGE_BASE_DIR", ""),
help="Prefix in storage gcs bucket where the audio files are located",
)
@click.option(
"--gcs-results-bucket",
default=lambda: os.environ.get("GCS_RESULTS_BUCKET", None),
help="GCS bucket where the processed audio is stored",
)
@click.option(
"--gcs-results-base-dir",
default=lambda: os.environ.get("GCS_RESULTS_BASE_DIR", ""),
help="Prefix in results GCS bucket where the audio files should be stored",
)
@click.option(
"--jaeger-tracing",
is_flag=True,
default=lambda: os.environ.get("JAEGER_TRACING_ENABLED", "0").lower()
in ("true", "t", "1"),
help="Export traces to Jaeger",
)
@click.option(
"--jaeger-agent-hostname",
default=lambda: os.environ.get("JAEGER_AGENT_HOSTNAME", "jaeger"),
help="Hostname for Jaeger service",
)
@click.option(
"--jaeger-agent-port",
type=click.INT,
default=lambda: os.environ.get("JAEGER_AGENT_PORT", 6831),
help="Port for Jaeger service",
)
@click.option(
"--gcp-tracing",
is_flag=True,
default=lambda: os.environ.get("GCP_TRACING_ENABLED", "0").lower()
in ("true", "t", "0"),
help="Export traces to Google Cloud Platform",
)
def serve(
debug,
port,
cyberpunk_secret,
audio_path,
local_storage_base_dir,
local_results_base_dir,
s3_loader_bucket,
s3_loader_base_dir,
s3_storage_bucket,
s3_storage_base_dir,
s3_results_bucket,
s3_results_base_dir,
google_application_credentials,
gcs_loader_bucket,
gcs_loader_base_dir,
gcs_storage_bucket,
gcs_storage_base_dir,
gcs_results_bucket,
gcs_results_base_dir,
jaeger_tracing,
jaeger_agent_hostname,
jaeger_agent_port,
gcp_tracing,
):
print(cyberpunk_secret)
config = CyberpunkConfig(
audio_path=audio_path,
local_storage_base_dir=local_storage_base_dir,
local_results_base_dir=local_results_base_dir,
s3_loader_bucket=s3_loader_bucket,
s3_loader_base_dir=s3_loader_base_dir,
s3_storage_bucket=s3_storage_bucket,
s3_storage_base_dir=s3_storage_base_dir,
s3_results_bucket=s3_results_bucket,
s3_results_base_dir=s3_results_base_dir,
google_application_credentials=google_application_credentials,
gcs_loader_bucket=gcs_loader_bucket,
gcs_loader_base_dir=gcs_loader_base_dir,
gcs_storage_bucket=gcs_storage_bucket,
gcs_storage_base_dir=gcs_storage_base_dir,
gcs_results_bucket=gcs_results_bucket,
gcs_results_base_dir=gcs_results_base_dir,
jaeger_tracing=jaeger_tracing,
jaeger_agent_hostname=jaeger_agent_hostname,
jaeger_agent_port=jaeger_agent_port,
gcp_tracing=gcp_tracing,
)
logging.debug(f"running server with config: {config}")
server = create_app(config)
server.run(
debug=debug,
load_dotenv=True,
port=port,
)
if __name__ == "__main__":
cli()