- Also delete sample data
This commit is contained in:
Peter Šurda 2021-02-10 17:13:31 +01:00
parent 935124968d
commit bfc4dbecb6
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
4 changed files with 14 additions and 11 deletions

View File

@ -1,9 +1,9 @@
[server] [server]
server_host = 127.0.0.1 server_host = 0.0.0.0
server_port = 8081 server_port = 8081
[app] [app]
user_data = user-data.txt user_data = user-data
meta_data = meta-data.txt meta_data = meta-data

View File

@ -1 +0,0 @@
suspended:httpd

View File

@ -1,2 +0,0 @@
This is a sample static file to be served
from cherrypy server at user-data url.

12
main.py
View File

@ -18,9 +18,6 @@ meta_data_filename = config["app"].get("meta_data", "meta_data_extra.txt")
class MainApp: class MainApp:
def __init__(self, *args):
self._init_ip()
def _init_ip(self): def _init_ip(self):
""" """
Get remote IP Get remote IP
@ -33,13 +30,20 @@ class MainApp:
except: except:
self.remoteip = cherrypy.request.remote.ip self.remoteip = cherrypy.request.remote.ip
try:
self.hostinfo = socket.gethostbyaddr(self.remoteip) self.hostinfo = socket.gethostbyaddr(self.remoteip)
except socket.herror:
self.hostinfo = ('localhost', )
@cherrypy.expose @cherrypy.expose
def user_data(self): def user_data(self):
""" """
Serves a static file Serves a static file
""" """
self._init_ip()
filepath = os.path.join(PATH, "data", self.hostinfo[0],
user_data_filename)
if not os.path.exists(filepath):
filepath = os.path.join(PATH, "data", user_data_filename) filepath = os.path.join(PATH, "data", user_data_filename)
return serve_file(filepath, "application/x-download", "attachment") return serve_file(filepath, "application/x-download", "attachment")
@ -48,6 +52,7 @@ class MainApp:
""" """
Return meta-data in YAML Return meta-data in YAML
""" """
self._init_ip()
hostname =self.hostinfo[0] hostname =self.hostinfo[0]
data = {"instance-id": hostname.split(".")[0], "local-hostname": hostname} data = {"instance-id": hostname.split(".")[0], "local-hostname": hostname}
@ -67,6 +72,7 @@ class MainApp:
:param data: meta-data to be added :param data: meta-data to be added
""" """
self._init_ip()
folder = os.path.join(PATH, "data", self.hostinfo[0]) folder = os.path.join(PATH, "data", self.hostinfo[0])
if not os.path.exists(folder): if not os.path.exists(folder):
os.makedirs(folder) os.makedirs(folder)