Skip to content

Commit

Permalink
Software Architecture major rework (#41)
Browse files Browse the repository at this point in the history
* Moved constants and logo ascii art out of the main file
* Moved Configuration class to separate file
* Moved Output class to a separate file
* Moved hostname class definition to it's own separate file
* Moved Model class definition to it's own file
* Moved Kernel class to its own file
* Moved uptime class definition to it's own file
* Moved Disk class definition to its own file
* Moved RAM class definition to it's own file
* Moved CPU class definition to it's own file
* Moved LanIp class definition to it's own file
* Moved WanIp class definition to a separate file
* Moved Packages class definition to separate file
* Moved User class definition to its own file
* Moved entry class definitions to their own directory
* Moved GPU entry class definition to a separate file
* Moved temperature entry class definition to a separate file
* Moved terminal entry class definition to separate file
* Moved shell entry class definition to separate file
* Rewrited the `LanIp` module to handle more cases and optimizations
* Moved window manager and desktop environment class definitions to separate files
* Moved distro class definition to separate file
* Removed direct use of COLOR_DICT in disk.py and ram.py
* Moved unit tests and modified import paths
* Moved {DE,WM}_DICT constants to their respective modules
* Made `Configuration` & `Processes` (new class) act as singletons
* Set the `Configuration` internal `config` dictionary to "private" attribute

+ Now relies on a `.pylintrc` file for Pylint (now almost fully-compliant)
+ Fixed typos
+ Added another dependency on `netifaces`, but this should remove the assumption about tools available in the user's environment
+ The project may now be run as a Python module
+ Marked Python 3.8 as supported for SetupTools
+ Added instructions (and tests) to build a standalone version of Archey
+ Adds @lannuttia to COPYRIGHT (initiator of the major rework)

- Removed the dependency to `net-tools`


Co-authored-by: Samuel FORESTIER <dev@samuel.domains>
  • Loading branch information
2 people authored and HorlogeSkynet committed Jul 22, 2019
1 parent d104613 commit 4dcf479
Show file tree
Hide file tree
Showing 79 changed files with 2,493 additions and 1,960 deletions.
15 changes: 15 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[MASTER]
# Required hook as we use absolute imports within the code.
init-hook='import sys; sys.path.append("archey/")'

# C sources of the `netifaces` module won't be available.
# Let's ignore it during linting please.
extension-pkg-whitelist=netifaces

# Automatically detects the number of CPU available to use.
jobs=0


[DESIGN]
# For entries classes, we only use the `__init__` magic method.
min-public-methods=0
28 changes: 24 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
dist: xenial
language: python
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7-dev"
#- "3.8-dev"

install:
# Archey package installation (and dependencies).
- pip3 install .
- pip3 install pylint

# Pylint, Stickytape and PyInstaller external dependencies (see below).
- pip3 install pylint stickytape pyinstaller

script:
# Simple execution.
- python3 -m archey

# Tests suite.
- python3 setup.py test
- python3 archey/archey.py
- pylint archey/ --jobs=2 --disable=missing-docstring,too-few-public-methods,too-many-lines
- pylint test/ --jobs=2 --disable=missing-docstring,too-few-public-methods,unused-argument,protected-access,no-value-for-parameter
- python3 -m unittest

# Lint all the things !
- pylint archey/

# Build a standalone script from sources (Stickytape).
- stickytape --add-python-path . --output-file dist/archey archey/__main__.py
- python3 dist/archey

# Build a standalone script from sources (PyInstaller).
- pyinstaller --distpath dist --specpath dist --name archey --onefile archey/__main__.py
- ./dist/archey
1 change: 1 addition & 0 deletions COPYRIGHT.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ See <http://www.gnu.org/licenses/gpl.txt> for the full license text.
* Workaround for Tinkerboard Linux builds by @thisforeda <thisforeda@live.cn>
* Windows Subsystem Linux file-systems support by @Naragato <development@simonbalarabe.com>
* `lsb-release` dropping support guidance by Eli Schwartz <eschwartz93@gmail.com>
* Major software architecture rework by @lannuttia <lannuttia@gmail.com>

Currently maintained by Samuel Forestier <dev@samuel.domains>

Expand Down
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ The answer is [here](https://blog.samuel.domains/archey4).

* `python3`
* `python3-distro` (`python-distro` on Arch Linux)
* `python3-netifaces` (`python-netifaces` on Arch Linux)
* `procps` (potentially `procps-ng`)

### Highly recommended packages

| Environments | Packages | Reasons | Notes |
| :----------- | :--------: | :-----------------------------------: | :---: |
| All | `dnsutils` or `bind-tools` | **WAN_IP** would be detected faster | Would provide `dig` |
| All | `net-tools` | **LAN_IP** would be detected faster | Would provide `hostname` |
| Graphical | `pciutils` or `pciutils-ng` | **GPU** wouldn't be detected without it | Would provide `lspci` |
| Graphical | `wmctrl` | **WindowManager** would be more accurate | φ |
| Virtual | `virt-what` and `dmidecode` | **Model** would contain details about the hypervisor | `archey` would have to be run as **root** |
Expand Down Expand Up @@ -109,8 +109,7 @@ $ sudo pip3 uninstall archey4
# _________________________________________

# But if you don't have PIP, no worries :
$ sudo cp archey/archey.py /usr/local/bin/archey
$ sudo chmod +x /usr/local/bin/archey
$ sudo python3 setup.py install
# _______________________________________

### Step 3 (Optional) : Configuration files
Expand All @@ -123,6 +122,25 @@ $ sudo cp archey/config.json /etc/archey4/config.json
$ mkdir ~/.config/archey4
$ cp archey/config.json ~/.config/archey4/config.json
# _____________________________

### Step 4 (Optional) : I want a standalone script, as before !

# You can go through StickyTape for this :
$ sudo pip3 install stickytape
$ stickytape --add-python-path . --output-file dist/archey archey/__main__.py
$ python3 dist/archey
# ________________________________________

# You can either use PyInstaller :
$ sudo pip3 install pyinstaller
$ pyinstaller --distpath dist --specpath dist --name archey --onefile archey/__main__.py
$ ./dist/archey
# ________________________________

# You can now move this script anywhere, as before :
$ chmod +x dist/archey
$ sudo mv dist/archey /usr/local/bin/
# __________________________________________________
```

## Usage
Expand All @@ -131,10 +149,10 @@ $ cp archey/config.json ~/.config/archey4/config.json
$ archey
```

or if you only want to try this out :
or if you only want to try this out (for instance, from source) :

```shell
$ python3 archey/archey.py
$ python3 -m archey
```

## Configuration (optional)
Expand Down Expand Up @@ -198,7 +216,7 @@ Tests are now available. Here is a short procedure to run them (you'll only need
```shell
$ git clone https://github.com/HorlogeSkynet/archey4.git
$ cd archey4/
# If you have `setuptools` installed
# If you got `setuptools` installed
$ python3 setup.py test
# But if you still don't, no worries !
$ python3 -m unittest
Expand Down
78 changes: 78 additions & 0 deletions archey/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3

"""
Archey main file.
It loads each entry as a different class coming from the `entries` module.
Logos are stored under the `logos` module.
"""

from enum import Enum

from archey.output import Output
from archey.configuration import Configuration
from archey.processes import Processes
from archey.entries.user import User as e_User
from archey.entries.hostname import Hostname as e_Hostname
from archey.entries.model import Model as e_Model
from archey.entries.distro import Distro as e_Distro
from archey.entries.kernel import Kernel as e_Kernel
from archey.entries.uptime import Uptime as e_Uptime
from archey.entries.window_manager import WindowManager as e_WindowManager
from archey.entries.desktop_environment import DesktopEnvironment as e_DesktopEnvironment
from archey.entries.shell import Shell as e_Shell
from archey.entries.terminal import Terminal as e_Terminal
from archey.entries.packages import Packages as e_Packages
from archey.entries.temperature import Temperature as e_Temperature
from archey.entries.cpu import CPU as e_CPU
from archey.entries.gpu import GPU as e_GPU
from archey.entries.ram import RAM as e_RAM
from archey.entries.disk import Disk as e_Disk
from archey.entries.lan_ip import LanIp as e_LanIp
from archey.entries.wan_ip import WanIp as e_WanIp


class Entries(Enum):
"""
An enumeration to store and declare each one of our entries.
The string representation of keys will act as entries names.
Values will be set under the `value` attribute of each obtained objects.
"""
User = e_User
Hostname = e_Hostname
Model = e_Model
Distro = e_Distro
Kernel = e_Kernel
Uptime = e_Uptime
WindowManager = e_WindowManager
DesktopEnvironment = e_DesktopEnvironment
Shell = e_Shell
Terminal = e_Terminal
Packages = e_Packages
Temperature = e_Temperature
CPU = e_CPU
GPU = e_GPU
RAM = e_RAM
Disk = e_Disk
LAN_IP = e_LanIp
WAN_IP = e_WanIp


def main():
"""Simple entry point"""

# `Processes` is a singleton, let's populate the internal list here.
Processes()

# `Configuration` is a singleton, let's populate the internal object here.
configuration = Configuration()

output = Output()
for entry in Entries:
if configuration.get('entries', {}).get(entry.name, True):
output.append(entry.name, entry.value().value)

output.output()


if __name__ == '__main__':
main()
Loading

0 comments on commit 4dcf479

Please sign in to comment.