Properly package

This commit is contained in:
Agatha Lovelace 2021-10-18 02:31:48 +03:00
parent 91c9387d4e
commit b06e776850
No known key found for this signature in database
GPG Key ID: 2DB18BA2E0A80BC3
8 changed files with 119 additions and 85 deletions

View File

@ -10,8 +10,14 @@ A small command line tool that displays information about your Borg backups.
- Python 3.0+
## Usage
1. *Optional: create a [virtual environment](https://docs.python.org/3/library/venv.html) and run `source <venv>/bin/activate`*
2. Clone the respository: `git clone https://git.lain.faith/sorceress/vacuum-tube.git && cd vacuum-tube`
3. Install dependencies: `pip3 install -r requirements.txt`
4. Run: `python main.py`
5. Edit the newly created configuration file and run `main.py` again
1. Clone the respository: `git clone https://git.lain.faith/sorceress/vacuum-tube.git && cd vacuum-tube`
2. Run `sudo pip install .` *(Or, without `sudo` if you wish to install it into `~/.local/bin/`)*
3. Run `vacuum-tube`
5. Edit the newly created configuration file and run `vacuum-tube` again
## Troubleshooting
- ### vacuum-tube: command not found
If you installed the package locally, your installation directory may not be in `$PATH`.
You can add it with `export PATH="/some/directory:$PATH"` in your `.bashrc`/`.zshrc`/etc file.
- ### No module named setuptools
`pip install setuptools`

76
main.py
View File

@ -1,76 +0,0 @@
from prepare import borg_info_raw, readable_csize, csize, archive_num, last_archive_time, df_avail_readable, df_avail_bytes
from rich import box
from rich.console import Console
from rich.layout import Layout
from rich.padding import Padding
from rich.panel import Panel
from rich.progress import Progress, BarColumn
from rich.style import Style
from config import config
emphasis = Style(color=config['color'] or '#d89961', bold=True)
flomp = f'''[{emphasis}]
.=--::
-***##- ::. ...
+**##*: =##*. =*****:
:******+::.. :##*: :******.
=*************+====-::+*****+
.+**=:-==+++++****************:
-***. .:--==+++++******+
=**+. .:-+#***-
:***= *****
-***- -#***-
.=+**=:. *****
.:-+++=-:. =#***=
.:-=*+=-:. :#****.
.:-=+++-::*****=
.:-=+****
.:.
'''
if borg_info_raw.returncode == 0:
online = Padding('[#82bfe0 bold]◉[/#82bfe0 bold] Host online', (0, 2))
else:
online = Padding('[#34454f bold]◌[/#34454f bold] Host offline', (0, 2))
# it's hacky, but should work as expected
used = Progress(
'[progress.description]{task.description}',
# space used
f'[{emphasis}]{readable_csize}[/{emphasis}]',
BarColumn(complete_style=emphasis, finished_style="#d34141"),
# space available
f'[{emphasis}]{df_avail_readable}[/{emphasis}]',
'[progress.percentage]{task.percentage:>3.0f}%'
)
used.add_task('Used:', completed=csize, total=df_avail_bytes)
disk_usage = Panel(used, box=box.SQUARE, border_style=emphasis)
avail_backups = Panel(f"Available: [{emphasis}]{archive_num}[/{emphasis}] backups. Last backup from: [{emphasis}]{last_archive_time}[/{emphasis}]", box=box.SQUARE, border_style=emphasis)
if config['ascii_art']:
console = Console(width=85, height=18)
else:
console = Console(width=70, height=8)
layout = Layout()
layout.split_row(
Layout(flomp, name="left"),
Layout(name="right")
)
layout['right'].split_column(
Layout(online, size=1),
Layout(disk_usage, size=3),
Layout(avail_backups, size=4)
)
layout['left'].visible = config['ascii_art']
# actually print the thing
console.print(Panel.fit(
layout,
box=box.DOUBLE, border_style=emphasis
))

View File

@ -1,3 +0,0 @@
rich==10.11.0
toml==0.10.2
tomli==1.2.1

25
setup.py Normal file
View File

@ -0,0 +1,25 @@
from setuptools import setup, find_packages
setup(
name='vacuumtube',
version='1.0.0',
author='Agatha V. Lovelace',
author_email='agatharose@wantscuddl.es',
description=('A small command line tool that displays information about your Borg backups'),
license='CNPL v7+',
url='https://git.lain.faith/sorceress/vacuum-tube',
python_requires=">=3.0",
packages=find_packages(),
include_package_data=True,
install_requires=(
'rich==10.11.0',
'toml==0.10.2',
'tomli==1.2.1',
'setuptools'
),
entry_points={
'console_scripts': [
'vacuum-tube = vacuumtube.main:main'
]
}
)

0
vacuumtube/__init__.py Normal file
View File

82
vacuumtube/main.py Normal file
View File

@ -0,0 +1,82 @@
from vacuumtube.config import config
from vacuumtube.prepare import borg_info_raw, readable_csize, csize, archive_num, last_archive_time, df_avail_readable, df_avail_bytes
from rich import box
from rich.console import Console
from rich.layout import Layout
from rich.padding import Padding
from rich.panel import Panel
from rich.progress import Progress, BarColumn
from rich.style import Style
def main():
emphasis = Style(color=config['color'] or '#d89961', bold=True)
flomp = f'''[{emphasis}]
.=--::
-***##- ::. ...
+**##*: =##*. =*****:
:******+::.. :##*: :******.
=*************+====-::+*****+
.+**=:-==+++++****************:
-***. .:--==+++++******+
=**+. .:-+#***-
:***= *****
-***- -#***-
.=+**=:. *****
.:-+++=-:. =#***=
.:-=*+=-:. :#****.
.:-=+++-::*****=
.:-=+****
.:.
'''
if borg_info_raw.returncode == 0:
online = Padding('[#82bfe0 bold]◉[/#82bfe0 bold] Host online', (0, 2))
else:
online = Padding('[#34454f bold]◌[/#34454f bold] Host offline', (0, 2))
# it's hacky, but should work as expected
used = Progress(
'[progress.description]{task.description}',
# space used
f'[{emphasis}]{readable_csize}[/{emphasis}]',
BarColumn(complete_style=emphasis, finished_style="#d34141"),
# space available
f'[{emphasis}]{df_avail_readable}[/{emphasis}]',
'[progress.percentage]{task.percentage:>3.0f}%'
)
used.add_task('Used:', completed=csize, total=df_avail_bytes)
disk_usage = Panel(used, box=box.SQUARE, border_style=emphasis)
avail_backups = Panel(f"Available: [{emphasis}]{archive_num}[/{emphasis}] backups. Last backup from: [{emphasis}]{last_archive_time}[/{emphasis}]", box=box.SQUARE, border_style=emphasis)
if config['ascii_art']:
console = Console(width=85, height=18)
else:
console = Console(width=70, height=8)
layout = Layout()
layout.split_row(
Layout(flomp, name="left"),
Layout(name="right")
)
layout['right'].split_column(
Layout(online, size=1),
Layout(disk_usage, size=3),
Layout(avail_backups, size=4)
)
layout['left'].visible = config['ascii_art']
# actually print the thing
console.print(Panel.fit(
layout,
box=box.DOUBLE, border_style=emphasis
))
if __name__ == '__main__':
main()

View File

@ -1,4 +1,4 @@
from config import config
from vacuumtube.config import config
from datetime import datetime
from rich import print
import json