1 """
2 Cores wrapping some external program directly, or having some
3 python code doing things.
4 """
5
6
7
8
9
10
11
12 from gavo import base
13 from gavo import rsc
14 from gavo import rscdef
15 from gavo.svcs import core
16
17
19 """A core wrapping external applications.
20
21 ComputedCores wrap command line tools taking command line arguments,
22 reading from stdin, and outputting to stdout.
23
24 The command line arguments are taken from the inputTable's parameters,
25 stdin is created by serializing the inputTable's rows like they are
26 serialized for with the TSV output, except only whitespace is entered
27 between the values.
28
29 The output is the primary table of parsing the program's output with
30 the data child.
31
32 While in principle more declarative than PythonCores, these days I'd
33 say rather use one of those.
34 """
35 name_ = "computedCore"
36
37 _computer = rscdef.ResdirRelativeAttribute("computer",
38 default=base.Undefined, description="Resdir-relative basename of"
39 " the binary doing the computation. The standard rules for"
40 " cross-platform binary name determination apply.",
41 copyable=True)
42 _resultParse = base.StructAttribute("resultParse",
43 description="Data descriptor to parse the computer's output.",
44 childFactory=rscdef.DataDescriptor, copyable=True)
45
46 - def start_(self, ctx, name, value):
47 if name=="outputTable":
48 raise base.StructureError("Cannot define a computed core's"
49 " output table.", hint="Computed cores have their output"
50 " defined by the primary table of resultParse.")
51 return core.Core.start_(self, ctx, name, value)
52
54 raise base.StructureError("ComputedCore was a bad idea and"
55 " is therefore removed in DaCHS 1.0")
56
57
59 """A definition of a pythonCore's functionalty.
60
61 This is a procApp complete with setup and code; you could inherit
62 between these.
63
64 coreProcs see the embedding service, the input table passed, and the
65 query metadata as service, inputTable, and queryMeta, respectively.
66
67 The core itself is available as self.
68 """
69 name_ = "coreProc"
70 requiredType = "coreProc"
71 formalArgs = "self, service, inputTable, queryMeta"
72
73 additionalNamesForProcs = {
74 "rsc": rsc
75 }
76
77
79 """A core doing computation using a piece of python.
80
81 See `Python Cores instead of Custom Cores`_ in the reference.
82 """
83 name_ = "pythonCore"
84
85 _computer = base.StructAttribute("coreProc", default=base.Undefined,
86 childFactory=CoreProc,
87 description="Code making the outputTable from the inputTable.",
88 copyable=True)
89
95 - def run(self, service, inputTable, queryMeta):
96 return self.coreProc.compile()(self, service, inputTable, queryMeta)
97