CostaPy base
This commit is contained in:
parent
c52b1b397f
commit
6a1cf1d167
0
config/__init__.py
Normal file
0
config/__init__.py
Normal file
7
config/database.py
Executable file
7
config/database.py
Executable file
@ -0,0 +1,7 @@
|
||||
main_db = {
|
||||
'host' : 'localhost' ,
|
||||
'user' : 'root' ,
|
||||
'password' : '' ,
|
||||
'database' : 'melon' ,
|
||||
'autocommit' : True ,
|
||||
}
|
27
config/directory.py
Normal file
27
config/directory.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
page = "static/page"
|
||||
template = "static/template"
|
||||
thumbs = 'static/media/thumbs/'
|
||||
dirconfig = {
|
||||
'/' :
|
||||
{
|
||||
'tools.sessions.on' : True ,
|
||||
'tools.staticdir.root' : os.path.abspath(os.getcwd()) ,
|
||||
},
|
||||
'/lib' :
|
||||
{
|
||||
'tools.staticdir.on' : True ,
|
||||
'tools.staticdir.dir' : './static/lib' ,
|
||||
},
|
||||
'/css' :
|
||||
{
|
||||
'tools.staticdir.on' : True ,
|
||||
'tools.staticdir.dir' : './static/css' ,
|
||||
},
|
||||
'/media' :
|
||||
{
|
||||
'tools.staticdir.on' : True ,
|
||||
'tools.staticdir.dir' : './static/media' ,
|
||||
},
|
||||
}
|
2
config/globalvar.py
Executable file
2
config/globalvar.py
Executable file
@ -0,0 +1,2 @@
|
||||
GV_base_url = "http://localhost:9999"
|
||||
GV_title = "Media Lounge Network"
|
7
config/server.py
Normal file
7
config/server.py
Normal file
@ -0,0 +1,7 @@
|
||||
update = {
|
||||
'server.socket_host' : "hostname" ,
|
||||
'server.socket_port' : "port" ,
|
||||
'tools.sessions.on' : True ,
|
||||
'engine.autoreload.on' : False ,
|
||||
'request.show_tracebacks' : False ,
|
||||
}
|
17
config/template.py
Normal file
17
config/template.py
Normal file
@ -0,0 +1,17 @@
|
||||
from core import html
|
||||
from config import directory
|
||||
|
||||
class main:
|
||||
|
||||
def __init__(self):
|
||||
self.html_page = html.main.get_html(directory.page )
|
||||
self.html_template = html.main.get_html(directory.template )
|
||||
|
||||
def user(self, page):
|
||||
params_list = {
|
||||
"template" : self.html_template ["template.html" ],
|
||||
"topnav" : self.html_template ["topnav.html" ],
|
||||
"footer" : self.html_template ["footer.html" ],
|
||||
"container" : self.html_page [f"{page}.html" ],
|
||||
}
|
||||
return params_list
|
0
core/__init__.py
Normal file
0
core/__init__.py
Normal file
17
core/html.py
Normal file
17
core/html.py
Normal file
@ -0,0 +1,17 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
class main:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_html(location):
|
||||
html_dict = {}
|
||||
html_page_list = os.listdir( location )
|
||||
for html_page in html_page_list:
|
||||
full_path = location + "/" + html_page
|
||||
html_handle = open( full_path , 'r' )
|
||||
html_raw = html_handle.read()
|
||||
html_dict[html_page] = html_raw
|
||||
return html_dict
|
23
costa.py
Normal file
23
costa.py
Normal file
@ -0,0 +1,23 @@
|
||||
import sys
|
||||
import cherrypy
|
||||
import handler
|
||||
|
||||
from config import server
|
||||
from config import directory
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
dirconfig = directory.dirconfig
|
||||
update = server.update
|
||||
|
||||
if len(sys.argv) >= 3:
|
||||
|
||||
update["server.socket_host"] = sys.argv[1]
|
||||
update["server.socket_port"] = int(sys.argv[2])
|
||||
|
||||
cherrypy.config.update ( update )
|
||||
cherrypy.quickstart ( handler.handler(), config = dirconfig )
|
||||
|
||||
else:
|
||||
print ("Usage : python<ver> costa.py <ip_address> <port> <service_name>")
|
||||
print ("Example : python3 costa.py localhost 81 CostaPySample")
|
44
handler.py
Executable file
44
handler.py
Executable file
@ -0,0 +1,44 @@
|
||||
import cherrypy
|
||||
import json
|
||||
|
||||
import config.globalvar as globalvar
|
||||
import config.template as pages
|
||||
|
||||
import modules.user.home as user_home
|
||||
import modules.user.portal as user_portal
|
||||
|
||||
import modules.api.portal.add as api_portal_add
|
||||
|
||||
class handler(pages.main):
|
||||
|
||||
def __init__(self):
|
||||
pages.main.__init__(self)
|
||||
|
||||
def index(self, **kwargs):
|
||||
kwargs["params_page"] = pages.main().user("home")
|
||||
return user_home.main().html(kwargs)
|
||||
index.exposed = True
|
||||
|
||||
def portal(self, **kwargs):
|
||||
kwargs["params_page"] = pages.main().user("portal")
|
||||
return user_portal.main().html(kwargs)
|
||||
portal.exposed = True
|
||||
|
||||
class api(pages.main):
|
||||
|
||||
def __init__(self):
|
||||
pages.main.__init__(self)
|
||||
|
||||
class portal(pages.main):
|
||||
def add(self, **kwargs):
|
||||
response = api_portal_add.main().result(kwargs)
|
||||
if response["message_action"] == "success":
|
||||
print ("Success")
|
||||
raise cherrypy.HTTPRedirect('/?message=success')
|
||||
else:
|
||||
print ("Failed")
|
||||
raise cherrypy.HTTPRedirect('/?message=failed')
|
||||
add.exposed = True
|
||||
portal=portal()
|
||||
|
||||
api=api()
|
Loading…
Reference in New Issue
Block a user