Skip to content

Commit

Permalink
Fix Log Issues (#4)
Browse files Browse the repository at this point in the history
* Fix permissions issue for logging when installed
- Logs are now written to home dir on .battery-advisor.log

* Bump to 1.2.1
  • Loading branch information
fer-hnndz authored Oct 3, 2024
1 parent 6d77340 commit c98efd3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .SRCINFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkgbase = battery-advisor
pkgdesc = A simple tool to monitor and notify about battery status. Built with Python.
pkgver = 1.2.0
pkgver = 1.2.1
pkgrel = 1
url = https://github.com/fer-hnndz/battery-advisor
arch = any
Expand All @@ -16,7 +16,7 @@ pkgbase = battery-advisor
depends = python-pystray
depends = python-systemd
backup = etc/battery-advisor/defaultSettings.toml
source = https://files.pythonhosted.org/packages/source/b/battery_advisor/battery_advisor-1.2.0.tar.gz
sha256sums = e2128de236038d4beae221cd92e8c82a50a033d97bd7bdd6afab725e02bc8fc3
source = https://files.pythonhosted.org/packages/source/b/battery_advisor/battery_advisor-1.2.1.tar.gz
sha256sums = 2e40d3b6855c418c75d757cba720a7b93b2b98be055287e507bed82c20ebd447

pkgname = battery-advisor
4 changes: 2 additions & 2 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintainer: Jorge Hernández <[email protected]>
pkgname="battery-advisor"
pkgver=1.2.0
pkgver=1.2.1
pkgrel=1
pkgdesc="A simple tool to monitor and notify about battery status. Built with Python."
arch=('any')
Expand All @@ -11,7 +11,7 @@ backup=("etc/battery-advisor/defaultSettings.toml")
makedepends=(python-build python-installer python-wheel)
_name=${pkgname#python-}
source=("https://files.pythonhosted.org/packages/source/${_name::1}/${_name//-/_}/${_name//-/_}-$pkgver.tar.gz")
sha256sums=(e2128de236038d4beae221cd92e8c82a50a033d97bd7bdd6afab725e02bc8fc3)
sha256sums=(2e40d3b6855c418c75d757cba720a7b93b2b98be055287e507bed82c20ebd447)
validpgpkeys=()

prepare() {
Expand Down
2 changes: 1 addition & 1 deletion battery_advisor/battery_advisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _battery_checker(self):
notify("Battery Unplugged", "Battery is now discharging.")

report = self.get_battery_reports()
logging.info("Battery Report:", report)
logging.info(f"Battery Report: {str(report)}")

if report is None:
time.sleep(self.settings.check_interval)
Expand Down
43 changes: 25 additions & 18 deletions battery_advisor/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@
import argparse
import logging
import os
from .utils import _get_project_root
from .utils import get_log_path
import traceback


def cli():
log_path = os.path.join(_get_project_root(), "advisor.log")
try:
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s ] (%(module)s.%(funcName)s | %(levelname)s) %(message)s",
datefmt="%d/%m/%Y @ %H:%M:%S %Z",
filename=get_log_path(),
)

logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s ] (%(module)s.%(funcName)s | %(levelname)s) %(message)s",
datefmt="%d/%m/%Y @ %H:%M:%S %Z",
filename=log_path,
)
parser = argparse.ArgumentParser(
prog="Battery Advisor",
description="A simple tool to monitor and notify about battery status. Built with Python.",
epilog="Made with ❤️ by Jorge Hernández.",
)
parser.add_argument(
"--version", action="version", version=f"%(prog)s {VERSION}"
)
parser.add_argument(
"--clean", action="store_true", help="Use default settings."
)

parser = argparse.ArgumentParser(
prog="Battery Advisor",
description="A simple tool to monitor and notify about battery status. Built with Python.",
epilog="Made with ❤️ by Jorge Hernández.",
)
parser.add_argument("--version", action="version", version=f"%(prog)s {VERSION}")
parser.add_argument("--clean", action="store_true", help="Use default settings.")

args = parser.parse_args()
BatteryAdvisor(clean=args.clean).start()
args = parser.parse_args()
BatteryAdvisor(clean=args.clean).start()
except Exception as e:
logging.error(traceback.format_exc())
quit(1)
7 changes: 5 additions & 2 deletions battery_advisor/settings_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from typing import Type
from .types import SettingsFile
from .utils import _get_project_root
import logging


logger = logging.getLogger(__name__)
user_settings_path = os.path.expanduser("~/.config/battery-advisor/settings.toml")
default_settings_path = _get_project_root() + "/defaultSettings.toml"

Expand All @@ -18,7 +21,7 @@ def load_settings(load_default: bool = False) -> SettingsFile:
"""

if load_default:
print("Loading default settings...")
logging.info("(--clean) Loading default settings...")
with open(default_settings_path) as f:
return toml.load(f)

Expand All @@ -29,7 +32,7 @@ def load_settings(load_default: bool = False) -> SettingsFile:
)

if not os.path.exists(user_settings_path):
print("User settings not found. Using default settings.")
logging.warning("User settings not found. Using default settings.")

with open(path) as f:
return toml.load(f)
Expand Down
4 changes: 4 additions & 0 deletions battery_advisor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def _get_project_root() -> str:
return os.path.expandvars(absolute_root)


def get_log_path() -> str:
return os.path.expanduser("~/.battery-advisor.log")


def _get_path_icon():
icon_path = _get_project_root() + "/icon.png"
return os.path.expandvars(icon_path)
Expand Down
2 changes: 1 addition & 1 deletion battery_advisor/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.2.0"
VERSION = "1.2.1"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "battery-advisor"
version = "1.2.0"
version = "1.2.1"
description = "A simple tool to monitor and notify about battery status. Built with Python."
authors = ["fer-hnndz <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit c98efd3

Please sign in to comment.