Skip to content

Commit

Permalink
Re-purpose the project to include all architecture information
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 1, 2025
1 parent c25fd8b commit ac33c71
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
venv
build
temp.py
PhyDisk.egg-info
PyArchitecture.egg-info
*.json
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]

Expand All @@ -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

Expand Down Expand Up @@ -84,23 +84,23 @@ 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

© Vignesh Rao

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/
68 changes: 12 additions & 56 deletions phydisk/__init__.py → pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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.",
}
Expand All @@ -97,24 +53,24 @@ 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:
get_help = True

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)
46 changes: 46 additions & 0 deletions pyarchitecture/disks/__init__.py
Original file line number Diff line number Diff line change
@@ -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 []
File renamed without changes.
2 changes: 1 addition & 1 deletion phydisk/macOS.py → pyarchitecture/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phydisk/windows.py → pyarchitecture/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
from typing import Dict, List, Tuple

from phydisk import squire
from pyarchitecture import squire

LOGGER = logging.getLogger(__name__)

Expand Down
19 changes: 7 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

0 comments on commit ac33c71

Please sign in to comment.