Skip to content

Commit 1dab2f0

Browse files
authored
Refactor (#193)
* added indentation to saved json * black format and isort the whole database for consistency * added black to requirements-dev * added todo * added .vscode to .gitignore * updated requirements * Logging (#2) * rename * fixed crash when value is None * improved exception handling * added prototyped crash_reporting * fixed exception handling * added TimeoutError Handling * Py qt6 (#3) * start migration to PyQt6 * Migrated enums and exec_ * updated TODO * started updating tests * Reordered and packaged codebase (#4) * changed file structure * deleted unused files and packaged the application * updated TODO * removed build/ * removed build files * removed publish script * updated gitignore * moved peracruda * bumped version * added logdir to gitignore * pinned PyQt to specific version * polished logger and config * move the exception handler to its own module * fix excepthook import * added comment * isort * fixed config * started cleaning up gui code * cleaned up some gui code * updated pytest-qt * fixed test_pretty_print * formatting * remove deprecated methods * :/ * extracted widgets * removed old tests * fix for `extracted widgets` commit * fixed requirements and patched for 3.9 * fixed default theme * updated deps * bump version * fixed arg parsing * possible fix for crash on copy on some devices * bump patch * moved logdir * version bump (patch) * force conf in '~/.config/peracotta' * bump version (patch) * fix automatic features update * fixed brand parsing for some manufacturers * fix features saving * moved logs to .config/peracotta * Toml config (#5) * added utility function * configs are now loaded in order of priority from local env, .env file in ~/.config/peracotta, config.toml in ~/.config/peracotta, default config.toml (in the package's directory) * updated TODO * Automatic crash report (#6) * added automatic crash report * silently pass if there's any exception during reporting * renamed requirements to requirements-dev * merged with toml_config * removed .env from package since it's no longer default * added pre-commit hooks * pre-run commit hook * Docs (#7) * added requirements * added module description * naming conventions * added isort to pre-commit * extended documentation and added log when erroring during crash report * removed isort (conflicting with black) * format * restore QT function names * updated gitignore * revert to PyQt5 for i386 compatibility * create parent dirs if they don't exist * deprecate python 3.6, target python 3.9 * added documentation * improved compatibility with old versions of peracotta and miso * updated black version * fix: pyqt5 and features.json not found * bump version * update requirements * added indentation to saved json * black format and isort the whole database for consistency * added black to requirements-dev * added todo * added .vscode to .gitignore * updated requirements * Logging (#2) * rename * fixed crash when value is None * improved exception handling * added prototyped crash_reporting * fixed exception handling * added TimeoutError Handling * Py qt6 (#3) * start migration to PyQt6 * Migrated enums and exec_ * updated TODO * started updating tests * Reordered and packaged codebase (#4) * changed file structure * deleted unused files and packaged the application * updated TODO * Reordered and packaged codebase (#4) * changed file structure * deleted unused files and packaged the application * updated TODO * removed build/ * removed build files * removed publish script * updated gitignore * moved peracruda * bumped version * added logdir to gitignore * pinned PyQt to specific version * polished logger and config * move the exception handler to its own module * fix excepthook import * added comment * isort * fixed config * started cleaning up gui code * cleaned up some gui code * updated pytest-qt * fixed test_pretty_print * formatting * remove deprecated methods * :/ * extracted widgets * removed old tests * fix for `extracted widgets` commit * fixed requirements and patched for 3.9 * fixed default theme * updated deps * bump version * fixed arg parsing * possible fix for crash on copy on some devices * bump patch * moved logdir * version bump (patch) * force conf in '~/.config/peracotta' * bump version (patch) * fix automatic features update * fixed brand parsing for some manufacturers * fix features saving * moved logs to .config/peracotta * Toml config (#5) * added utility function * configs are now loaded in order of priority from local env, .env file in ~/.config/peracotta, config.toml in ~/.config/peracotta, default config.toml (in the package's directory) * updated TODO * Automatic crash report (#6) * added automatic crash report * silently pass if there's any exception during reporting * renamed requirements to requirements-dev * merged with toml_config * removed .env from package since it's no longer default * added pre-commit hooks * pre-run commit hook * Docs (#7) * added requirements * added module description * naming conventions * added isort to pre-commit * extended documentation and added log when erroring during crash report * removed isort (conflicting with black) * format * restore QT function names * updated gitignore * revert to PyQt5 for i386 compatibility * create parent dirs if they don't exist * deprecate python 3.6, target python 3.9 * added documentation * improved compatibility with old versions of peracotta and miso * updated black version * fix: pyqt5 and features.json not found * bump version * update requirements * update gitignore * fix pyproject.toml * update requirements * fix: calling ./peracruda called pip install * gitignore * fix: requirements should now target 3.8 * fix:error when right clicking an item * add dev requirements * Delete .direnv directory * Delete .envrc * Delete flake.lock * Delete build/lib/peracotta directory * Delete peracotta.egg-info directory * unpin dbus-python * update pre-commit and fix flake * update CI * update lint action * added pytest dep * add pytest options * remove dbus-python from requirements * fix: changed src/ directory structure * fix: python 3.8 compatibility * fixes for 3.8 * bump version * added build and twine to dev requirements * add automatic crash reporting * add menu action to open logs dir * fix default conf not being used * fix error reporting * bump version * fix: exclude 0-bytes devices * bump * ignore non-hdd block devices * add log to item removal * fix: all HDDs skipping * fix: rare drive not being recognized * feat: added udevadm for finding RAM more reliably and fixed a bunch of RAM issues * format * feat: added CI for publishing on pypi * fix: polish exception reporting * fix: polish exception reporting * imp: log before popup * fix: exc_value can only be read once * fix: parse_udevadm shits itself when serial number is a non-hex string * amend log order doesn't work if not like this * add guard for udevadm errors * improved logging * impr: remove unused imports * fix: fixed peracruda * fixed existing tests * fix: requirements * fix:CI
1 parent 6cf8d80 commit 1dab2f0

File tree

258 files changed

+8735
-8466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+8735
-8466
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export TARALLO_TOKEN=yoLeCHmEhNNseN0BlG0s3A:ksfPYziGg7ebj0goT0Zc7pbmQEIYvZpRTIkw
33
export TARALLO_FEATURES_AUTO_DOWNLOAD=1
44
export GENERATE_FILES_USE_SUDO=1
55
export GENERATE_FILES_ASK_SUDO_PASSWORD=1
6+
export AUTOMATIC_REPORT_ERRORS=1
7+
export REPORT_URL=http://127.0.0.1:9999

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/lint.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212

1313
steps:
1414
- name: Check out Git repository
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616

1717
- name: Set up Python
18-
uses: actions/setup-python@v1
18+
uses: actions/setup-python@v5
1919
with:
2020
python-version: 3.8
2121

2222
- name: Install Python dependencies
23-
run: pip install black flake8
24-
23+
run: pip install black
24+
2525
- name: Run linters
26-
uses: wearerequired/lint-action@v1
26+
uses: wearerequired/lint-action@v2
2727
with:
2828
black: true
2929
flake8: false

.github/workflows/publish.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Build distribution 📦
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
19+
- name: Install pypa/build
20+
run: >-
21+
python3 -m
22+
pip install
23+
build
24+
--user
25+
- name: Build a binary wheel and a source tarball
26+
run: python3 -m build
27+
- name: Store the distribution packages
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: python-package-distributions
31+
path: dist/
32+
33+
publish-to-pypi:
34+
name: >-
35+
Publish Python 🐍 distribution 📦 to PyPI
36+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
37+
needs:
38+
- build
39+
runs-on: ubuntu-latest
40+
environment:
41+
name: pypi
42+
url: https://pypi.org/p/peracotta # Replace <package-name> with your PyPI project name
43+
permissions:
44+
id-token: write # IMPORTANT: mandatory for trusted publishing
45+
steps:
46+
- name: Download all the dists
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: python-package-distributions
50+
path: dist/
51+
- name: Publish distribution 📦 to PyPI
52+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/python-tests.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,58 @@ on:
99
jobs:
1010

1111
run-tests:
12-
13-
runs-on: ubuntu-latest
1412
strategy:
1513
matrix:
16-
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
14+
os: [ubuntu-latest]
15+
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
16+
runs-on: ${{ matrix.os }}
1717

1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
2020

2121
- name: Set up Python version ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
architecture: x64
26-
26+
2727
- name: Install dev dependencies
28-
run: pip install -r requirements-dev.txt
28+
run: |
29+
sudo apt install build-essential libpython3-dev libdbus-1-dev
30+
pip install -r requirements-dev.txt
2931
30-
- name: Install dataclasses on Python 3.6
31-
run: pip install dataclasses
32-
if: matrix.python-version == '3.6'
32+
#- name: Install dev dependencies
33+
# run: |
34+
# # Add Docker's official GPG key:
35+
# sudo apt-get update
36+
# sudo apt-get install ca-certificates curl
37+
# sudo install -m 0755 -d /etc/apt/keyrings
38+
# sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
39+
# sudo chmod a+r /etc/apt/keyrings/docker.asc
3340

34-
- name: Set up local development Tarallo instance
35-
run: |
36-
git clone https://github.com/weee-open/tarallo
37-
cd tarallo || exit
38-
make ci
39-
make up
40-
cd - &> /dev/null
41-
42-
- name: Create test .env file to access local Tarallo instance
43-
run: |
44-
echo "export TARALLO_URL=http://127.0.0.1:8080" >> .env
45-
echo "export TARALLO_TOKEN=yoLeCHmEhNNseN0BlG0s3A:ksfPYziGg7ebj0goT0Zc7pbmQEIYvZpRTIkwuscAM_k" >> .env
41+
# # Add the repository to Apt sources:
42+
# echo \
43+
# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
44+
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
45+
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
46+
# sudo apt-get update
47+
# sudo apt install build-essential libpython3-dev libdbus-1-dev docker-ce docker-ce-cli containerd.io docker-compose-plugin
48+
# pip install -r requirements-dev.txt
49+
50+
#- name: Set up local development Tarallo instance
51+
# run: |
52+
# git clone https://github.com/weee-open/tarallo
53+
# cd tarallo || exit
54+
# docker-compose() { docker compose "$@"; } # tarallo's makefile has the older deprecated docker-compose command
55+
# export -f docker-compose
56+
# make ci
57+
# make up
58+
# cd - &> /dev/null
4659

47-
# - name: Run tests
48-
# uses: GabrielBB/xvfb-action@v1
49-
# with:
50-
# run: pytest -vv tests
60+
#- name: Run tests
61+
# uses: coactions/setup-xvfb@v1
62+
# with:
63+
# run: pytest -vv tests
5164

5265
- name: Run tests
5366
run: pytest -vv tests -m "not gui"

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__pycache__/
22
.idea/
33
venv/
4+
.venv/
45
dev_dmdi_files/
56
.DS_Store
67
__pycache__/
@@ -18,3 +19,12 @@ pera*.bin
1819
pera*.build
1920
pera*.dist
2021
pera*.onefile-build
22+
.vscode/
23+
publish.sh
24+
dist/
25+
build/
26+
*.egg-info
27+
logs
28+
*/*.log
29+
*.egg-info
30+
.direnv/

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# .pre-commit-config.yaml
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.6.0
5+
hooks:
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- repo: https://github.com/psf/black
10+
rev: 24.4.1
11+
hooks:
12+
- id: black
13+
language_version: python3.9
14+
args:
15+
- --target-version=py39

Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

Installing.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Launch `peracotta`: that is the GUI that allows you to gather data, parse it and
2020

2121
![Main peracotta window, displaying a motherboard](docs/peracotta_mobo_screenshot.png)
2222

23-
Options can be configured in the left pane, then after Generate is pressed data is displayed in the right pane.
23+
Options can be configured in the left pane, then after Generate is pressed data is displayed in the right pane.
2424
Some basic editing is possible (add and remove items and features, edit feature values). The result can be saved as a JSON or uploaded directly to tarallo.
2525

2626
### You are using a slow pc or you don't have PyQt installed
2727

28-
Launch `peracruda` from the terminal: this a script that gathers and parses data, however it offers no editing capabilities.
28+
Launch `peracruda` from the terminal: this a script that gathers and parses data, however it offers no editing capabilities.
2929
At the end, you can save data as a JSON or upload it to tarallo directly.
3030

3131
The saved JSON can be uploaded to tarallo or imported from the `peracotta` GUI e.g. on another computer, to review and edit it before upload.
@@ -39,20 +39,8 @@ You can load those files in `peracruda` (`-f` option) or `peracotta` (`File > Lo
3939
## How to install and run
4040

4141
```bash
42-
# Clone this repo
43-
git clone https://github.com/weee-open/peracotta
44-
45-
# Make a virtual environment and activate it
46-
cd peracotta
47-
python3 -m venv venv
48-
source venv/bin/activate
49-
50-
# Install the requirements
51-
pip install -r requirements.txt
52-
53-
# Copy the example .env file and edit it to your liking
54-
cp .env.example .env
55-
nano .env
42+
sudo apt install libxcb-cursor-dev
43+
pip install peracotta
5644
```
5745

5846
### Privileges and sudo
@@ -82,28 +70,21 @@ Add this to your .env:
8270
```bash
8371
export GENERATE_FILES_USE_SUDO=0
8472
```
85-
86-
#### pkexec
87-
88-
You can run `polkit.py` just once: it will configure pkexec to run generate_files.sh with root privileges. However, the configuration contains hardcoded absolute paths to your generate_files.sh script, so you cannot move it.
89-
90-
Additionally, if anyone edits generate_files.sh, it will be executed with root privileges. Unless you move it to /sbin and change its owner to root:root, this is also not very secure.
91-
9273
#### Manually
9374

9475
Run `sudo generate_files.sh /path/to/output/directory` then load the raw files in peracruda or peracotta. This is probably the safest way, considering that generate_files.sh is pretty short so you can inspect it before running. Everything else will work as usual and won't require root permissions.
9576

9677
### How to develop
9778

9879
Same as before, until the `pip install` part. Just install `requirements-dev.txt` instead:
99-
`pip install -r requirements-dev.txt`
80+
`pip install -r requirements-dev.txt`
10081

10182
This will allow you to run tests: `pytest -vv tests`
10283

10384
Some markers are also available, e.g. you can run `pytest -m gui` to just test the gui, or `pytest -m 'not gui'` to test everything else. See `pytest.ini` for a list of markers.
10485

105-
If requirements change:
106-
- install the correct version of the requirements (e.g. a new library or a new version of an already installed library)
86+
If requirements change:
87+
- install the correct version of the requirements (e.g. a new library or a new version of an already installed library)
10788
- with the virtual environment activated, run `pip freeze > requirements-dev.txt` and *manually* edit the file (add the `-r requirements.txt` line and remove non-dev requirements)
10889

10990
If you can't run generate_files.sh because you don't have access to `sudo`, such as on our development VM, you can look at `tests/source_files` for examples.
@@ -118,7 +99,7 @@ You can find the usage below, but keep in mind that the three most important arg
11899

119100
- the path for files generation: if none given, it will default to a tmp directory, and if it exists, you will be asked whether you want to overwrite it
120101
- `-g | -c | -b`: one of these tells the script where the GPU (or graphics card if it's not integrated) is located. If none of them is given, a menu with the same choices will appear during the execution.
121-
- `--code CODE` and `--owner OWNER`: these two parameters are used to add some more information directly into the output json file.
102+
- `--code CODE` and `--owner OWNER`: these two parameters are used to add some more information directly into the output json file.
122103
- `-f` to read files from the path instead of calling `generate_files.sh` again.
123104

124105
```
@@ -150,12 +131,12 @@ Just need to run it with `./peracotta` or from your file manager. It does everyt
150131

151132
### generate_files.sh
152133

153-
This will create some txt files with data related to the computer, that will be parsed by launching
154-
`peracruda` with -f/--files argument. The hard work is powered by the many `read_X.py` scripts, which are the actual
134+
This will create some txt files with data related to the computer, that will be parsed by launching
135+
`peracruda` with -f/--files argument. The hard work is powered by the many `read_X.py` scripts, which are the actual
155136
parsers.
156137

157-
Install dependencies on Debian-based distributions (Debian, Ubuntu, Xubuntu, etc):
158-
`sudo apt install pciutils i2c-tools mesa-utils smartmontools dmidecode`
138+
Install dependencies on Debian-based distributions (Debian, Ubuntu, Xubuntu, etc):
139+
`sudo apt install pciutils i2c-tools mesa-utils smartmontools dmidecode`
159140
These are the actual programs that generate the files that we parse.
160141

161142
### parsers

TODO.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- [x] Known and non-fatal errors shouldn't crash the program.
2+
- [ ] Known and fatal errors should crash the program
3+
- [ ] Handle in-thread exceptions
4+
- [ ] Possibly use better sudo management (especially for devices with fingerprint)
5+
- [ ] Migrate to PySide6? Seems to have a better suppot for Nuitka
6+
- [ ] github Actions to auto-publish to PyPi
7+
- [ ] Check peracruda
8+
- [x] Add TOML config
9+
- [x] Fix logs
10+
- [ ] Properly credit Authors and Mantainers in README and pyproject
11+
- [x] Add crash feedback
12+
- [ ] Add tests

0 commit comments

Comments
 (0)