Skip to content

Commit

Permalink
Add system reports. (bartfeenstra#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra authored Dec 6, 2022
1 parent f0ac277 commit 6d8f620
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 16 deletions.
27 changes: 27 additions & 0 deletions betty/about.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import platform
import sys
from importlib.metadata import distributions
from pathlib import Path
from typing import Dict, Iterator


def version() -> str:
Expand All @@ -7,3 +11,26 @@ def version() -> str:
if release_version == '0.0.0':
return 'development'
return release_version


def _indent_mapping(items: Dict[str, str]) -> str:
max_indentation = max(map(len, items.keys())) + 4
return '\n'.join(map(lambda x: '\n'.join(_indent_mapping_item(x[0], x[1], max_indentation)), items.items()))


def _indent_mapping_item(key: str, value: str, max_indentation: int) -> Iterator[str]:
lines = value.split('\n')
yield f'{key}{" " * (max_indentation - len(key))} {lines[0]}'
for line in lines[1:]:
yield f'{" " * max_indentation} {line}'


def report() -> str:
return _indent_mapping({
'Betty': version(),
'Operating system': platform.platform(),
'Python': sys.version,
'Python packages': _indent_mapping({
x.metadata["Name"]: x.version for x in sorted(distributions(), key=lambda x: x.metadata["Name"].lower())
}),
})
7 changes: 5 additions & 2 deletions betty/assets/betty.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-17 13:48+0000\n"
"POT-Creation-Date: 2022-12-06 18:11+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -602,7 +602,10 @@ msgstr ""
msgid "Remove people, events, places, files, sources, and citations if they have no relationships with any other resources. Enable the Privatizer and Anonymizer as well to make this most effective."
msgstr ""

msgid "Report bugs and request new features"
msgid "Report a bug"
msgstr ""

msgid "Request a new feature"
msgstr ""

msgid "Reset"
Expand Down
7 changes: 5 additions & 2 deletions betty/assets/locale/fr_FR/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-17 13:48+0000\n"
"POT-Creation-Date: 2022-12-06 18:11+0000\n"
"PO-Revision-Date: 2020-11-27 19:49+0100\n"
"Last-Translator: \n"
"Language: fr\n"
Expand Down Expand Up @@ -684,7 +684,10 @@ msgid ""
"Anonymizer as well to make this most effective."
msgstr ""

msgid "Report bugs and request new features"
msgid "Report a bug"
msgstr ""

msgid "Request a new feature"
msgstr ""

msgid "Reset"
Expand Down
9 changes: 6 additions & 3 deletions betty/assets/locale/nl_NL/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-17 13:48+0000\n"
"POT-Creation-Date: 2022-12-06 18:11+0000\n"
"PO-Revision-Date: 2022-04-08 01:58+0100\n"
"Last-Translator: \n"
"Language: nl\n"
Expand Down Expand Up @@ -719,8 +719,11 @@ msgstr ""
"Schakel de Privatiseerder en Anonimiseerder in om dit zo effectief "
"mogelijk te maken."

msgid "Report bugs and request new features"
msgstr "Meld problemen en vraag nieuwe functionaliteit aan"
msgid "Report a bug"
msgstr "Meld een probleem"

msgid "Request a new feature"
msgstr "Vraag nieuwe functionaliteit aan"

msgid "Reset"
msgstr "Reset"
Expand Down
7 changes: 5 additions & 2 deletions betty/assets/locale/uk/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-17 13:48+0000\n"
"POT-Creation-Date: 2022-12-06 18:11+0000\n"
"PO-Revision-Date: 2020-05-02 22:29+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: uk\n"
Expand Down Expand Up @@ -676,7 +676,10 @@ msgid ""
"Anonymizer as well to make this most effective."
msgstr ""

msgid "Report bugs and request new features"
msgid "Report a bug"
msgstr ""

msgid "Request a new feature"
msgstr ""

msgid "Reset"
Expand Down
2 changes: 1 addition & 1 deletion betty/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_command(self, ctx: Context, cmd_name: str):

@click.command(cls=_BettyCommands)
@click.option('--configuration', '-c', 'app', is_eager=True, help='The path to a Betty project configuration file. Defaults to betty.json|yaml|yml in the current working directory. This will make additional commands available.', callback=_init_ctx)
@click.version_option(about.version(), prog_name='Betty')
@click.version_option(about.version(), message=about.report(), prog_name='Betty')
def main(app):
pass

Expand Down
47 changes: 41 additions & 6 deletions betty/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from datetime import datetime
from os import path
from typing import TYPE_CHECKING
from urllib.parse import urlencode

from PyQt6.QtCore import Qt, QCoreApplication
from PyQt6.QtGui import QIcon, QAction
from PyQt6.QtWidgets import QFormLayout, QWidget, QVBoxLayout, QHBoxLayout, QFileDialog, QPushButton

from betty import about, cache
from betty.about import report
from betty.asyncio import sync
from betty.gui import BettyWindow, get_configuration_file_filter
from betty.gui.error import catch_exceptions
Expand Down Expand Up @@ -58,9 +60,13 @@ def __init__(self, *args, **kwargs):

self.help_menu = menu_bar.addMenu('')

self.view_issues_action = QAction(self)
self.view_issues_action.triggered.connect(lambda _: self.view_issues()) # type: ignore
self.help_menu.addAction(self.view_issues_action)
self.report_bug_action = QAction(self)
self.report_bug_action.triggered.connect(lambda _: self.report_bug()) # type: ignore
self.help_menu.addAction(self.report_bug_action)

self.request_feature_action = QAction(self)
self.request_feature_action.triggered.connect(lambda _: self.request_feature()) # type: ignore
self.help_menu.addAction(self.request_feature_action)

self.about_action = QAction(self)
self.about_action.triggered.connect(lambda _: self._about_betty()) # type: ignore
Expand All @@ -79,12 +85,41 @@ def _do_set_translatables(self) -> None:
self.clear_caches_action.setText(_('Clear all caches'))
self.exit_action.setText(_('Exit'))
self.help_menu.setTitle('&' + _('Help'))
self.view_issues_action.setText(_('Report bugs and request new features'))
self.report_bug_action.setText(_('Report a bug'))
self.request_feature_action.setText(_('Request a new feature'))
self.about_action.setText(_('About Betty'))

@catch_exceptions
def view_issues(self) -> None:
webbrowser.open_new_tab('https://github.com/bartfeenstra/betty/issues')
def report_bug(self) -> None:
body = f'''
## Summary
## Steps to reproduce
## Expected behavior
## System report
```
{report()}
```
'''.strip()
webbrowser.open_new_tab('https://github.com/bartfeenstra/betty/issues/new?' + urlencode({
'body': body,
'labels': 'bug',
}))

@catch_exceptions
def request_feature(self) -> None:
body = '''
## Summary
## Expected behavior
'''.strip()
webbrowser.open_new_tab('https://github.com/bartfeenstra/betty/issues/new?' + urlencode({
'body': body,
'labels': 'enhancement',
}))

@catch_exceptions
def _about_betty(self) -> None:
Expand Down

0 comments on commit 6d8f620

Please sign in to comment.