diff --git a/ceurws/__init__.py b/ceurws/__init__.py index a8d4557..6a9beea 100644 --- a/ceurws/__init__.py +++ b/ceurws/__init__.py @@ -1 +1 @@ -__version__ = "0.3.5" +__version__ = "0.4.0" diff --git a/ceurws/ceur_ws_web_cmd.py b/ceurws/ceur_ws_web_cmd.py new file mode 100644 index 0000000..81531c3 --- /dev/null +++ b/ceurws/ceur_ws_web_cmd.py @@ -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()) \ No newline at end of file diff --git a/ceurws/version.py b/ceurws/version.py index 40dc3c3..dd09daf 100644 --- a/ceurws/version.py +++ b/ceurws/version.py @@ -4,8 +4,9 @@ @author: wf """ import ceurws +from dataclasses import dataclass - +@dataclass class Version(object): """ Version handling for VolumeBrowser @@ -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" diff --git a/ceurws/webserver.py b/ceurws/webserver.py new file mode 100644 index 0000000..20f2dfc --- /dev/null +++ b/ceurws/webserver.py @@ -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) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 25e6234..933515b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -84,4 +86,4 @@ packages = [ "ceurws", ] [project.scripts] -ceur-ws = "ceurws.ceur_ws_cmd:main" +ceur-ws = "ceurws.ceur_ws_web_cmd:main"