Fixes
- Also delete sample data
This commit is contained in:
parent
935124968d
commit
bfc4dbecb6
|
@ -1,9 +1,9 @@
|
|||
|
||||
|
||||
[server]
|
||||
server_host = 127.0.0.1
|
||||
server_host = 0.0.0.0
|
||||
server_port = 8081
|
||||
|
||||
[app]
|
||||
user_data = user-data.txt
|
||||
meta_data = meta-data.txt
|
||||
user_data = user-data
|
||||
meta_data = meta-data
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
suspended:httpd
|
|
@ -1,2 +0,0 @@
|
|||
This is a sample static file to be served
|
||||
from cherrypy server at user-data url.
|
12
main.py
12
main.py
|
@ -18,9 +18,6 @@ meta_data_filename = config["app"].get("meta_data", "meta_data_extra.txt")
|
|||
|
||||
|
||||
class MainApp:
|
||||
def __init__(self, *args):
|
||||
self._init_ip()
|
||||
|
||||
def _init_ip(self):
|
||||
"""
|
||||
Get remote IP
|
||||
|
@ -33,13 +30,20 @@ class MainApp:
|
|||
except:
|
||||
self.remoteip = cherrypy.request.remote.ip
|
||||
|
||||
try:
|
||||
self.hostinfo = socket.gethostbyaddr(self.remoteip)
|
||||
except socket.herror:
|
||||
self.hostinfo = ('localhost', )
|
||||
|
||||
@cherrypy.expose
|
||||
def user_data(self):
|
||||
"""
|
||||
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)
|
||||
return serve_file(filepath, "application/x-download", "attachment")
|
||||
|
||||
|
@ -48,6 +52,7 @@ class MainApp:
|
|||
"""
|
||||
Return meta-data in YAML
|
||||
"""
|
||||
self._init_ip()
|
||||
hostname =self.hostinfo[0]
|
||||
data = {"instance-id": hostname.split(".")[0], "local-hostname": hostname}
|
||||
|
||||
|
@ -67,6 +72,7 @@ class MainApp:
|
|||
|
||||
:param data: meta-data to be added
|
||||
"""
|
||||
self._init_ip()
|
||||
folder = os.path.join(PATH, "data", self.hostinfo[0])
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
|
Loading…
Reference in New Issue
Block a user