-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d524ba
commit 7c2a8a5
Showing
5 changed files
with
260 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.3.5" | ||
__version__ = "0.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters