X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fnbi.py;h=2dfeb22e52bc5398ff740be4d92ea5238203cb1c;hp=b7a6990bf9f4a919bdd2c7af128156deba415d71;hb=f717cbe40358a8a8246d7936064cf235e2ff7f79;hpb=cd65be33d44114e73936813eaf790e6a12b0df63 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index b7a6990..2dfeb22 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -1,6 +1,19 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import cherrypy import time import json @@ -431,7 +444,8 @@ class Server(object): elif "application/yaml" in accept or "*/*" in accept or "text/plain" in accept: pass - else: + # if there is not any valid accept, raise an error. But if response is already an error, format in yaml + elif cherrypy.response.status >= 400: raise cherrypy.HTTPError(HTTPStatus.NOT_ACCEPTABLE.value, "Only 'Accept' of type 'application/json' or 'application/yaml' " "for output format are available") @@ -531,7 +545,7 @@ class Server(object): def test(self, *args, **kwargs): thread_info = None if args and args[0] == "help": - return "
\ninit\nfile/  download file\ndb-clear/table\nprune\nlogin\nlogin2\n"\
+            return "
\ninit\nfile/  download file\ndb-clear/table\nfs-clear[/folder]\nlogin\nlogin2\n"\
                    "sleep/
" elif args and args[0] == "init": @@ -552,9 +566,16 @@ class Server(object): return f elif len(args) == 2 and args[0] == "db-clear": - return self.engine.db.del_list(args[1], kwargs) - elif args and args[0] == "prune": - return self.engine.prune() + deleted_info = self.engine.db.del_list(args[1], kwargs) + return "{} {} deleted\n".format(deleted_info["deleted"], args[1]) + elif len(args) and args[0] == "fs-clear": + if len(args) >= 2: + folders = (args[1],) + else: + folders = self.engine.fs.dir_ls(".") + for folder in folders: + self.engine.fs.file_delete(folder) + return ",".join(folders) + " folders deleted\n" elif args and args[0] == "login": if not cherrypy.request.headers.get("Authorization"): cherrypy.response.headers["WWW-Authenticate"] = 'Basic realm="Access to OSM site", charset="UTF-8"' @@ -601,7 +622,7 @@ class Server(object): " session: {}\n".format(cherrypy.session) + " cookie: {}\n".format(cherrypy.request.cookie) + " method: {}\n".format(cherrypy.request.method) + - " session: {}\n".format(cherrypy.session.get('fieldname')) + + " session: {}\n".format(cherrypy.session.get('fieldname')) + " body:\n") return_text += " length: {}\n".format(cherrypy.request.body.length) if cherrypy.request.body.length: @@ -837,7 +858,7 @@ class Server(object): cherrypy.log("Exception {}".format(e)) else: http_code_value = cherrypy.response.status = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR - cherrypy.log("CRITICAL: Exception {}".format(e)) + cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) http_code_name = HTTPStatus.BAD_REQUEST.name if hasattr(outdata, "close"): # is an open file outdata.close()