Use Typer instead of platformdirs
This commit is contained in:
@ -55,6 +55,8 @@ def add(
|
|||||||
@app.command()
|
@app.command()
|
||||||
def stats() -> None:
|
def stats() -> None:
|
||||||
"""Print the number of feeds and entries in the database"""
|
"""Print the number of feeds and entries in the database"""
|
||||||
|
app_dir = typer.get_app_dir(Settings.APP_NAME)
|
||||||
|
typer.echo(app_dir)
|
||||||
with closing(make_reader(Settings.db_file)) as reader:
|
with closing(make_reader(Settings.db_file)) as reader:
|
||||||
feed_count = reader.get_feed_counts()
|
feed_count = reader.get_feed_counts()
|
||||||
entry_count = reader.get_entry_counts()
|
entry_count = reader.get_entry_counts()
|
||||||
@ -100,14 +102,14 @@ def check() -> None:
|
|||||||
@app.command()
|
@app.command()
|
||||||
def backup() -> None:
|
def backup() -> None:
|
||||||
"""Backup the database"""
|
"""Backup the database"""
|
||||||
backup_dir = os.path.join(Settings.data_dir, "backup")
|
backup_dir = os.path.join(Settings.app_dir, "backup")
|
||||||
os.makedirs(backup_dir, exist_ok=True)
|
os.makedirs(backup_dir, exist_ok=True)
|
||||||
|
|
||||||
# Get the current time
|
# Get the current time
|
||||||
current_time = time.strftime("%Y-%m-%d_%H-%M-%S")
|
current_time = time.strftime("%Y-%m-%d_%H-%M-%S")
|
||||||
|
|
||||||
backup_file_location = os.path.join(
|
backup_file_location = os.path.join(
|
||||||
Settings.data_dir, "backup", f"db_{current_time}.sqlite"
|
Settings.app_dir, "backup", f"db_{current_time}.sqlite"
|
||||||
)
|
)
|
||||||
copyfile(Settings.db_file, backup_file_location)
|
copyfile(Settings.db_file, backup_file_location)
|
||||||
|
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from platformdirs import user_data_dir
|
import typer
|
||||||
|
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
data_dir = user_data_dir(
|
APP_NAME: str = "discord-rss-bot"
|
||||||
appname="discord-rss-bot", # The name of application.
|
|
||||||
appauthor="TheLovinator", # The name of the app author or distributing body for this application
|
app_dir = typer.get_app_dir(APP_NAME)
|
||||||
roaming=True, # Whether to use the roaming appdata directory on Windows
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the data directory if it doesn't exist
|
# Create the data directory if it doesn't exist
|
||||||
os.makedirs(data_dir, exist_ok=True)
|
os.makedirs(app_dir, exist_ok=True)
|
||||||
|
|
||||||
# Store the database file in the data directory
|
# Store the database file in the data directory
|
||||||
db_file = os.path.join(data_dir, "db.sqlite")
|
db_file: Path = Path(os.path.join(app_dir, "db.sqlite"))
|
||||||
|
|
||||||
# Store the config in the data directory
|
# Store the config in the data directory
|
||||||
config_location = os.path.join(data_dir, "config.conf")
|
config_location: Path = Path(os.path.join(app_dir, "config.conf"))
|
||||||
|
|
||||||
if not os.path.isfile(config_location):
|
if not os.path.isfile(config_location):
|
||||||
# TODO: Add config for db_file and config_location
|
# TODO: Add config for db_file and config_location
|
||||||
|
4
poetry.lock
generated
4
poetry.lock
generated
@ -323,7 +323,7 @@ python-versions = ">=2.6"
|
|||||||
name = "platformdirs"
|
name = "platformdirs"
|
||||||
version = "2.4.0"
|
version = "2.4.0"
|
||||||
description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
||||||
category = "main"
|
category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.6"
|
python-versions = ">=3.6"
|
||||||
|
|
||||||
@ -570,7 +570,7 @@ multidict = ">=4.0"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "bfc980afa624bed7398f84e92bbe8a08724b12a0e5e9d40ed7fd3d6ec24d4b30"
|
content-hash = "d31a61ac43f00272d9a36098174ebd7bc781c2c4abff929326b322fd5030ab39"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiohttp = [
|
aiohttp = [
|
||||||
|
@ -9,7 +9,6 @@ python = "^3.9"
|
|||||||
reader = "^2.6"
|
reader = "^2.6"
|
||||||
typer = {extras = ["all"], version = "^0.4.0"}
|
typer = {extras = ["all"], version = "^0.4.0"}
|
||||||
dhooks = "^1.1.4"
|
dhooks = "^1.1.4"
|
||||||
platformdirs = "^2.4.0"
|
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^5.2"
|
pytest = "^5.2"
|
||||||
|
Reference in New Issue
Block a user