Skip to content

Commit

Permalink
Merge pull request #16 from jeremiah-k/initial-trunk
Browse files Browse the repository at this point in the history
Initial trunk
  • Loading branch information
jeremiah-k authored Nov 15, 2024
2 parents 1e65863 + e434395 commit d43c869
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 236 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ on:
release:
types: [created]

permissions:
contents: read
packages: read

jobs:
build-and-publish:
runs-on: ubuntu-latest
environment: release

permissions:
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: 3.x

- name: Install build dependencies
run: |
Expand All @@ -30,3 +31,5 @@ jobs:

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
2 changes: 2 additions & 0 deletions .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
2 changes: 2 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
5 changes: 5 additions & 0 deletions .trunk/configs/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generic, formatter-friendly config.
select = ["B", "D3", "E", "F"]

# Never enforce `E501` (line length violations). This should be handled by formatters.
ignore = ["E501"]
32 changes: 32 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.8
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.4
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fetchtastic is a utility for downloading and managing the latest Meshtastic Andr
1. **Install Termux**: Download and install [Termux](https://f-droid.org/en/packages/com.termux/) from F-Droid.
2. **Install Termux Boot**: Download and install [Termux Boot](https://f-droid.org/en/packages/com.termux.boot/) from F-Droid.
3. **Install Termux API**: Download and install [Termux API](https://f-droid.org/en/packages/com.termux.api/) from F-Droid.
4. *(Optional)* **Install ntfy**: Download and install [ntfy](https://f-droid.org/en/packages/io.heckel.ntfy/) from F-Droid.
4. _(Optional)_ **Install ntfy**: Download and install [ntfy](https://f-droid.org/en/packages/io.heckel.ntfy/) from F-Droid.

## Installation

Expand Down Expand Up @@ -56,10 +56,10 @@ During setup, you will be able to:

By default, Fetchtastic saves files and configuration in the `Downloads/Meshtastic` directory:

- **Configuration File**: `Downloads/Meshtastic/fetchtastic.yaml`
- **Log File**: `Downloads/Meshtastic/fetchtastic.log`
- **APKs**: `Downloads/Meshtastic/apks`
- **Firmware**: `Downloads/Meshtastic/firmware`
- **Configuration File**: `Downloads/Meshtastic/fetchtastic.yaml`
- **Log File**: `Downloads/Meshtastic/fetchtastic.log`
- **APKs**: `Downloads/Meshtastic/apks`
- **Firmware**: `Downloads/Meshtastic/firmware`

You can manually edit the configuration file to change the settings.

Expand All @@ -68,6 +68,7 @@ You can manually edit the configuration file to change the settings.
During setup, you have the option to add a cron job that runs Fetchtastic daily at 3 AM.

To modify the cron job, you can run:

```bash
crontab -e
```
Expand Down
88 changes: 61 additions & 27 deletions app/cli.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,73 @@
# app/cli.py

import argparse
import subprocess
import os
import shutil
from . import downloader
from . import setup_config
import subprocess

from . import downloader, setup_config


def main():
parser = argparse.ArgumentParser(description="Fetchtastic - Meshtastic Firmware and APK Downloader")
subparsers = parser.add_subparsers(dest='command')
parser = argparse.ArgumentParser(
description="Fetchtastic - Meshtastic Firmware and APK Downloader"
)
subparsers = parser.add_subparsers(dest="command")

# Command to run setup
subparsers.add_parser('setup', help='Run the setup process')
subparsers.add_parser("setup", help="Run the setup process")

# Command to download firmware and APKs
subparsers.add_parser('download', help='Download firmware and APKs')
subparsers.add_parser("download", help="Download firmware and APKs")

# Command to display NTFY topic
subparsers.add_parser('topic', help='Display the current NTFY topic')
subparsers.add_parser("topic", help="Display the current NTFY topic")

# Command to clean/remove Fetchtastic files and settings
subparsers.add_parser('clean', help='Remove Fetchtastic configuration, downloads, and cron jobs')
subparsers.add_parser(
"clean", help="Remove Fetchtastic configuration, downloads, and cron jobs"
)

args = parser.parse_args()

if args.command == 'setup':
if args.command == "setup":
# Run the setup process
setup_config.run_setup()
elif args.command == 'download':
elif args.command == "download":
# Check if configuration exists
if not setup_config.config_exists():
print("No configuration found. Running setup.")
setup_config.run_setup()
else:
# Run the downloader
downloader.main()
elif args.command == 'topic':
elif args.command == "topic":
# Display the NTFY topic and prompt to copy to clipboard
config = setup_config.load_config()
if config and config.get('NTFY_SERVER') and config.get('NTFY_TOPIC'):
ntfy_server = config['NTFY_SERVER'].rstrip('/')
ntfy_topic = config['NTFY_TOPIC']
if config and config.get("NTFY_SERVER") and config.get("NTFY_TOPIC"):
ntfy_server = config["NTFY_SERVER"].rstrip("/")
ntfy_topic = config["NTFY_TOPIC"]
full_url = f"{ntfy_server}/{ntfy_topic}"
print(f"Current NTFY topic URL: {full_url}")
print(f"Topic name: {ntfy_topic}")
copy_to_clipboard = input("Do you want to copy the topic name to the clipboard? [y/n] (default: yes): ").strip().lower() or 'y'
if copy_to_clipboard == 'y':
copy_to_clipboard = (
input(
"Do you want to copy the topic name to the clipboard? [y/n] (default: yes): "
)
.strip()
.lower()
or "y"
)
if copy_to_clipboard == "y":
copy_to_clipboard_termux(ntfy_topic)
print("Topic name copied to clipboard.")
else:
print("You can copy the topic name from above.")
else:
print("Notifications are not set up. Run 'fetchtastic setup' to configure notifications.")
elif args.command == 'clean':
print(
"Notifications are not set up. Run 'fetchtastic setup' to configure notifications."
)
elif args.command == "clean":
# Run the clean process
run_clean()
elif args.command is None:
Expand All @@ -63,16 +77,23 @@ def main():
else:
parser.print_help()


def copy_to_clipboard_termux(text):
try:
subprocess.run(['termux-clipboard-set'], input=text.encode('utf-8'), check=True)
subprocess.run(["termux-clipboard-set"], input=text.encode("utf-8"), check=True)
except Exception as e:
print(f"An error occurred while copying to clipboard: {e}")


def run_clean():
print("This will remove Fetchtastic configuration files, downloaded files, and cron job entries.")
confirm = input("Are you sure you want to proceed? [y/n] (default: no): ").strip().lower() or 'n'
if confirm != 'y':
print(
"This will remove Fetchtastic configuration files, downloaded files, and cron job entries."
)
confirm = (
input("Are you sure you want to proceed? [y/n] (default: no): ").strip().lower()
or "n"
)
if confirm != "y":
print("Clean operation cancelled.")
return

Expand All @@ -91,13 +112,23 @@ def run_clean():
# Remove cron job entries
try:
# Get current crontab entries
result = subprocess.run(['crontab', '-l'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
result = subprocess.run(
["crontab", "-l"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
if result.returncode == 0:
existing_cron = result.stdout
# Remove existing fetchtastic cron jobs
new_cron = '\n'.join([line for line in existing_cron.split('\n') if 'fetchtastic download' not in line])
new_cron = "\n".join(
[
line
for line in existing_cron.split("\n")
if "fetchtastic download" not in line
]
)
# Update crontab
process = subprocess.Popen(['crontab', '-'], stdin=subprocess.PIPE, text=True)
process = subprocess.Popen(
["crontab", "-"], stdin=subprocess.PIPE, text=True
)
process.communicate(input=new_cron)
print("Removed Fetchtastic cron job entries.")
except Exception as e:
Expand All @@ -110,7 +141,10 @@ def run_clean():
print(f"Removed boot script: {boot_script}")

print("Fetchtastic has been cleaned from your system.")
print("If you installed Fetchtastic via pip and wish to uninstall it, run 'pip uninstall fetchtastic'.")
print(
"If you installed Fetchtastic via pip and wish to uninstall it, run 'pip uninstall fetchtastic'."
)


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

0 comments on commit d43c869

Please sign in to comment.