Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Feb 22, 2024
1 parent 7d524ba commit 7c2a8a5
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ceurws/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.5"
__version__ = "0.4.0"
148 changes: 148 additions & 0 deletions ceurws/ceur_ws_web_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
Created on 2024-02-22
@author: wf
"""
import sys
from ngwidgets.cmd import WebserverCmd
from ceurws.webserver import CeurWsWebServer
from argparse import ArgumentParser
from tabulate import tabulate
from tqdm import tqdm
from dataclasses import asdict

from ceurws.ceur_ws import VolumeManager
from ceurws.namedqueries import NamedQueries
from ceurws.wikidatasync import WikidataSync


class CeurWsCmd(WebserverCmd):
"""
command line handling for CEUR-WS Volume browser
"""

def __init__(self):
"""
constructor
"""
config = CeurWsWebServer.get_config()
WebserverCmd.__init__(self, config, CeurWsWebServer, DEBUG)
pass

def getArgParser(self, description: str, version_msg) -> ArgumentParser:
"""
override the default argparser call
"""
parser = super().getArgParser(description, version_msg)
parser.add_argument(
"-f",
"--force",
action="store_true",
help="force update [default: %(default)s]",
)
parser.add_argument(
"--list",
action="store_true",
help="list all volumes [default: %(default)s]",
)
parser.add_argument(
"-rc",
"--recreate",
action="store_true",
help="recreate caches e.g. volume table",
)
parser.add_argument(
"-den",
"--dblp_endpoint_name",
help="name of dblp endpoint to use %(default)s",
default="qlever-dblp",
)
parser.add_argument(
"-wen",
"--wikidata_endpoint_name",
help="name of wikidata endpoint to use %(default)s",
default="wikidata",
)
parser.add_argument(
"-wdu",
"--wikidata_update",
action="store_true",
help="update tables from wikidata",
)
parser.add_argument(
"-dbu", "--dblp_update", action="store_true", help="update dblp cache"
)
parser.add_argument(
"-nq",
"--namedqueries",
action="store_true",
help="generate named queries [default: %(default)s]",
)
return parser

def handle_args(self)->bool:
"""
handle the command line arguments
"""
args=self.args
if args.namedqueries:
nq = NamedQueries()
yaml = nq.toYaml()
print(yaml)
if args.list:
manager = VolumeManager()
manager.loadFromBackup()
for volume in manager.getList():
print(volume)
if args.recreate:
manager = VolumeManager()
manager.recreate(progress=True)
if args.wikidata_update:
wdsync = WikidataSync.from_args(args)
wdsync.update(withStore=True)
if args.dblp_update:
wdsync = WikidataSync.from_args(args)
endpoint = wdsync.dbpEndpoint
print(f"updating dblp cache from SPARQL endpoint {endpoint.sparql.url}")
# Instantiate the progress bar
pbar = tqdm(total=len(wdsync.dbpEndpoint.cache_functions))
for _step, (cache_name, cache_function) in enumerate(
endpoint.cache_functions.items(), start=1
):
# Call the corresponding function to refresh cache data
cache_function(force_query=args.force)
# Update the progress bar description with the cache name and increment
pbar.set_description(f"{cache_name} updated ...")

# Update the progress bar manually
pbar.update(1) # Increment the progress bar by 1 for each iteration

# Close the progress bar after the loop
pbar.close()
table_data = []
for _step, (cache_name, cache_function) in enumerate(
endpoint.cache_functions.items(), start=1
):
info = endpoint.json_cache_manager.get_cache_info(cache_name)
table_data.append(asdict(info))
table = tabulate(table_data, headers="keys", tablefmt="grid")
print(table)
pass
handled=super().handle_args()
return handled


def main(argv: list = None):
"""
main call
"""
cmd = CeurWsCmd()
exit_code = cmd.cmd_main(argv)
return exit_code


DEBUG = 0
if __name__ == "__main__":
if DEBUG:
sys.argv.append("-d")
sys.exit(main())
7 changes: 4 additions & 3 deletions ceurws/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
@author: wf
"""
import ceurws
from dataclasses import dataclass


@dataclass
class Version(object):
"""
Version handling for VolumeBrowser
Expand All @@ -14,8 +15,8 @@ class Version(object):
name = "CEUR-WS Volume Browser"
version = ceurws.__version__
date = "2022-08-14"
updated = "2024-02-20"
description = ("CEUR-WS Volume browser",)
updated = "2024-02-22"
description = "CEUR-WS Volume browser"

authors = "Tim Holzheim, Wolfgang Fahl"

Expand Down
72 changes: 72 additions & 0 deletions ceurws/webserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'''
Created on 2024-02-22
@author: wf
'''
from ngwidgets.input_webserver import InputWebserver, InputWebSolution
from ngwidgets.webserver import WebserverConfig
from ceurws.version import Version
from nicegui import Client,ui
from ceurws.wikidatasync import WikidataSync

class CeurWsWebServer(InputWebserver):
"""
webserver
"""

@classmethod
def get_config(cls) -> WebserverConfig:
copy_right = "(c)2023-2024 Wolfgang Fahl"
config = WebserverConfig(
copy_right=copy_right,
version=Version(),
default_port=9998,
short_name="spf"
)
server_config = WebserverConfig.get(config)
server_config.solution_class =CeurWsSolution
return server_config

def __init__(self):
"""
constructor
"""
InputWebserver.__init__(self, config=CeurWsWebServer.get_config())

def configure_run(self):
InputWebserver.configure_run(self)
self.wdSync = WikidataSync.from_args(self.args)
self.volume_options=[]
for volume in self.wdSync.vm.getList():
title = f"Vol-{volume.number}:{volume.title}"
self.volume_options.append(title)

class CeurWsSolution(InputWebSolution):
"""
CEUR-WS Volume browser solution
"""
def __init__(self, webserver: CeurWsWebServer, client: Client):
"""
Initialize the solution
Calls the constructor of the base solution
Args:
webserver (CeurWsWebServer): The webserver instance associated with this context.
client (Client): The client instance this context is associated with.
"""
super().__init__(webserver, client) # Call to the superclass constructor

async def home(self):
"""
home page selection
"""

def show():
try:
with ui.row():
self.volume_select=ui.select(options=self.webserver.volume_options, with_input=True)
except Exception as ex:
self.handle_exception(ex)

await self.setup_content_div(show)
68 changes: 35 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,42 @@ maintainers = [
readme = "README.md"
license= "Apache-2.0"
dependencies = [
# https://pypi.org/project/fastapi/
# pin fastapi, httpcore and starlette as long as we use justpy
'fastapi==0.95.0',
'starlette==0.26.1',
'httpcore==0.15.0',
# https://pypi.org/project/geograpy3/
'geograpy3>=0.2.7',
#https://github.com/martinblech/xmltodict
'xmltodict>=0.13.0',
# https://pypi.org/project/pylodstorage/
'pylodstorage>=0.4.11',
# https://github.com/pyparsing/pyparsing
'pyparsing>=3.0.9',
# https://pypi.org/project/beautifulsoup4/
'BeautifulSoup4>=4.11.2',
# https://pypi.org/project/lxml/
'lxml>=4.9.2',
# pyjustpywidgets
# https://pypi.org/project/pyJustpyWidgets/
'pyJustpyWidgets>=0.1.13',
# https://pypi.org/project/justpy/
'justpy>=0.13.0',
# https://pypi.org/project/pyGenericSpreadSheet/
'pyGenericSpreadSheet>=0.2.4',
# https://pypi.org/project/py-3rdparty-mediawiki/
'py-3rdparty-mediawiki>=0.9.3',
# https://github.com/tqdm/tqdm
'tqdm',
'orjson>=3.8.9',
# https://pypi.org/project/neo4j/
'neo4j'
# https://pypi.org/project/fastapi/
# pin fastapi, httpcore and starlette as long as we use justpy
# 'fastapi==0.95.0',
# 'starlette==0.26.1',
# 'httpcore==0.15.0',
# https://pypi.org/project/geograpy3/
'geograpy3>=0.2.7',
#https://github.com/martinblech/xmltodict
'xmltodict>=0.13.0',
# https://pypi.org/project/pylodstorage/
'pylodstorage>=0.4.11',
# https://github.com/pyparsing/pyparsing
'pyparsing>=3.0.9',
# https://pypi.org/project/beautifulsoup4/
'BeautifulSoup4>=4.11.2',
# https://pypi.org/project/lxml/
'lxml>=4.9.2',
# pyjustpywidgets
# https://pypi.org/project/pyJustpyWidgets/
# 'pyJustpyWidgets>=0.1.13',
# https://pypi.org/project/justpy/
# 'justpy>=0.13.0',
# https://pypi.org/project/pyGenericSpreadSheet/
'pyGenericSpreadSheet>=0.2.4',
# https://pypi.org/project/py-3rdparty-mediawiki/
'py-3rdparty-mediawiki>=0.9.3',
# https://github.com/tqdm/tqdm
'tqdm',
'orjson>=3.8.9',
# https://pypi.org/project/neo4j/
'neo4j',
# https://github.com/WolfgangFahl/nicegui_widgets
'ngwidgets>=0.12.5',
]

requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
Expand Down Expand Up @@ -84,4 +86,4 @@ packages = [
"ceurws",
]
[project.scripts]
ceur-ws = "ceurws.ceur_ws_cmd:main"
ceur-ws = "ceurws.ceur_ws_web_cmd:main"

0 comments on commit 7c2a8a5

Please sign in to comment.