From ac33c712ccffd7284207f2bc9dfd037b0d5bff33 Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Tue, 31 Dec 2024 21:03:46 -0600 Subject: [PATCH] Re-purpose the project to include all architecture information --- .gitignore | 2 +- README.md | 34 +++++----- {phydisk => pyarchitecture}/__init__.py | 68 ++++---------------- pyarchitecture/disks/__init__.py | 46 +++++++++++++ {phydisk => pyarchitecture/disks}/linux.py | 0 {phydisk => pyarchitecture/disks}/macOS.py | 2 +- {phydisk => pyarchitecture/disks}/models.py | 0 {phydisk => pyarchitecture/disks}/squire.py | 0 {phydisk => pyarchitecture/disks}/windows.py | 2 +- pyproject.toml | 19 ++---- 10 files changed, 85 insertions(+), 88 deletions(-) rename {phydisk => pyarchitecture}/__init__.py (50%) create mode 100644 pyarchitecture/disks/__init__.py rename {phydisk => pyarchitecture/disks}/linux.py (100%) rename {phydisk => pyarchitecture/disks}/macOS.py (99%) rename {phydisk => pyarchitecture/disks}/models.py (100%) rename {phydisk => pyarchitecture/disks}/squire.py (100%) rename {phydisk => pyarchitecture/disks}/windows.py (99%) diff --git a/.gitignore b/.gitignore index 125ccdd..1565c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ venv build temp.py -PhyDisk.egg-info +PyArchitecture.egg-info *.json diff --git a/README.md b/README.md index 602aba3..e316059 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# PhyDisk (Physical Disk) -PhyDisk is an ultra lightweight python module to get all physical disks connected to a host machine. +# PyArchitecture +PyArchitecture is an ultra lightweight python module to get system architecture information. ![Python][label-pyversion] @@ -14,26 +14,26 @@ PhyDisk is an ultra lightweight python module to get all physical disks connecte ## Installation ```shell -pip install PhyDisk +pip install PyArchitecture ``` ## Usage **Initiate - IDE** ```python -import phydisk +import pyarchitecture if __name__ == '__main__': - all_disks = phydisk.get_all_disks() + all_disks = pyarchitecture.disks.get_all_disks() print(all_disks) ``` **Initiate - CLI** ```shell -phydisk print +pyarchitecture disk ``` -> Use `phydisk --help` for usage instructions. +> Use `pyarchitecture --help` for usage instructions. ### Source Commands @@ -84,7 +84,7 @@ pre-commit run --all-files ## Pypi Package [![pypi-module][label-pypi-package]][pypi-repo] -[https://pypi.org/project/PhyDisk/][pypi] +[https://pypi.org/project/PyArchitecture/][pypi] ## License & copyright @@ -92,15 +92,15 @@ pre-commit run --all-files Licensed under the [MIT License][license] -[license]: https://github.com/thevickypedia/PhyDisk/blob/master/LICENSE -[label-pypi-package]: https://img.shields.io/badge/Pypi%20Package-PhyDisk-blue?style=for-the-badge&logo=Python +[license]: https://github.com/thevickypedia/PyArchitecture/blob/master/LICENSE +[label-pypi-package]: https://img.shields.io/badge/Pypi%20Package-PyArchitecture-blue?style=for-the-badge&logo=Python [label-pyversion]: https://img.shields.io/badge/python-3.10%20%7C%203.11-blue [label-platform]: https://img.shields.io/badge/Platform-Linux|macOS|Windows-1f425f.svg -[label-actions-pypi]: https://github.com/thevickypedia/PhyDisk/actions/workflows/python-publish.yaml/badge.svg -[label-pypi]: https://img.shields.io/pypi/v/PhyDisk -[label-pypi-format]: https://img.shields.io/pypi/format/PhyDisk -[label-pypi-status]: https://img.shields.io/pypi/status/PhyDisk -[gha_pypi]: https://github.com/thevickypedia/PhyDisk/actions/workflows/python-publish.yaml -[pypi]: https://pypi.org/project/PhyDisk -[pypi-files]: https://pypi.org/project/PhyDisk/#files +[label-actions-pypi]: https://github.com/thevickypedia/PyArchitecture/actions/workflows/python-publish.yaml/badge.svg +[label-pypi]: https://img.shields.io/pypi/v/PyArchitecture +[label-pypi-format]: https://img.shields.io/pypi/format/PyArchitecture +[label-pypi-status]: https://img.shields.io/pypi/status/PyArchitecture +[gha_pypi]: https://github.com/thevickypedia/PyArchitecture/actions/workflows/python-publish.yaml +[pypi]: https://pypi.org/project/PyArchitecture +[pypi-files]: https://pypi.org/project/PyArchitecture/#files [pypi-repo]: https://packaging.python.org/tutorials/packaging-projects/ diff --git a/phydisk/__init__.py b/pyarchitecture/__init__.py similarity index 50% rename from phydisk/__init__.py rename to pyarchitecture/__init__.py index 25518fc..65bcd32 100644 --- a/phydisk/__init__.py +++ b/pyarchitecture/__init__.py @@ -1,58 +1,14 @@ import json -import logging -import os import sys import time -from typing import Dict, List -from . import linux, macOS, models, windows +from pyarchitecture import disks -version = "0.1.0" - -LOGGER = logging.getLogger(__name__) - - -def get_disk_lib(user_input: str | os.PathLike) -> str: - """Get the disk library for the appropriate OS. - - Args: - user_input: Disk library input by user. - """ - disk_lib = ( - user_input - or os.environ.get("disk_lib") - or os.environ.get("DISK_LIB") - or models.default_disk_lib()[models.OPERATING_SYSTEM] - ) - assert os.path.isfile(disk_lib), f"Disk library {disk_lib!r} doesn't exist" - return disk_lib - - -def get_all_disks(disk_lib: str | os.PathLike = None) -> List[Dict[str, str]]: - """OS-agnostic function to get all disks connected to the host system. - - Args: - disk_lib: Custom disk library path. - - Returns: - List[Dict[str, str]]: - Returns a list of disk information. - """ - os_map = { - models.OperatingSystem.darwin: macOS.drive_info, - models.OperatingSystem.linux: linux.drive_info, - models.OperatingSystem.windows: windows.drive_info, - } - try: - disk_lib = get_disk_lib(disk_lib) - return os_map[models.OperatingSystem(models.OPERATING_SYSTEM)](disk_lib) - except Exception as error: - LOGGER.error(error) - return [] +version = "0.0.0-a0" def commandline() -> None: - """Starter function to invoke PhyDisk via CLI commands. + """Starter function to invoke PyArchitecture via CLI commands. **Flags** - ``--version | -V``: Prints the version. @@ -61,11 +17,11 @@ def commandline() -> None: - ``save``: Saves the disk information into a JSON file. - ``--filename``: Filename to store the disk information. """ - assert sys.argv[0].lower().endswith("phydisk"), "Invalid commandline trigger!!" + assert sys.argv[0].lower().endswith("pyarchitecture"), "Invalid commandline trigger!!" print_ver = "--version" in sys.argv or "-V" in sys.argv get_help = "--help" in sys.argv or "-H" in sys.argv - print_info = "print" in sys.argv + disk_info = "disk" in sys.argv save_info = "save" in sys.argv filename = None custom_filename = "--filename" in sys.argv @@ -84,7 +40,7 @@ def commandline() -> None: options = { "--version | -V": "Prints the version.", "--help | -H": "Prints the help section.", - "print": "Prints the disk information in the terminal.", + "disk": "Prints the disk information in the terminal.", "save": "Saves the disk information into a JSON file.", "--filename": "Filename to store the disk information.", } @@ -97,17 +53,17 @@ def commandline() -> None: ) if print_ver: - print(f"PhyDisk {version}") + print(f"PyArchitecture {version}") sys.exit(0) - if print_info: - for disk in get_all_disks(): + if disk_info: + for disk in disks.get_all_disks(): print(disk) sys.exit(0) elif save_info: - filename = filename or f"PhyDisk_{int(time.time())}.json" + filename = filename or f"PyArchitecture_{int(time.time())}.json" with open(filename, "w") as file: - json.dump(get_all_disks(), file, indent=2) + json.dump(disks.get_all_disks(), file, indent=2) print(f"Physical disks' information has been stored in {filename!r}") sys.exit(0) else: @@ -115,6 +71,6 @@ def commandline() -> None: if get_help: print( - f"\nUsage: phydisk [arbitrary-command]\n\nOptions (and corresponding behavior):{choices}" + f"\nUsage: pyarchitecture [arbitrary-command]\n\nOptions (and corresponding behavior):{choices}" ) sys.exit(0) diff --git a/pyarchitecture/disks/__init__.py b/pyarchitecture/disks/__init__.py new file mode 100644 index 0000000..dd24145 --- /dev/null +++ b/pyarchitecture/disks/__init__.py @@ -0,0 +1,46 @@ +import logging +import os +from typing import Dict, List + +from . import linux, macOS, models, windows + +LOGGER = logging.getLogger(__name__) + + +def get_disk_lib(user_input: str | os.PathLike) -> str: + """Get the disk library for the appropriate OS. + + Args: + user_input: Disk library input by user. + """ + disk_lib = ( + user_input + or os.environ.get("disk_lib") + or os.environ.get("DISK_LIB") + or models.default_disk_lib()[models.OPERATING_SYSTEM] + ) + assert os.path.isfile(disk_lib), f"Disk library {disk_lib!r} doesn't exist" + return disk_lib + + +def get_all_disks(disk_lib: str | os.PathLike = None) -> List[Dict[str, str]]: + """OS-agnostic function to get all disks connected to the host system. + + Args: + disk_lib: Custom disk library path. + + Returns: + List[Dict[str, str]]: + Returns a list of disk information. + """ + os_map = { + models.OperatingSystem.darwin: macOS.drive_info, + models.OperatingSystem.linux: linux.drive_info, + models.OperatingSystem.windows: windows.drive_info, + } + try: + disk_lib = get_disk_lib(disk_lib) + return os_map[models.OperatingSystem(models.OPERATING_SYSTEM)](disk_lib) + except Exception as error: + LOGGER.error(error) + return [] diff --git a/phydisk/linux.py b/pyarchitecture/disks/linux.py similarity index 100% rename from phydisk/linux.py rename to pyarchitecture/disks/linux.py diff --git a/phydisk/macOS.py b/pyarchitecture/disks/macOS.py similarity index 99% rename from phydisk/macOS.py rename to pyarchitecture/disks/macOS.py index f706a84..048ff3b 100644 --- a/phydisk/macOS.py +++ b/pyarchitecture/disks/macOS.py @@ -5,7 +5,7 @@ from collections import defaultdict from typing import Dict, List -from phydisk import squire +from pyarchitecture import squire LOGGER = logging.getLogger(__name__) diff --git a/phydisk/models.py b/pyarchitecture/disks/models.py similarity index 100% rename from phydisk/models.py rename to pyarchitecture/disks/models.py diff --git a/phydisk/squire.py b/pyarchitecture/disks/squire.py similarity index 100% rename from phydisk/squire.py rename to pyarchitecture/disks/squire.py diff --git a/phydisk/windows.py b/pyarchitecture/disks/windows.py similarity index 99% rename from phydisk/windows.py rename to pyarchitecture/disks/windows.py index e854c99..86b9d17 100644 --- a/phydisk/windows.py +++ b/pyarchitecture/disks/windows.py @@ -6,7 +6,7 @@ import subprocess from typing import Dict, List, Tuple -from phydisk import squire +from pyarchitecture import squire LOGGER = logging.getLogger(__name__) diff --git a/pyproject.toml b/pyproject.toml index 1883e49..e7762c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "PhyDisk" +name = "PyArchitecture" dynamic = ["version"] description = "Python module to get physical drives connected to a host machine" readme = "README.md" @@ -12,33 +12,28 @@ classifiers = [ "Operating System :: OS Independent", "Topic :: System :: Hardware", ] -keywords = ["physical-drives", "PhyDisk"] +keywords = ["physical-drives", "PyArchitecture"] requires-python = ">=3.10" [tool.setuptools] packages = [ - "phydisk" + "pyarchitecture" ] [tool.setuptools.dynamic] -version = {attr = "phydisk.version"} +version = {attr = "pyarchitecture.version"} [project.optional-dependencies] dev = ["pre-commit"] -standard = [ - "Jinja2==3.1.*", - "requests==2.*", - "gmail-connector" -] [project.scripts] # sends all the args to commandline function, where the arbitary commands as processed accordingly -phydisk = "phydisk:commandline" +pyarchitecture = "pyarchitecture:commandline" [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project.urls] -Homepage = "https://github.com/thevickypedia/PhyDisk" -Source = "https://github.com/thevickypedia/PhyDisk" +Homepage = "https://github.com/thevickypedia/PyArchitecture" +Source = "https://github.com/thevickypedia/PyArchitecture"