Skip to content

Commit

Permalink
Refactor (#193)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
parmigggiana authored Oct 1, 2024
1 parent 6cf8d80 commit 1dab2f0
Show file tree
Hide file tree
Showing 258 changed files with 8,735 additions and 8,466 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export TARALLO_TOKEN=yoLeCHmEhNNseN0BlG0s3A:ksfPYziGg7ebj0goT0Zc7pbmQEIYvZpRTIkw
export TARALLO_FEATURES_AUTO_DOWNLOAD=1
export GENERATE_FILES_USE_SUDO=1
export GENERATE_FILES_ASK_SUDO_PASSWORD=1
export AUTOMATIC_REPORT_ERRORS=1
export REPORT_URL=http://127.0.0.1:9999
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Install Python dependencies
run: pip install black flake8
run: pip install black

- name: Run linters
uses: wearerequired/lint-action@v1
uses: wearerequired/lint-action@v2
with:
black: true
flake8: false
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/peracotta # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
65 changes: 39 additions & 26 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,58 @@ on:
jobs:

run-tests:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
os: [ubuntu-latest]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install dev dependencies
run: pip install -r requirements-dev.txt
run: |
sudo apt install build-essential libpython3-dev libdbus-1-dev
pip install -r requirements-dev.txt
- name: Install dataclasses on Python 3.6
run: pip install dataclasses
if: matrix.python-version == '3.6'
#- name: Install dev dependencies
# run: |
# # Add Docker's official GPG key:
# sudo apt-get update
# sudo apt-get install ca-certificates curl
# sudo install -m 0755 -d /etc/apt/keyrings
# sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
# sudo chmod a+r /etc/apt/keyrings/docker.asc

- name: Set up local development Tarallo instance
run: |
git clone https://github.com/weee-open/tarallo
cd tarallo || exit
make ci
make up
cd - &> /dev/null
- name: Create test .env file to access local Tarallo instance
run: |
echo "export TARALLO_URL=http://127.0.0.1:8080" >> .env
echo "export TARALLO_TOKEN=yoLeCHmEhNNseN0BlG0s3A:ksfPYziGg7ebj0goT0Zc7pbmQEIYvZpRTIkwuscAM_k" >> .env
# # Add the repository to Apt sources:
# echo \
# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# sudo apt-get update
# sudo apt install build-essential libpython3-dev libdbus-1-dev docker-ce docker-ce-cli containerd.io docker-compose-plugin
# pip install -r requirements-dev.txt

#- name: Set up local development Tarallo instance
# run: |
# git clone https://github.com/weee-open/tarallo
# cd tarallo || exit
# docker-compose() { docker compose "$@"; } # tarallo's makefile has the older deprecated docker-compose command
# export -f docker-compose
# make ci
# make up
# cd - &> /dev/null

# - name: Run tests
# uses: GabrielBB/xvfb-action@v1
# with:
# run: pytest -vv tests
#- name: Run tests
# uses: coactions/setup-xvfb@v1
# with:
# run: pytest -vv tests

- name: Run tests
run: pytest -vv tests -m "not gui"
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__pycache__/
.idea/
venv/
.venv/
dev_dmdi_files/
.DS_Store
__pycache__/
Expand All @@ -18,3 +19,12 @@ pera*.bin
pera*.build
pera*.dist
pera*.onefile-build
.vscode/
publish.sh
dist/
build/
*.egg-info
logs
*/*.log
*.egg-info
.direnv/
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.4.1
hooks:
- id: black
language_version: python3.9
args:
- --target-version=py39
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

37 changes: 0 additions & 37 deletions Installing.py

This file was deleted.

17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

43 changes: 12 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Launch `peracotta`: that is the GUI that allows you to gather data, parse it and

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

Options can be configured in the left pane, then after Generate is pressed data is displayed in the right pane.
Options can be configured in the left pane, then after Generate is pressed data is displayed in the right pane.
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.

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

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

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.
Expand All @@ -39,20 +39,8 @@ You can load those files in `peracruda` (`-f` option) or `peracotta` (`File > Lo
## How to install and run

```bash
# Clone this repo
git clone https://github.com/weee-open/peracotta

# Make a virtual environment and activate it
cd peracotta
python3 -m venv venv
source venv/bin/activate

# Install the requirements
pip install -r requirements.txt

# Copy the example .env file and edit it to your liking
cp .env.example .env
nano .env
sudo apt install libxcb-cursor-dev
pip install peracotta
```

### Privileges and sudo
Expand Down Expand Up @@ -82,28 +70,21 @@ Add this to your .env:
```bash
export GENERATE_FILES_USE_SUDO=0
```

#### pkexec

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.

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.

#### Manually

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.

### How to develop

Same as before, until the `pip install` part. Just install `requirements-dev.txt` instead:
`pip install -r requirements-dev.txt`
`pip install -r requirements-dev.txt`

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

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.

If requirements change:
- install the correct version of the requirements (e.g. a new library or a new version of an already installed library)
If requirements change:
- install the correct version of the requirements (e.g. a new library or a new version of an already installed library)
- 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)

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.
Expand All @@ -118,7 +99,7 @@ You can find the usage below, but keep in mind that the three most important arg

- 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
- `-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.
- `--code CODE` and `--owner OWNER`: these two parameters are used to add some more information directly into the output json file.
- `--code CODE` and `--owner OWNER`: these two parameters are used to add some more information directly into the output json file.
- `-f` to read files from the path instead of calling `generate_files.sh` again.

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

### generate_files.sh

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

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

### parsers
Expand Down
12 changes: 12 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- [x] Known and non-fatal errors shouldn't crash the program.
- [ ] Known and fatal errors should crash the program
- [ ] Handle in-thread exceptions
- [ ] Possibly use better sudo management (especially for devices with fingerprint)
- [ ] Migrate to PySide6? Seems to have a better suppot for Nuitka
- [ ] github Actions to auto-publish to PyPi
- [ ] Check peracruda
- [x] Add TOML config
- [x] Fix logs
- [ ] Properly credit Authors and Mantainers in README and pyproject
- [x] Add crash feedback
- [ ] Add tests
Loading

0 comments on commit 1dab2f0

Please sign in to comment.