def tryRemoteReload(rdId): """tries to reload the rdId on a running service This only works if there's [web]adminpasswd and[web]serverURL set, and both match what the actual server uses. """ pw = config.get("web", "adminpasswd") # don't bother if admin passwd has not been set or when running unit tests. if pw == "" or pw == "this_is_the_unittest_suite": return try: f = utils.urlopenRemote(makeAbsoluteURL("/seffe/%s" % rdId), urllib.urlencode({ "__nevow_form__": "adminOps", "submit": "Reload RD" }), creds=("gavoadmin", pw)) f.read() except IOError, ex: utils.sendUIEvent( "Warning", "Could not reload %s RD (%s). This means" " that the server may still use stale metadata. You may want" " to reload %s manually (or restart the server)." % (rdId, ex, rdId))
def __init__(self, uploadURL, uploadName): self.uploadURL, self.name = uploadURL, uploadName self.file = utils.urlopenRemote(self.uploadURL) self.filename = uploadURL self.headers = self.file.info() major, minor, parSet = formats.getMIMEKey(self.headers.get( "content-type", "*/*")) self.type = "%s/%s"%(major, minor) self.type_options = dict(parSet)
def doHTTP(self, **moreArgs): """returns the result of parsing the current query plus moreArgs to the current registry. The result is returned as a string. """ srcURL = self.registry.rstrip("?") + "?" + self._getOpQS(**self.getKWs( **moreArgs)) base.ui.notifyInfo("OAI query %s" % srcURL) f = utils.urlopenRemote(srcURL) res = f.read() f.close() return res
def expireRDs(args): pw = base.getConfig("web", "adminpasswd") if pw == '': raise base.ReportableError( "expireRDs needs [web]adminpasswd config item.") for rdId in args.rdIds: if rdId.startswith("//"): rdId = "__system__" + rdId[1:] try: f = utils.urlopenRemote(base.makeAbsoluteURL("/seffe/" + urllib.quote(rdId)), urllib.urlencode({ "__nevow_form__": "adminOps", "submit": "Reload RD" }), creds=("gavoadmin", pw)) ignored = f.read( ) #noflake: don't care enough to check at this point. except IOError, msg: raise base.ReportableError("Failed to reload %s: %s" % (rdId, msg))
def _ingestUploads(uploads, connection): tds = [] for destName, src in uploads: if isinstance(src, tap.LocalFile): srcF = open(src.fullPath) else: try: srcF = utils.urlopenRemote(src) except IOError, ex: raise base.ui.logOldExc( base.ValidationError("Upload '%s' cannot be retrieved"%( src), "UPLOAD", hint="The I/O operation failed with the message: "+ str(ex))) if valuemappers.needsQuoting(destName): raise base.ValidationError("'%s' is not a valid table name on" " this site"%destName, "UPLOAD", hint="It either contains" " non-alphanumeric characters or conflicts with an ADQL" " reserved word. Quoted table names are not supported" " at this site.") uploadedTable = votableread.uploadVOTable(destName, srcF, connection, nameMaker=votableread.AutoQuotedNameMaker()) if uploadedTable is not None: tds.append(uploadedTable.tableDef) srcF.close()
def _createAuxiliaries(self, dd): from urllib import urlencode from gavo import votable if os.path.exists("q.cache"): f = open("q.cache") else: f = utils.urlopenRemote( "http://dc.g-vo.org/tap/sync", data=urlencode({ "LANG": "ADQL", "QUERY": "select *" " from wfpdb.main" " where object is not null and object!=''" " and instr_id='BYU102A'" " and method='objective prism'" })) with open("q.cache", "w") as cache: cache.write(f.read()) f = open("q.cache") data, metadata = votable.load(f) self.platemeta = {} for row in metadata.iterDicts(data): plateid = row["object"].replace(" ", "").lower() # for the following code, see import_platemeta in q.rd if row["object"] == "FBS 0966" and int(row["epoch"]) == 1974: row["object"] = "FBS 0966a" if row["object"] == "FBS 0326" and row["epoch"] > 1971.05: row["object"] = "FBS 0326a" if row["object"] == "FBS 0449" and row["epoch"] > 1971.38: row["object"] = "FBS 0449a" self.platemeta[plateid] = row
def value(self): try: f = utils.urlopenRemote(self.uploadURL) return f.read() finally: f.close()