1 """
2 Common functionality for the DC user interface.
3 """
4
5
6
7
8
9
10
11 import sys
12
13 from gavo import base
14
15
17 """returns the module name and a funciton name within the module for
18 the function selector funcSelector.
19
20 The function will exit if funcSelector is not a unique prefix within
21 functions.
22 """
23 matches = []
24 for key, res in functions:
25 if key.startswith(funcSelector):
26 matches.append(res)
27 if len(matches)==1:
28 return matches[0]
29 if matches:
30 sys.stderr.write("Multiple matches for function %s.\n\n"%funcSelector)
31 else:
32 sys.stderr.write("No match for function %s.\n\n"%funcSelector)
33 parser.print_help(file=sys.stderr)
34 sys.exit(1)
35
36
38 """helps getPertainingDDs
39 """
40 res = []
41 for dd in rd.dds:
42 if dd.auto:
43 res.append(dd)
44 return res
45
46
48 """helps getPertainingDDs
49 """
50 res = []
51 ddDict = dict((dd.id, dd) for dd in rd.dds)
52 for ddId in selectedIds:
53 if ddId not in ddDict:
54 raise base.ReportableError(
55 "The DD '%s' you are trying to import is not defined within"
56 " the RD '%s'."%(ddId, rd.sourceId),
57 hint="Data elements available in %s include %s"%(rd.sourceId,
58 ", ".join(ddDict) or '(None)'))
59 res.append(ddDict[ddId])
60 return res
61
62
64 """returns a list of dds on which imp or drop should operate.
65
66 By default, that's the "auto" dds of rd. If ddIds is not empty,
67 it is validated that all ids mentioned actually exist.
68
69 Finally, if no DDs are selected but DDs are available, an error is raised.
70 """
71 if selectedIds:
72 dds = _getSelectedDDIds(rd, selectedIds)
73 else:
74 dds = _getAutoDDIds(rd)
75 if not dds:
76 if not rd.dds:
77 base.ui.notifyWarning("There is no data element"
78 " in the RD %s; is that all right?"%rd.sourceId)
79 else:
80 raise base.ReportableError(
81 "Neither automatic not manual data selected from RD %s "%rd.sourceId,
82 hint="All data elements have auto=False. You have to"
83 " explicitely name one or more data to import (names"
84 " available: %s)"%(", ".join(dd.id or "(anon)" for dd in rd.dds)))
85 return dds
86