From b06e776850f18cbf0be393b15d410c102bd5f72d Mon Sep 17 00:00:00 2001 From: Agatha Rose Date: Mon, 18 Oct 2021 02:31:48 +0300 Subject: [PATCH] Properly package --- README.md | 16 ++++-- main.py | 76 -------------------------- requirements.txt | 3 -- setup.py | 25 +++++++++ vacuumtube/__init__.py | 0 config.py => vacuumtube/config.py | 0 vacuumtube/main.py | 82 +++++++++++++++++++++++++++++ prepare.py => vacuumtube/prepare.py | 2 +- 8 files changed, 119 insertions(+), 85 deletions(-) delete mode 100644 main.py delete mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 vacuumtube/__init__.py rename config.py => vacuumtube/config.py (100%) create mode 100644 vacuumtube/main.py rename prepare.py => vacuumtube/prepare.py (98%) diff --git a/README.md b/README.md index 7ef5b35..057aa39 100644 --- a/README.md +++ b/README.md @@ -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 /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 \ No newline at end of file +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` \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 0afd6af..0000000 --- a/main.py +++ /dev/null @@ -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 -)) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 44a05e3..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -rich==10.11.0 -toml==0.10.2 -tomli==1.2.1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fbe3616 --- /dev/null +++ b/setup.py @@ -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' + ] + } +) diff --git a/vacuumtube/__init__.py b/vacuumtube/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config.py b/vacuumtube/config.py similarity index 100% rename from config.py rename to vacuumtube/config.py diff --git a/vacuumtube/main.py b/vacuumtube/main.py new file mode 100644 index 0000000..ccf11a1 --- /dev/null +++ b/vacuumtube/main.py @@ -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() diff --git a/prepare.py b/vacuumtube/prepare.py similarity index 98% rename from prepare.py rename to vacuumtube/prepare.py index 38c4c87..abbc088 100644 --- a/prepare.py +++ b/vacuumtube/prepare.py @@ -1,4 +1,4 @@ -from config import config +from vacuumtube.config import config from datetime import datetime from rich import print import json