| 1 |
""" |
| 2 |
Operator code based on DaCHS (e.g., custom grammars or pages, other helper |
| 3 |
code, or ``<code>`` items in RDs) should just need to ``from gavo import api`` |
| 4 |
and then work with what is in here. See |
| 5 |
http://docs.g-vo.org/DaCHS/ref.html#api-function-reference for what is |
| 6 |
available here. |
| 7 |
""" |
| 8 |
|
| 9 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 10 |
#c |
| 11 |
#c This program is free software, covered by the GNU GPL. See the |
| 12 |
#c COPYING file in the source distribution. |
| 13 |
|
| 14 |
|
| 15 |
# Not checked by pyflakes: API file with gratuitous imports |
| 16 |
|
| 17 |
from gavo import base |
| 18 |
from gavo import rscdesc |
| 19 |
from gavo import votable |
| 20 |
from gavo import web |
| 21 |
|
| 22 |
getRD = base.caches.getRD |
| 23 |
RD = rscdesc.RD |
| 24 |
|
| 25 |
from gavo.base import (getConfig, setConfig, getBinaryName, |
| 26 |
getDBConnection, DBError, IntegrityError, |
| 27 |
UnmanagedQuerier, AdhocQuerier, |
| 28 |
getTableConn, getAdminConn, getUntrustedConn, |
| 29 |
getWritableTableConn, getWritableAdminConn, |
| 30 |
NoMetaKey, Error, StructureError, ValidationError, LiteralParseError, |
| 31 |
ReportableError, NotFoundError, RDNotFound, SourceParseError, DataError, |
| 32 |
MetaValidationError, BadUnit, BadCode, |
| 33 |
parseFromString, |
| 34 |
makeStruct, |
| 35 |
parseUnit, |
| 36 |
getMetaText, |
| 37 |
ui, |
| 38 |
resolveCrossId, getTableDefForTable, |
| 39 |
SERVER_SOFTWARE) |
| 40 |
|
| 41 |
from gavo.formats import formatData, getFormatted |
| 42 |
from gavo.formats.votablewrite import (writeAsVOTable, getAsVOTable, |
| 43 |
VOTableContext) |
| 44 |
|
| 45 |
from gavo.grammars.customgrammar import CustomRowIterator, CustomGrammar |
| 46 |
|
| 47 |
from gavo.helpers.processing import (CannotComputeHeader, |
| 48 |
FileProcessor, ImmediateHeaderProcessor, HeaderProcessor, |
| 49 |
AnetHeaderProcessor, PreviewMaker, OneDPreviewMaker, |
| 50 |
SpectralPreviewMaker, DLPreviewMaker, procmain) |
| 51 |
|
| 52 |
from gavo.helpers.fitstricks import (addHistoryCard, |
| 53 |
updateTemplatedHeader, makeHeaderFromTemplate, getTemplateForName) |
| 54 |
|
| 55 |
from gavo.rsc import (TableForDef, DBTable, makeData, parseValidating, |
| 56 |
parseNonValidating, getParseOptions, Data, makeDependentsFor, |
| 57 |
createDump, restoreDump) |
| 58 |
|
| 59 |
from gavo.rscdef import (DataDescriptor, TableDef, |
| 60 |
getFlatName, getReferencedElement) |
| 61 |
|
| 62 |
from gavo.stc import (dateTimeToJYear, dateTimeToJdn, dateTimeToMJD, |
| 63 |
jYearToDateTime, jdnToDateTime, jdnToJYear, mjdToDateTime, parseISODT, isMJD, |
| 64 |
JD_MJD) |
| 65 |
|
| 66 |
from gavo.svcs import (UnknownURI, ForbiddenURI, Authenticate, |
| 67 |
WebRedirect, SeeOther, Core, OutputTableDef, QueryMeta) |
| 68 |
|
| 69 |
from gavo.user.logui import LoggingUI |
| 70 |
from gavo.user.plainui import StingyPlainUI, PlainUI |
| 71 |
|
| 72 |
from gavo.utils import ( |
| 73 |
loadPythonModule, formatISODT, bytify, EqualingRE, |
| 74 |
document, |
| 75 |
pyfits, cutoutFITS, |
| 76 |
safeReplaced, |
| 77 |
QuotedName, |
| 78 |
urlopenRemote, setUserAgent) |
| 79 |
|
| 80 |
from gavo.votable import VOTableError, ADQLTAPJob |
| 81 |
|
| 82 |
from gavo.web import ServiceBasedPage, renderDCErrorPage |
| 83 |
from gavo.helpers.testtricks import getXMLTree |
| 84 |
|
| 85 |
from gavo.rscdef.rmkfuncs import * |
| 86 |
|
| 87 |
@document |
| 88 |
def reloadLocal(): |
| 89 |
"""reloads the local namespace. |
| 90 |
|
| 91 |
This is material an operator defines in $GAVO_CONFIG/local.py. If that |
| 92 |
file is missing or unreadable, api.local will be a stub that raises |
| 93 |
a constant error regardless of what you try to getattr from it. |
| 94 |
""" |
| 95 |
global local |
| 96 |
modpath = base.getConfig("configDir") / "local" |
| 97 |
try: |
| 98 |
local, _ = loadPythonModule(modpath) |
| 99 |
except (FileNotFoundError, ImportError): |
| 100 |
class _: |
| 101 |
def __getattr__(self, name): |
| 102 |
raise ReportableError(f"No file {modpath}.py found") |
| 103 |
local = _() |
| 104 |
|
| 105 |
|
| 106 |
reloadLocal() |
| 107 |
|
| 108 |
__version__ = base.getVersion() |