From a0d6163c520e901155d2b90c1e3a0b0ba839d151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Gardfj=C3=A4ll?= Date: Tue, 7 Apr 2020 20:38:22 +0200 Subject: [PATCH] move all executable scripts under garminexport.cli --- garminbackup.py | 30 ------------------- garminexport/cli/__init__.py | 0 garminexport/{cli.py => cli/backup.py} | 29 ++++++++++++++++++ .../cli/get_activity.py | 2 +- .../cli/upload_activity.py | 5 ++-- 5 files changed, 32 insertions(+), 34 deletions(-) delete mode 100755 garminbackup.py create mode 100644 garminexport/cli/__init__.py rename garminexport/{cli.py => cli/backup.py} (66%) rename get_activity.py => garminexport/cli/get_activity.py (99%) rename upload_activity.py => garminexport/cli/upload_activity.py (96%) diff --git a/garminbackup.py b/garminbackup.py deleted file mode 100755 index d584cc2..0000000 --- a/garminbackup.py +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env python -"""This python script calls garminexport.garminbackup module with CLI parsed arguments -and performs (incremental) backups of activities for a given Garmin Connect account. -The activities are stored in a local directory on the user's computer. -The backups are incremental, meaning that only activities that aren't already -stored in the backup directory will be downloaded. -""" -import logging - -from garminexport.cli import parse_args -from garminexport.incremental_backup import incremental_backup -from garminexport.logging_config import LOG_LEVELS - -logging.basicConfig(level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s") -log = logging.getLogger(__name__) - -if __name__ == "__main__": - args = parse_args() - logging.root.setLevel(LOG_LEVELS[args.log_level]) - - try: - incremental_backup(username=args.username, - password=args.password, - backup_dir=args.backup_dir, - format=args.format, - ignore_errors=args.ignore_errors, - max_retries=args.max_retries) - - except Exception as e: - log.error("failed with exception: {}".format(e)) diff --git a/garminexport/cli/__init__.py b/garminexport/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/garminexport/cli.py b/garminexport/cli/backup.py similarity index 66% rename from garminexport/cli.py rename to garminexport/cli/backup.py index 6478922..33860b1 100644 --- a/garminexport/cli.py +++ b/garminexport/cli/backup.py @@ -1,7 +1,19 @@ +"""This script performs backups of activities for a Garmin Connect account. The +activities are stored in a local directory on the user's computer. The backups +are incremental, meaning that only activities that aren't already stored in the +backup directory will be downloaded. + +""" import argparse +import logging import os from garminexport.backup import export_formats +from garminexport.incremental_backup import incremental_backup +from garminexport.logging_config import LOG_LEVELS + +logging.basicConfig(level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s") +log = logging.getLogger(__name__) DEFAULT_MAX_RETRIES = 7 """The default maximum number of retries to make when fetching a single activity.""" @@ -14,6 +26,7 @@ def parse_args() -> argparse.Namespace: This object may be directly used by garminexport/garminbackup.py. """ parser = argparse.ArgumentParser( + prog="garminbackup", description=( "Performs incremental backups of activities for a " "given Garmin Connect account. Only activities that " @@ -48,3 +61,19 @@ def parse_args() -> argparse.Namespace: "will double with every retry, starting at one second. DEFAULT: {}").format(DEFAULT_MAX_RETRIES)) return parser.parse_args() + + +def main(): + args = parse_args() + logging.root.setLevel(LOG_LEVELS[args.log_level]) + + try: + incremental_backup(username=args.username, + password=args.password, + backup_dir=args.backup_dir, + format=args.format, + ignore_errors=args.ignore_errors, + max_retries=args.max_retries) + + except Exception as e: + log.error("failed with exception: {}".format(e)) diff --git a/get_activity.py b/garminexport/cli/get_activity.py similarity index 99% rename from get_activity.py rename to garminexport/cli/get_activity.py index 0330ffd..9446095 100755 --- a/get_activity.py +++ b/garminexport/cli/get_activity.py @@ -18,8 +18,8 @@ from garminexport.retryer import Retryer, ExponentialBackoffDelayStrategy, MaxRe logging.basicConfig(level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s") log = logging.getLogger(__name__) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser( description="Downloads one particular activity for a given Garmin Connect account.") diff --git a/upload_activity.py b/garminexport/cli/upload_activity.py similarity index 96% rename from upload_activity.py rename to garminexport/cli/upload_activity.py index 7e8ccac..1d6d69e 100755 --- a/upload_activity.py +++ b/garminexport/cli/upload_activity.py @@ -1,6 +1,5 @@ #! /usr/bin/env python -"""A program that uploads an activity file to a Garmin -Connect account. +"""A program that uploads an activity file to a Garmin Connect account. """ import argparse import getpass @@ -12,8 +11,8 @@ from garminexport.logging_config import LOG_LEVELS logging.basicConfig(level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s") log = logging.getLogger(__name__) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser( description="Uploads an activity file to a Garmin Connect account.")