diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/database.py b/config/database.py new file mode 100755 index 0000000..75d622a --- /dev/null +++ b/config/database.py @@ -0,0 +1,7 @@ +main_db = { + 'host' : 'localhost' , + 'user' : 'root' , + 'password' : '' , + 'database' : 'melon' , + 'autocommit' : True , +} diff --git a/config/directory.py b/config/directory.py new file mode 100644 index 0000000..727ccf9 --- /dev/null +++ b/config/directory.py @@ -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' , + }, +} diff --git a/config/globalvar.py b/config/globalvar.py new file mode 100755 index 0000000..84e4675 --- /dev/null +++ b/config/globalvar.py @@ -0,0 +1,2 @@ +GV_base_url = "http://localhost:9999" +GV_title = "Media Lounge Network" diff --git a/config/server.py b/config/server.py new file mode 100644 index 0000000..3868f33 --- /dev/null +++ b/config/server.py @@ -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 , +} diff --git a/config/template.py b/config/template.py new file mode 100644 index 0000000..9ded351 --- /dev/null +++ b/config/template.py @@ -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 diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/html.py b/core/html.py new file mode 100644 index 0000000..edf4949 --- /dev/null +++ b/core/html.py @@ -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 diff --git a/costa.py b/costa.py new file mode 100644 index 0000000..4deec72 --- /dev/null +++ b/costa.py @@ -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 costa.py ") + print ("Example : python3 costa.py localhost 81 CostaPySample") diff --git a/handler.py b/handler.py new file mode 100755 index 0000000..71e13ca --- /dev/null +++ b/handler.py @@ -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()