Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/dashboard/dashboard.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from pathlib import PosixPath | from pathlib import Path | ||||
from ..model import Tree | from ..model import Tree | ||||
import plotly.graph_objects as go | import plotly.graph_objects as go | ||||
import dash | import dash | ||||
import dash_core_components as dcc | import dash_core_components as dcc | ||||
import dash_html_components as html | import dash_html_components as html | ||||
import dash_bootstrap_components as dbc | import dash_bootstrap_components as dbc | ||||
from dash.dependencies import Input, Output | from dash.dependencies import Input, Output | ||||
def generate_table_body(dir_path: PosixPath, source: Tree): | def generate_table_body(dir_path: Path, source: Tree): | ||||
""" | """ | ||||
Generate the data_table from the path taken from the chart. | Generate the data_table from the path taken from the chart. | ||||
For each file builds the html table rows showing the known status, a local link to | For each file builds the html table rows showing the known status, a local link to | ||||
the file and the relative SoftWare Heritage persistent IDentifier (SWHID). | the file and the relative SoftWare Heritage persistent IDentifier (SWHID). | ||||
""" | """ | ||||
data = [] | data = [] | ||||
for file_info in source.getFilesFromDir(dir_path): | for file_info in source.getFilesFromDir(dir_path): | ||||
for file_path, attr in file_info.items(): | for file_path, attr in file_info.items(): | ||||
file_path = PosixPath(file_path) | file_path = Path(file_path) | ||||
file_name = file_path.parts[len(file_path.parts) - 1] | file_name = file_path.parts[len(file_path.parts) - 1] | ||||
data.append( | data.append( | ||||
html.Tr( | html.Tr( | ||||
[ | [ | ||||
html.Td("✔" if attr["known"] else ""), | html.Td("✔" if attr["known"] else ""), | ||||
html.Td( | html.Td( | ||||
html.A(file_name, href="file://" + str(file_path.resolve())) | html.A(file_name, href="file://" + str(file_path.resolve())) | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def update_files_table(click_data): | ||||
update the `files_table` children with the relative files. | update the `files_table` children with the relative files. | ||||
""" | """ | ||||
if click_data is not None: | if click_data is not None: | ||||
raw_path = click_data["points"][0]["label"] | raw_path = click_data["points"][0]["label"] | ||||
full_path = ( | full_path = ( | ||||
source.path.joinpath(raw_path) | source.path.joinpath(raw_path) | ||||
if raw_path != str(source.path) | if raw_path != str(source.path) | ||||
else PosixPath(raw_path) | else Path(raw_path) | ||||
) | ) | ||||
return table_header + generate_table_body(full_path, source), str(full_path) | return table_header + generate_table_body(full_path, source), str(full_path) | ||||
else: | else: | ||||
return "", "" | return "", "" | ||||
app.run_server(debug=True, use_reloader=True) | app.run_server(debug=True, use_reloader=True) |