valid_args = [x["Flag2"].lstrip("-") for x in valid_args] args = [config["GMT"]["report_bin"]] for key, val in params.items(): if key in valid_args and isinstance(val, str): args.append("--" + key) args.append(val) else: logger.warning("Removing invalid gmt-argument: --%s %s" % (key, str(val))) logger.info("Executing: %s" % (" ".join(args))) proc = subprocess.Popen(args, cwd=os.path.dirname( config["GMT"]["report_bin"]), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = proc.communicate() if proc.returncode != 0: logger.error("Error while executing %s" % (" ".join(args))) logger.error(out.decode("utf-8")) return jsfail(returncode=proc.returncode) return jssuccess(returncode=proc.returncode, output=str(out)) application = startapp(GmtSrv)
error = None try: ftp = ftplib.FTP() ftp.connect(host, port) ftp.login(username, password) ftp.set_pasv(True) path = os.path.normpath(path) ftp.cwd(os.path.dirname(path)) ftp.storbinary("STOR %s" % os.path.basename(path), io.BytesIO(bytes(text, "utf-8"))) ftp.quit() except ftplib.all_errors as err: error = str(err) dbmsg["errors"] = error self._db["messages_sent"].insert(dbmsg) msgevt = { "id": dbmsg["Message-ID"], "user": dbmsg["SenderID"], "timestamp": dbmsg["CreatedTime"], "event": "msg_sent", } self._db["events"].insert(msgevt) if error is None: return jssuccess() return jsfail(errors=[error]) return jsfail(errors=["API version not supported."]) return jsdeny() application = startapp(MsgSrv)
tfp = self._db["tfps"].find_one({"code": row[0]}) if tfp is not None and row[2] >= minewh: out += "%f,%f,%f,%f\n" % (tfp["lon"], tfp["lat"], row[2], row[1]) return out # @cherrypy.expose def saveformdata(self, _form, **kwargs): doc = kwargs.copy() doc.pop("_id", None) doc["_ip"] = cherrypy.request.headers["X-Forwarded-For"] \ if "X-Forwarded-For" in cherrypy.request.headers \ else cherrypy.request.remote.ip doc["_form"] = _form doc["_time"] = datetime.datetime.now() self._db["formdata"].insert(doc) return jssuccess() # @cherrypy.expose def queryformdata(self, _form=None, **kwargs): if _form is not None: kwargs["_form"] = _form data = list(self._db["formdata"].find(kwargs)) return jssuccess(data=data) application = startapp(DataSrv)
val["_id"] = "{inst}_{station}_{timestamp!s}" \ .format_map(val) self._db["sealeveldata"].remove(val["_id"]) if val["_id"] not in ids: values.append(val) ids.append(val["_id"]) vnr += 1 else: verr += 1 if values != []: self._db["sealeveldata"].insert(values) last = self._db["sealeveldata"].find_one( { "inst": inst["name"], "station": station }, sort=[("timestamp", -1)]) lastts = None if last is None else last["timestamp"] return jssuccess(values=vnr, errors=verr, lastts=lastts) return jsfail(errors=["Parameter station is missing."]) return jsfail(errors=["Dataformat %s not known." % dataformat]) def feedsealevel_api2_xml(self, inst, xml): return jsfail(errors=["Not yet implemented."]) def feedsealevel_api2_text(self, inst, text): return jsfail(errors=["Not yet implemented."]) application = startapp(FeederSrv)
raise HTTPError("404 Not Found") raise HTTPError("403 Forbidden") @cherrypy.expose def scanenv(self, username=None, password=None): if username is None and password is None: user = self.getUser() else: user = self._db["users"].find_one({"username": username}) if user is not None: if "pwsalt" in user and "pwhash" in user: if not checkpassword(password, user["pwsalt"], user["pwhash"]): user = None if user is not None and user["permissions"].get("admin", False): self._db["envfiles"].remove() for file in recursivelistdir(config["simenv"]["envdir"]): elm = { "fname": os.path.relpath(file, config["simenv"]["envdir"]), "hash": hashfile(file), "size": os.stat(file).st_size, } elm["name"] = os.path.basename(elm["fname"]) elm["kind"] = os.path.dirname(elm["fname"]) self._db["envfiles"].insert(elm) return jssuccess(files=list(self._db["envfiles"].find())) return jsdeny() application = startapp(WorkerSrv)