forked from NationalGenomicsInfrastructure/genomics-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_app.py
626 lines (577 loc) · 26.2 KB
/
status_app.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
""" Main genomics-status web application.
"""
import base64
import subprocess
import uuid
import yaml
import json
import requests
from collections import OrderedDict
from couchdb import Server
import tornado.autoreload
import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornado import template
from tornado.options import define, options
from status.applications import (
ApplicationDataHandler,
ApplicationHandler,
ApplicationsDataHandler,
ApplicationsHandler,
)
from status.barcode import BarcodeHandler
from status.user_management import UserManagementHandler, UserManagementDataHandler
from status.authorization import LoginHandler, LogoutHandler, UnAuthorizedHandler
from status.bioinfo_analysis import BioinfoAnalysisHandler
from status.data_deliveries_plot import DataDeliveryHandler, DeliveryPlotHandler
from status.deliveries import DeliveriesPageHandler
from status.flowcell import FlowcellHandler, ONTFlowcellHandler, ONTReportHandler
from status.flowcells import (
FlowcellDemultiplexHandler,
FlowcellLinksDataHandler,
FlowcellNotesDataHandler,
FlowcellQ30Handler,
FlowcellQCHandler,
FlowcellsDataHandler,
FlowcellSearchHandler,
FlowcellsHandler,
FlowcellsInfoDataHandler,
OldFlowcellsInfoDataHandler,
ReadsTotalHandler,
)
from status.instruments import (
InstrumentLogsHandler,
DataInstrumentLogsHandler,
InstrumentNamesHandler,
)
from status.invoicing import (
InvoicingPageHandler,
InvoiceSpecDateHandler,
InvoicingPageDataHandler,
GenerateInvoiceHandler,
DeleteInvoiceHandler,
SentInvoiceHandler,
InvoicingOrderDetailsHandler,
)
from status.multiqc_report import MultiQCReportHandler
from status.pricing import (
PricingDateToVersionDataHandler,
PricingExchangeRatesDataHandler,
PricingQuoteHandler,
PricingValidateDraftDataHandler,
PricingPublishDataHandler,
PricingReassignLockDataHandler,
PricingUpdateHandler,
PricingPreviewHandler,
PricingDataHandler,
PricingDraftDataHandler,
GenerateQuoteHandler,
AgreementTemplateTextHandler,
AgreementDataHandler,
AgreementMarkSignHandler,
SaveQuoteHandler,
)
from status.production import (
DeliveredMonthlyDataHandler,
DeliveredMonthlyPlotHandler,
DeliveredQuarterlyDataHandler,
DeliveredQuarterlyPlotHandler,
ProductionCronjobsHandler,
)
from status.projects import (
CaliperImageHandler,
CharonProjectHandler,
LinksDataHandler,
PresetsHandler,
ProjectDataHandler,
ProjectSamplesDataHandler,
ProjectSamplesHandler,
ProjectsDataHandler,
ProjectsFieldsDataHandler,
ProjectsHandler,
ProjectsSearchHandler,
ProjectTicketsDataHandler,
RecCtrlDataHandler,
RunningNotesDataHandler,
ProjMetaCompareHandler,
ProjectRNAMetaDataHandler,
FragAnImageHandler,
PresetsOnLoadHandler,
ImagesDownloadHandler,
PrioProjectsTableHandler,
)
# Not used, delete?
from status.project_qc import ProjectQCDataHandler
from status.queues import (
qPCRPoolsDataHandler,
qPCRPoolsHandler,
SequencingQueuesDataHandler,
SequencingQueuesHandler,
WorksetQueuesHandler,
WorksetQueuesDataHandler,
LibraryPoolingQueuesHandler,
LibraryPoolingQueuesDataHandler,
)
from status.reads_plot import DataFlowcellYieldHandler, FlowcellPlotHandler
from status.running_notes import NEWRunningNotesDataHandler, LatestStickyNoteHandler #temp name
from status.sample_requirements import (
SampleRequirementsViewHandler,
SampleRequirementsDataHandler,
SampleRequirementsUpdateHandler,
SampleRequirementsDraftDataHandler,
SampleRequirementsValidateDraftDataHandler,
SampleRequirementsPreviewHandler,
SampleRequirementsReassignLockDataHandler,
SampleRequirementsPublishDataHandler,
)
from status.sensorpush import (
SensorpushDataHandler,
SensorpushHandler,
SensorpushWarningsDataHandler,
)
from status.sequencing import (
InstrumentClusterDensityPlotHandler,
InstrumentErrorratePlotHandler,
InstrumentUnmatchedPlotHandler,
InstrumentYieldPlotHandler,
InstrumentClusterDensityDataHandler,
InstrumentErrorrateDataHandler,
InstrumentUnmatchedDataHandler,
InstrumentYieldDataHandler,
)
from status.statistics import (
YearApplicationsProjectHandler,
YearApplicationsSamplesHandler,
YearAffiliationProjectsHandler,
YearDeliverytimeProjectsHandler,
ApplicationOpenProjectsHandler,
ApplicationOpenSamplesHandler,
WeekInstrumentTypeYieldHandler,
StatsAggregationHandler,
YearDeliverytimeApplicationHandler,
)
from status.suggestion_box import SuggestionBoxDataHandler, SuggestionBoxHandler
from status.testing import TestDataHandler
from status.util import (
BaseHandler,
DataHandler,
LastPSULRunHandler,
MainHandler,
UpdatedDocumentsDatahandler,
)
from status.user_preferences import UserPrefPageHandler, UserPrefPageHandler_b5
from status.worksets import (
WorksetHandler,
WorksetsHandler,
WorksetDataHandler,
WorksetLinksHandler,
WorksetNotesDataHandler,
WorksetsDataHandler,
WorksetSearchHandler,
ClosedWorksetsHandler,
)
from zenpy import Zenpy
from urllib.parse import urlsplit
from pathlib import Path
class Application(tornado.web.Application):
def __init__(self, settings):
# Set up a set of globals to pass to every template
self.gs_globals = {}
# GENOMICS STATUS MAJOR VERSION NUMBER
# Bump this with any change that requires an update to documentation
self.gs_globals["gs_version"] = "1.0"
# Get the latest git commit hash
# This acts as a minor version number for small updates
# It also forces javascript / CSS updates and solves caching problems
try:
self.gs_globals["git_commit"] = subprocess.check_output(
["git", "rev-parse", "--short=7", "HEAD"]
).strip()
self.gs_globals["git_commit_full"] = subprocess.check_output(
["git", "rev-parse", "HEAD"]
).strip()
except:
self.gs_globals["git_commit"] = "unknown"
self.gs_globals["git_commit_full"] = "unknown"
self.gs_globals["font_awesome_url"] = settings.get("font_awesome_url", None)
self.gs_globals["prod"] = True
if "dev" in settings.get("couch_server"):
self.gs_globals["prod"] = False
handlers = [
# The tuples are on the form ("URI regex", "Backend request handler")
# The groups of the regex are the arguments of the handlers get() method
("/", MainHandler),
("/login", LoginHandler),
("/logout", LogoutHandler),
("/unauthorized", UnAuthorizedHandler),
("/api/v1", DataHandler),
("/api/v1/applications", ApplicationsDataHandler),
("/api/v1/application/([^/]*)$", ApplicationDataHandler),
("/api/v1/bioinfo_analysis", BioinfoAnalysisHandler),
("/api/v1/bioinfo_analysis/([^/]*)$", BioinfoAnalysisHandler),
tornado.web.URLSpec(
"/api/v1/caliper_image/(?P<project>[^/]+)/(?P<sample>[^/]+)/(?P<step>[^/]+)",
CaliperImageHandler,
name="CaliperImageHandler",
),
("/api/v1/charon_summary/([^/]*)$", CharonProjectHandler),
("/api/v1/cost_calculator", PricingDataHandler),
("/api/v1/delete_invoice", DeleteInvoiceHandler),
("/api/v1/delivered_monthly", DeliveredMonthlyDataHandler),
("/api/v1/delivered_monthly.png", DeliveredMonthlyPlotHandler),
("/api/v1/delivered_quarterly", DeliveredQuarterlyDataHandler),
("/api/v1/delivered_quarterly.png", DeliveredQuarterlyPlotHandler),
tornado.web.URLSpec(
"/api/v1/download_images/(?P<project>[^/]+)/(?P<type>[^/]+)",
ImagesDownloadHandler,
name="ImagesDownloadHandler",
),
("/api/v1/draft_cost_calculator", PricingDraftDataHandler),
("/api/v1/draft_sample_requirements", SampleRequirementsDraftDataHandler),
("/api/v1/flowcells", FlowcellsDataHandler),
("/api/v1/flowcell_info2/([^/]*)$", FlowcellsInfoDataHandler),
("/api/v1/flowcell_info/([^/]*)$", OldFlowcellsInfoDataHandler),
("/api/v1/flowcell_qc/([^/]*)$", FlowcellQCHandler),
("/api/v1/flowcell_demultiplex/([^/]*)$", FlowcellDemultiplexHandler),
("/api/v1/flowcell_q30/([^/]*)$", FlowcellQ30Handler),
("/api/v1/flowcell_notes/([^/]*)$", FlowcellNotesDataHandler),
("/api/v1/flowcell_links/([^/]*)$", FlowcellLinksDataHandler),
("/api/v1/flowcell_search/([^/]*)$", FlowcellSearchHandler),
("/api/v1/flowcell_yield/([^/]*)$", DataFlowcellYieldHandler),
tornado.web.URLSpec(
"/api/v1/frag_an_image/(?P<project>[^/]+)/(?P<sample>[^/]+)/(?P<step>[^/]+)",
FragAnImageHandler,
name="FragAnImageHandler",
),
("/api/v1/get_agreement_doc/([^/]*)$", AgreementDataHandler),
("/api/v1/get_agreement_template_text", AgreementTemplateTextHandler),
("/api/v1/get_order_det_invoicing/([^/]*)", InvoicingOrderDetailsHandler),
("/api/v1/get_sent_invoices", SentInvoiceHandler),
("/api/v1/generate_invoice", GenerateInvoiceHandler),
("/api/v1/generate_invoice_spec", InvoiceSpecDateHandler),
("/api/v1/invoice_spec_list", InvoicingPageDataHandler),
("/api/v1/instrument_cluster_density", InstrumentClusterDensityDataHandler),
(
"/api/v1/instrument_cluster_density.png",
InstrumentClusterDensityPlotHandler,
),
("/api/v1/instrument_error_rates", InstrumentErrorrateDataHandler),
("/api/v1/instrument_error_rates.png", InstrumentErrorratePlotHandler),
("/api/v1/instrument_logs", DataInstrumentLogsHandler),
("/api/v1/instrument_logs/([^/]*)$", DataInstrumentLogsHandler),
("/api/v1/instrument_names", InstrumentNamesHandler),
("/api/v1/instrument_unmatched", InstrumentUnmatchedDataHandler),
("/api/v1/instrument_unmatched.png", InstrumentUnmatchedPlotHandler),
("/api/v1/instrument_yield", InstrumentYieldDataHandler),
("/api/v1/instrument_yield.png", InstrumentYieldPlotHandler),
("/api/v1/last_updated", UpdatedDocumentsDatahandler),
("/api/v1/last_psul", LastPSULRunHandler),
("/api/v1/latest_sticky_run_note/([^/]*)", LatestStickyNoteHandler),
("/api/v1/libpooling_queues", LibraryPoolingQueuesDataHandler),
("/api/v1/mark_agreement_signed", AgreementMarkSignHandler),
("/api/v1/pricing_date_to_version", PricingDateToVersionDataHandler),
("/api/v1/pricing_exchange_rates", PricingExchangeRatesDataHandler),
("/api/v1/pricing_publish_draft", PricingPublishDataHandler),
("/api/v1/pricing_reassign_lock", PricingReassignLockDataHandler),
("/api/v1/pricing_validate_draft", PricingValidateDraftDataHandler),
("/api/v1/prio_projects", PrioProjectsTableHandler),
("/api/v1/proj_staged/([^/]*)$", DataDeliveryHandler),
("/api/v1/projects", ProjectsDataHandler),
("/api/v1/project/([^/]*)$", ProjectSamplesDataHandler),
("/api/v1/project/([^/]*)/tickets", ProjectTicketsDataHandler),
("/api/v1/projects_fields", ProjectsFieldsDataHandler),
("/api/v1/project_summary/([^/]*)$", ProjectDataHandler),
("/api/v1/project_search/([^/]*)$", ProjectsSearchHandler),
("/api/v1/presets", PresetsHandler),
("/api/v1/presets/onloadcheck", PresetsOnLoadHandler),
("/api/v1/projectqc/([^/]*)$", ProjectQCDataHandler),
("/api/v1/qpcr_pools", qPCRPoolsDataHandler),
("/api/v1/rna_report/([^/]*$)", ProjectRNAMetaDataHandler),
("/api/v1/running_notes/([^/]*)$", RunningNotesDataHandler),
("/api/v1/new_running_notes/([^/]*)$", NEWRunningNotesDataHandler),
("/api/v1/links/([^/]*)$", LinksDataHandler),
("/api/v1/sample_requirements", SampleRequirementsDataHandler),
(
"/api/v1/sample_requirements_publish_draft",
SampleRequirementsPublishDataHandler,
),
(
"/api/v1/sample_requirements_validate_draft",
SampleRequirementsValidateDraftDataHandler,
),
(
"/api/v1/sample_requirements_reassign_lock",
SampleRequirementsReassignLockDataHandler,
),
("/api/v1/save_quote", SaveQuoteHandler),
("/api/v1/sequencing_queues", SequencingQueuesDataHandler),
("/api/v1/sensorpush", SensorpushDataHandler),
("/api/v1/sensorpush_warnings", SensorpushWarningsDataHandler),
("/api/v1/stats", StatsAggregationHandler),
("/api/v1/stats/application_open_projects", ApplicationOpenProjectsHandler),
("/api/v1/stats/application_open_samples", ApplicationOpenSamplesHandler),
("/api/v1/stats/week_instr_yield", WeekInstrumentTypeYieldHandler),
("/api/v1/stats/year_application", YearApplicationsProjectHandler),
("/api/v1/stats/year_application_samples", YearApplicationsSamplesHandler),
("/api/v1/stats/year_affiliation_projects", YearAffiliationProjectsHandler),
(
"/api/v1/stats/year_deliverytime_projects",
YearDeliverytimeProjectsHandler,
),
(
"/api/v1/stats/year_deliverytime_application",
YearDeliverytimeApplicationHandler,
),
("/api/v1/deliveries/set_bioinfo_responsible$", DeliveriesPageHandler),
("/api/v1/suggestions", SuggestionBoxDataHandler),
("/api/v1/test/(\w+)?", TestDataHandler),
("/api/v1/user_management/users", UserManagementDataHandler),
("/api/v1/workset/([^/]*)$", WorksetDataHandler),
("/api/v1/worksets", WorksetsDataHandler),
("/api/v1/workset_search/([^/]*)$", WorksetSearchHandler),
("/api/v1/workset_notes/([^/]*)$", WorksetNotesDataHandler),
("/api/v1/workset_links/([^/]*)$", WorksetLinksHandler),
("/api/v1/workset_queues", WorksetQueuesDataHandler),
("/api/v1/closed_worksets", ClosedWorksetsHandler),
("/barcode", BarcodeHandler),
("/applications", ApplicationsHandler),
("/application/([^/]*)$", ApplicationHandler),
("/bioinfo/(P[^/]*)$", BioinfoAnalysisHandler),
("/deliveries", DeliveriesPageHandler),
("/flowcells", FlowcellsHandler),
("/flowcells/(\d{6,8}_[^/]*)$", FlowcellHandler),
("/flowcells_ont/(\d{8}_[^/]*)$", ONTFlowcellHandler),
("/flowcells_ont/(\d{8}_[^/]*)/[^/]*$", ONTReportHandler),
("/flowcells_plot", FlowcellPlotHandler),
("/data_delivered_plot", DeliveryPlotHandler),
("/generate_quote", GenerateQuoteHandler),
("/instrument_logs", InstrumentLogsHandler),
("/instrument_logs/([^/]*)$", InstrumentLogsHandler),
("/invoicing", InvoicingPageHandler),
("/libpooling_queues", LibraryPoolingQueuesHandler),
("/multiqc_report/([^/]*)$", MultiQCReportHandler),
("/pools_qpcr", qPCRPoolsHandler),
("/pricing_preview", PricingPreviewHandler),
("/pricing_quote", PricingQuoteHandler),
("/pricing_update", PricingUpdateHandler),
("/production/cronjobs", ProductionCronjobsHandler),
("/project/([^/]*)$", ProjectSamplesHandler),
("/project/(P[^/]*)/([^/]*)$", ProjectSamplesHandler),
("/projects", ProjectsHandler),
("/proj_meta", ProjMetaCompareHandler),
("/reads_total/([^/]*)$", ReadsTotalHandler),
("/rec_ctrl_view/([^/]*)$", RecCtrlDataHandler),
("/sample_requirements", SampleRequirementsViewHandler),
("/sample_requirements_preview", SampleRequirementsPreviewHandler),
("/sample_requirements_update", SampleRequirementsUpdateHandler),
("/sensorpush", SensorpushHandler),
("/sequencing_queues", SequencingQueuesHandler),
("/suggestion_box", SuggestionBoxHandler),
("/user_management", UserManagementHandler),
("/userpref", UserPrefPageHandler),
("/userpref_b5", UserPrefPageHandler_b5),
("/worksets", WorksetsHandler),
("/workset_queues", WorksetQueuesHandler),
("/workset/([^/]*)$", WorksetHandler),
(r".*", BaseHandler),
]
self.declared_handlers = handlers
# Load templates
self.loader = template.Loader("design")
# Global connection to the database
couch = Server(settings.get("couch_server", None))
if couch:
self.agreements_db = couch["agreements"]
self.agreement_templates_db = couch["agreement_templates"]
self.analysis_db = couch["analysis"]
self.application_categories_db = couch["application_categories"]
self.bioinfo_db = couch["bioinfo_analysis"]
self.cost_calculator_db = couch["cost_calculator"]
self.cronjobs_db = couch["cronjobs"]
self.flowcells_db = couch["flowcells"]
self.gs_users_db = couch["gs_users"]
self.instruments_db = couch["instruments"]
self.instrument_logs_db = couch["instrument_logs"]
self.nanopore_runs_db = couch["nanopore_runs"]
self.pricing_exchange_rates_db = couch["pricing_exchange_rates"]
self.projects_db = couch["projects"]
self.sample_requirements_db = couch["sample_requirements"]
self.sensorpush_db = couch["sensorpush"]
self.server_status_db = couch["server_status"]
self.suggestions_db = couch["suggestion_box"]
self.worksets_db = couch["worksets"]
self.x_flowcells_db = couch["x_flowcells"]
self.running_notes_db = couch["running_notes"]
else:
print(settings.get("couch_server", None))
raise IOError("Cannot connect to couchdb")
# Load columns and presets from genstat-defaults user in StatusDB
genstat_id = ""
user_id = ""
user = settings.get("username", None)
for u in self.gs_users_db.view("authorized/users"):
if u.get("key") == "genstat-defaults":
genstat_id = u.get("value")
# It's important to check that this user exists!
if not genstat_id:
raise RuntimeError(
"genstat-defaults user not found on {}, please "
"make sure that the user is available with the "
"corresponding defaults information.".format(
settings.get("couch_server", None)
)
)
# We need to get this database as OrderedDict, so the pv_columns doesn't
# mess up
password = settings.get("password", None)
headers = {
"Accept": "application/json",
"Authorization": "Basic "
+ "{}:{}".format(
base64.b64encode(bytes(user, "ascii")),
base64.b64encode(bytes(password, "ascii")),
),
}
decoder = json.JSONDecoder(object_pairs_hook=OrderedDict)
user_url = "{}/gs_users/{}".format(settings.get("couch_server"), genstat_id)
json_user = (
requests.get(user_url, headers=headers).content.rstrip().decode("ascii")
)
self.genstat_defaults = decoder.decode(json_user)
# Load private instrument listing
self.instrument_list = settings.get("instruments")
# If settings states mode, no authentication is used
self.test_mode = settings["Testing mode"]
# google oauth key
self.oauth_key = settings["google_oauth"]["key"]
# ZenDesk
self.zendesk_url = settings["zendesk"]["url"]
self.zendesk_user = settings["zendesk"]["username"]
self.zendesk_token = settings["zendesk"]["token"]
self.zendesk = Zenpy(
email=self.zendesk_user,
token=self.zendesk_token,
subdomain=urlsplit(self.zendesk_url).hostname.split(".")[0],
)
# Trello
self.trello_api_key = settings["trello"]["api_key"]
self.trello_api_secret = settings["trello"]["api_secret"]
self.trello_token = settings["trello"]["token"]
# Slack
self.slack_token = settings["slack"]["token"]
# Load password seed
self.password_seed = settings.get("password_seed")
# load logins for the genologics sftp
self.genologics_login = settings["sftp"]["login"]
self.genologics_pw = settings["sftp"]["password"]
# Location of the psul log
self.psul_log = settings.get("psul_log")
# to display instruments in the server status
self.server_status = settings.get("server_status")
# project summary - multiqc tab
self.multiqc_path = settings.get("multiqc_path")
# MinKNOW reports
self.minknow_path = settings.get("minknow_path")
# lims backend credentials
limsbackend_cred_loc = Path(
settings["lims_backend_credential_location"]
).expanduser()
with limsbackend_cred_loc.open() as cred_file:
self.lims_conf = yaml.safe_load(cred_file)
order_portal_cred_loc = Path(
settings["order_portal_credential_location"]
).expanduser()
with order_portal_cred_loc.open() as cred_file:
self.order_portal_conf = yaml.safe_load(cred_file)["order_portal"]
# Setup the Tornado Application
settings["debug"] = True
settings["static_path"] = "static"
settings["login_url"] = "/login"
if options["develop"]:
tornado.autoreload.watch("design/application.html")
tornado.autoreload.watch("design/applications.html")
tornado.autoreload.watch("design/base.html")
tornado.autoreload.watch("design/base_b5.html")
tornado.autoreload.watch("design/bioinfo_tab.html")
tornado.autoreload.watch("design/bioinfo_tab/run_lane_sample_view.html")
tornado.autoreload.watch("design/bioinfo_tab/sample_run_lane_view.html")
tornado.autoreload.watch("design/cronjobs.html")
tornado.autoreload.watch("design/data_delivered_plot.html")
tornado.autoreload.watch("design/deliveries.html")
tornado.autoreload.watch("design/error_page.html")
tornado.autoreload.watch("design/flowcell.html")
tornado.autoreload.watch("design/flowcell_error.html")
tornado.autoreload.watch("design/flowcell_trend_plot.html")
tornado.autoreload.watch("design/flowcells.html")
tornado.autoreload.watch("design/index.html")
tornado.autoreload.watch("design/instrument_logs.html")
tornado.autoreload.watch("design/invoicing.html")
tornado.autoreload.watch("design/barcode.html")
tornado.autoreload.watch("design/link_tab.html")
tornado.autoreload.watch("design/qpcr_pools.html")
tornado.autoreload.watch("design/pricing_products.html")
tornado.autoreload.watch("design/pricing_quote.html")
tornado.autoreload.watch("design/pricing_quote_tbody.html")
tornado.autoreload.watch("design/proj_meta_compare.html")
tornado.autoreload.watch("design/project_samples.html")
tornado.autoreload.watch("design/projects.html")
tornado.autoreload.watch("design/reads_total.html")
tornado.autoreload.watch("design/rec_ctrl_view.html")
tornado.autoreload.watch("design/running_notes_help.html")
tornado.autoreload.watch("design/running_notes_tab.html")
tornado.autoreload.watch("design/sensorpush.html")
tornado.autoreload.watch("design/suggestion_box.html")
tornado.autoreload.watch("design/unauthorized.html")
tornado.autoreload.watch("design/user_management.html")
tornado.autoreload.watch("design/user_preferences.html")
tornado.autoreload.watch("design/workset_samples.html")
tornado.autoreload.watch("design/worksets.html")
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == "__main__":
# Tornado built-in command line parsing. Auto configures logging
define(
"testing_mode",
default=False,
help=(
"WARNING, this option disables "
"all security measures, use only "
"for testing purposes"
),
)
define(
"develop",
default=False,
help=(
"Define develop mode to look for changes "
"in files and automatically reloading them"
),
)
define(
"port", default=9761, type=int, help="The port that the server will listen to."
)
# After parsing the command line, the command line flags are stored in tornado.options
tornado.options.parse_command_line()
# Load configuration file
with open("settings.yaml") as settings_file:
server_settings = yaml.full_load(settings_file)
server_settings["Testing mode"] = options["testing_mode"]
if "cookie_secret" not in server_settings:
cookie_secret = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
server_settings["cookie_secret"] = cookie_secret
# Instantiate Application
application = Application(server_settings)
# Load ssl certificate and key files
ssl_cert = server_settings.get("ssl_cert", None)
ssl_key = server_settings.get("ssl_key", None)
if ssl_cert and ssl_key:
ssl_options = {"certfile": ssl_cert, "keyfile": ssl_key}
else:
ssl_options = None
# Start HTTP Server
http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options)
http_server.listen(options["port"])
# Get a handle to the instance of IOLoop
ioloop = tornado.ioloop.IOLoop.instance()
# Start the IOLoop
ioloop.start()