move all executable scripts under garminexport.cli

This commit is contained in:
Peter Gardfjäll 2020-04-07 20:38:22 +02:00
parent 54dad23e1c
commit a0d6163c52
5 changed files with 32 additions and 34 deletions

View File

@ -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))

View File

View File

@ -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))

View File

@ -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.")

View File

@ -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.")