Skip to content

Commit

Permalink
heavily refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Oct 31, 2023
1 parent 32a3aca commit fef8c60
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 939 deletions.
151 changes: 0 additions & 151 deletions frontend/cmsapp.py

This file was deleted.

118 changes: 22 additions & 96 deletions frontend/cmsmain.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,43 @@
'''
Created on 2022-12-03
@author: wf
'''
'''
Created on 2022-11-24
@author: wf
'''

from ngwidgets.cmd import WebserverCmd
from frontend.webserver import WebServer
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
from frontend.version import Version
from frontend.cmsapp import CmsApp
import os
import sys
import traceback
import webbrowser
# import after app!
from jpcore.justpy_app import JustpyServer
from frontend.server import Server

__version__ = Version.version
__date__ = Version.date
__updated__ = Version.updated

class CmsMain():
class CmsMain(WebserverCmd):
"""
ContentManagement System Main Program
"""

def __init__(self):
"""
construct me
constructor
"""
self.server = Server()
self.server.load()

def getArgParser(self,program_license,program_version_message):
# Setup argument parser
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-a","--about",help="show about info [default: %(default)s]",action="store_true")
parser.add_argument("-b","--browse",help="open browser", action="store_true")
parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="show debug info [default: %(default)s]")
parser.add_argument('--host',default=JustpyServer.getDefaultHost(),help="the host to serve / listen from [default: %(default)s]")
parser.add_argument('--logo',help="the server logo [default: %(default)s]",default=self.server.logo)
parser.add_argument('--port',type=int,default=8252,help="the port to serve from [default: %(default)s]")
parser.add_argument("--serve",help="start webserver",action="store_true")
parser.add_argument('-V', '--version', action='version', version=program_version_message)
return parser

def main(argv=None): # IGNORE:C0111
'''main program.'''

if argv is None:
argv=sys.argv[1:]
config=WebServer.get_config()
WebserverCmd.__init__(self, config, WebServer, DEBUG)
pass

program_name = os.path.basename(__file__)
program_shortdesc = Version.description
def getArgParser(self,description:str,version_msg)->ArgumentParser:
"""
override the default argparser call
"""
parser=super().getArgParser(description, version_msg)
parser.add_argument('--sites',nargs='+',required=False,help="the sites to enable")
return parser

program_version =f"v{__version__}"
program_build_date = str(__updated__)
program_version_message = f'{program_name} ({program_version},{program_build_date})'

user_name="Wolfgang Fahl"
program_license = '''%s
Created by %s on %s.
Copyright 2022-2023 Wolfgang Fahl. All rights reserved.
Licensed under the Apache License 2.0
http://www.apache.org/licenses/LICENSE-2.0
Distributed on an "AS IS" basis without warranties
or conditions of any kind, either express or implied.
USAGE
''' % (program_shortdesc, user_name,str(__date__))
try:
cmsMain=CmsMain()
parser=cmsMain.getArgParser(program_license, program_version_message)
args = parser.parse_args(argv)
if len(argv) < 1:
parser.print_usage()
sys.exit(1)
#ypgen=YPGen(args)
if args.about:
print(program_version_message)
print(f"see {Version.doc_url}")
webbrowser.open(Version.doc_url)
else:
app=CmsApp(version=Version, title="pyWikiCMS",args=args)
url=f"http://{args.host}:{args.port}"
if args.browse:
webbrowser.open(url)
if args.serve:
app.start(host=args.host, port=args.port,debug=args.debug)
pass
pass
except KeyboardInterrupt:
### handle keyboard interrupt ###
return 1
except Exception as e:
if DEBUG:
raise(e)
indent = len(program_name) * " "
sys.stderr.write(program_name + ": " + repr(e) + "\n")
sys.stderr.write(indent + " for help use --help")
if args.debug:
print(traceback.format_exc())
return 2
def main(argv:list=None):
"""
main call
"""
cmd=CmsMain()
exit_code=cmd.cmd_main(argv)
return exit_code

DEBUG = 1
DEBUG = 0
if __name__ == "__main__":
if DEBUG:
sys.argv.append("-d")
Expand Down
19 changes: 15 additions & 4 deletions frontend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import socket
import datetime
from flask import render_template
from lodstorage.jsonable import JSONAble
from pathlib import Path
from frontend.wikicms import Frontend
Expand All @@ -26,6 +25,7 @@ def __init__(self,debug=False):
Args:
storePath(str): the path to load my configuration from (if any)
'''
self.storage_secret=None
self.frontendConfigs=None
self.logo="https://wiki.bitplan.com/images/wiki/6/63/Profiwikiicon.png"
self.purpose=""
Expand Down Expand Up @@ -250,10 +250,21 @@ def checkApacheConfiguration(self,conf,status='enabled')->str:
stateSymbol=self.stateSymbol(confExists)
return stateSymbol

def render(self):
def asHtml(self)->str:
'''
render me
render me as HTML code
'''
html=render_template('server.html',server=self)
server=self
logo_html=""
if server.logo is not None:
logo_html=f"""<td><img src='{server.logo }' alt='{server.name} logo' height=150></td>"""
html=f"""<table>
<tr>
<td><img src='{server.getPlatformLogo()}' alt='{server.platform} logo' height=150></td>
{logo_html}
<td>Welcome to {server.name } ({ server.ip }) { server.purpose }<td>
</tr>
</table>
"""
return html

2 changes: 1 addition & 1 deletion frontend/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Version(object):
description='pyWikiCMS: python implementation of a Mediawiki based Content Management System'
version=frontend.__version__
date = '2022-11-16'
updated = '2023-02-25'
updated = '2023-10-30'
authors='Wolfgang Fahl'
doc_url="http://wiki.bitplan.com/index.php/PyWikiCMS"
chat_url="https://github.com/BITPlan/pyWikiCMS/discussions"
Expand Down
Loading

0 comments on commit fef8c60

Please sign in to comment.