Completed
Branch master (9edffc)
by Jordi
04:36
created

bika.lims.exportimport.instruments.thermoscientific.gallery.Ts9861x   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 59
dl 0
loc 88
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C Import() 0 57 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ThermoGallery9861xTSVParser.getAttachmentFileType() 0 2 1
A ThermoGallery9861xImporter.getKeywordsToBeExcluded() 0 2 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
""" Thermo Scientific 'Gallery 9861x'
9
"""
10
from bika.lims import bikaMessageFactory as _
11
from bika.lims.utils import t
12
from . import ThermoGalleryImporter, ThermoGalleryTSVParser
13
import json
14
import traceback
15
16
title = "Thermo Scientific - Gallery 9861x"
17
18
19
def Import(context, request):
20
    """ Thermo Scientific - Gallery 9861x analysis results
21
    """
22
    infile = request.form['thermoscientific_gallery_9861x_file']
23
    fileformat = request.form['thermoscientific_gallery_9861x_format']
24
    artoapply = request.form['thermoscientific_gallery_9861x_artoapply']
25
    override = request.form['thermoscientific_gallery_9861x_override']
26
    instrument = request.form.get('thermoscientific_gallery_9861x_instrument', None)
27
    errors = []
28
    logs = []
29
30
    # Load the most suitable parser according to file extension/options/etc...
31
    parser = None
32
    if not hasattr(infile, 'filename'):
33
        errors.append(_("No file selected"))
34
    if fileformat == 'tsv_40':
35
        parser = ThermoGallery9861xTSVParser(infile)
36
    else:
37
        errors.append(t(_("Unrecognized file format ${fileformat}",
38
                          mapping={"fileformat": fileformat})))
39
40
    if parser:
41
        # Load the importer
42
        status = ['sample_received', 'attachment_due', 'to_be_verified']
43
        if artoapply == 'received':
44
            status = ['sample_received']
45
        elif artoapply == 'received_tobeverified':
46
            status = ['sample_received', 'attachment_due', 'to_be_verified']
47
48
        over = [False, False]
49
        if override == 'nooverride':
50
            over = [False, False]
51
        elif override == 'override':
52
            over = [True, False]
53
        elif override == 'overrideempty':
54
            over = [True, True]
55
56
        importer = ThermoGallery9861xImporter(parser=parser,
57
                                              context=context,
58
                                              allowed_ar_states=status,
59
                                              allowed_analysis_states=None,
60
                                              override=over,
61
                                              instrument_uid=instrument)
62
        tbex = ''
63
        try:
64
            importer.process()
65
        except:
66
            tbex = traceback.format_exc()
67
        errors = importer.errors
68
        logs = importer.logs
69
        warns = importer.warns
70
        if tbex:
71
            errors.append(tbex)
72
73
    results = {'errors': errors, 'log': logs, 'warns': warns}
0 ignored issues
show
introduced by
The variable warns does not seem to be defined in case parser on line 40 is False. Are you sure this can never be the case?
Loading history...
74
75
    return json.dumps(results)
76
77
78
class ThermoGallery9861xTSVParser(ThermoGalleryTSVParser):
79
80
    def getAttachmentFileType(self):
81
        return "Thermo Scientific Gallery 9861x TSV/XLS"
82
83
84
class ThermoGallery9861xImporter(ThermoGalleryImporter):
85
86
    def getKeywordsToBeExcluded(self):
87
        return []
88