Skip to content

Commit 861efdb

Browse files
author
Casey Boettcher
committed
CherryPy server picking up config and serving static form file.
1 parent a2d8190 commit 861efdb

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ out
44
*.out
55
gen
66
test/xforce.cfg
7+
notes.txt
78

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests>=2.18.4
22
IPy>=0.83
3+
CherryPy>=11.0.0

web/server.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
[/]
3+
tools.sessions.on: True
4+
tools.staticdir.on = True
5+
tools.staticdir.root = os.path.abspath('.')
6+
tools.staticdir.dir = os.path.join(os.path.abspath('.'), 'web')
7+
tools.staticdir.index = "xfipchk.html"

web/webui.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
import cherrypy
4+
import os
5+
import io
6+
7+
8+
class XforceForm(object):
9+
def __init__(self, address='127.0.0.1', port=8000):
10+
cherrypy.config.update({'tools.staticdir.debug': True})
11+
# cherrypy.config.update('web/server.cfg')
12+
# parms override anything in config
13+
cherrypy.config.update({'server.socket_port': port,
14+
'server.socket_host': address})
15+
16+
# def start_server(self):
17+
# cherrypy.quickstart(XforceForm(), '/', './web/server.cfg')
18+
19+
@cherrypy.expose
20+
def index(self):
21+
return "/"
22+
23+
24+
if __name__ == '__main__':
25+
cherrypy.quickstart(XforceForm())

xfipchk.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
import argparse
1717
import requests
1818
import IPy
19-
import http.server
20-
import socketserver
19+
import web.webui
20+
import cherrypy
21+
2122

2223
XFORCE_API_BASE = 'https://api.xforce.ibmcloud.com'
2324
XFORCE_API_IP_REP = 'ipr'
@@ -147,7 +148,7 @@ def call_xforce_api(address_list, key, password):
147148
"""
148149
results = []
149150
for a in address_list:
150-
url = "{}/{}/{}".format(XFORCE_API_BASE, XFORCE_API_IP_REP, a)
151+
url = "{}/{}/{}".foGrmat(XFORCE_API_BASE, XFORCE_API_IP_REP, a)
151152
results.append(requests.get(url, auth=(key, password)).json())
152153
return results
153154

@@ -179,12 +180,9 @@ def print_json_file(results, file):
179180
file.write('######################################\n')
180181

181182

182-
def start_server(ip_address="127.0.0.1", port=8000):
183-
# we want to serve out of the web directory
184-
handler = http.server.SimpleHTTPRequestHandler
185-
with socketserver.TCPServer((ip_address, port), handler) as httpd:
186-
print("Starting HTTP server on port {0}".format(port))
187-
httpd.serve_forever()
183+
def start_server(address='127.0.0.1', port=8000):
184+
webapp = web.webui.XforceForm(address, port)
185+
cherrypy.quickstart(webapp, '/', './web/server.cfg')
188186

189187

190188
def main():

0 commit comments

Comments
 (0)