call export_formats supported_export_formats

Co-authored-by: Stanislav Khrapov khrapovs@gmail.com
This commit is contained in:
Peter Gardfjäll 2020-04-08 20:21:59 +02:00
parent f2225bb3b3
commit 3df00a89c9
4 changed files with 15 additions and 15 deletions

View File

@ -8,7 +8,7 @@ from datetime import datetime
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
export_formats = ["json_summary", "json_details", "gpx", "tcx", "fit"] supported_export_formats = ["json_summary", "json_details", "gpx", "tcx", "fit"]
"""The range of supported export formats for activities.""" """The range of supported export formats for activities."""
format_suffix = { format_suffix = {

View File

@ -8,7 +8,7 @@ import argparse
import logging import logging
import os import os
from garminexport.backup import export_formats from garminexport.backup import supported_export_formats
from garminexport.incremental_backup import incremental_backup from garminexport.incremental_backup import incremental_backup
from garminexport.logging_config import LOG_LEVELS from garminexport.logging_config import LOG_LEVELS
@ -47,9 +47,9 @@ def parse_args() -> argparse.Namespace:
help="Desired log output level (DEBUG, INFO, WARNING, ERROR). Default: INFO.", help="Desired log output level (DEBUG, INFO, WARNING, ERROR). Default: INFO.",
default="INFO") default="INFO")
parser.add_argument( parser.add_argument(
"-f", "--format", choices=export_formats, "-f", "--format", choices=supported_export_formats,
default=None, action='append', default=None, action='append',
help="Desired output formats ({}). Default: ALL.".format(', '.join(export_formats))) help="Desired output formats ({}). Default: ALL.".format(', '.join(supported_export_formats)))
parser.add_argument( parser.add_argument(
"-E", "--ignore-errors", action='store_true', "-E", "--ignore-errors", action='store_true',
help="Ignore errors and keep going. Default: FALSE") help="Ignore errors and keep going. Default: FALSE")
@ -71,7 +71,7 @@ def main():
incremental_backup(username=args.username, incremental_backup(username=args.username,
password=args.password, password=args.password,
backup_dir=args.backup_dir, backup_dir=args.backup_dir,
format=args.format, export_formats=args.format,
ignore_errors=args.ignore_errors, ignore_errors=args.ignore_errors,
max_retries=args.max_retries) max_retries=args.max_retries)

View File

@ -30,7 +30,7 @@ def main():
"activity", metavar="<activity>", type=int, help="Activity ID.") "activity", metavar="<activity>", type=int, help="Activity ID.")
parser.add_argument( parser.add_argument(
"format", metavar="<format>", type=str, "format", metavar="<format>", type=str,
help="Export format (one of: {}).".format(garminexport.backup.export_formats)) help="Export format (one of: {}).".format(garminexport.backup.supported_export_formats))
# optional args # optional args
parser.add_argument( parser.add_argument(
@ -49,10 +49,10 @@ def main():
if args.log_level not in LOG_LEVELS: if args.log_level not in LOG_LEVELS:
raise ValueError("Illegal log-level argument: {}".format(args.log_level)) raise ValueError("Illegal log-level argument: {}".format(args.log_level))
if args.format not in garminexport.backup.export_formats: if args.format not in garminexport.backup.supported_export_formats:
raise ValueError( raise ValueError(
"Unrecognized export format: '{}'. Must be one of {}".format( "Unrecognized export format: '{}'. Must be one of {}".format(
args.format, garminexport.backup.export_formats)) args.format, garminexport.backup.supported_export_formats))
logging.root.setLevel(LOG_LEVELS[args.log_level]) logging.root.setLevel(LOG_LEVELS[args.log_level])

View File

@ -5,7 +5,7 @@ import os
from datetime import timedelta from datetime import timedelta
import garminexport.backup import garminexport.backup
from garminexport.backup import export_formats from garminexport.backup import supported_export_formats
from garminexport.garminclient import GarminClient from garminexport.garminclient import GarminClient
from garminexport.retryer import Retryer, ExponentialBackoffDelayStrategy, MaxRetriesStopStrategy from garminexport.retryer import Retryer, ExponentialBackoffDelayStrategy, MaxRetriesStopStrategy
@ -15,7 +15,7 @@ log = logging.getLogger(__name__)
def incremental_backup(username: str, def incremental_backup(username: str,
password: str = None, password: str = None,
backup_dir: str = os.path.join(".", "activities"), backup_dir: str = os.path.join(".", "activities"),
format: str = 'ALL', export_formats: str = 'ALL',
ignore_errors: bool = False, ignore_errors: bool = False,
max_retries: int = 7): max_retries: int = 7):
"""Performs (incremental) backups of activities for a given Garmin Connect account. """Performs (incremental) backups of activities for a given Garmin Connect account.
@ -23,7 +23,7 @@ def incremental_backup(username: str,
:param username: Garmin Connect user name :param username: Garmin Connect user name
:param password: Garmin Connect user password. Default: None. If not provided, would be asked interactively. :param password: Garmin Connect user password. Default: None. If not provided, would be asked interactively.
:param backup_dir: Destination directory for downloaded activities. Default: ./activities/". :param backup_dir: Destination directory for downloaded activities. Default: ./activities/".
:param format: Desired output formats (json_summary, json_details, gpx, tcx, fit). Default: ALL. :param export_formats: Desired output formats (json_summary, json_details, gpx, tcx, fit). Default: ALL.
:param ignore_errors: Ignore errors and keep going. Default: False. :param ignore_errors: Ignore errors and keep going. Default: False.
:param max_retries: The maximum number of retries to make on failed attempts to fetch an activity. :param max_retries: The maximum number of retries to make on failed attempts to fetch an activity.
Exponential backoff will be used, meaning that the delay between successive attempts Exponential backoff will be used, meaning that the delay between successive attempts
@ -34,8 +34,8 @@ def incremental_backup(username: str,
stored in the backup directory will be downloaded. stored in the backup directory will be downloaded.
""" """
# if no --format was specified, all formats are to be backed up # if no --format was specified, all formats are to be backed up
format = format if format else export_formats export_formats = export_formats if export_formats else supported_export_formats
log.info("backing up formats: %s", ", ".join(format)) log.info("backing up formats: %s", ", ".join(export_formats))
if not os.path.isdir(backup_dir): if not os.path.isdir(backup_dir):
os.makedirs(backup_dir) os.makedirs(backup_dir)
@ -54,7 +54,7 @@ def incremental_backup(username: str,
activities = set(retryer.call(client.list_activities)) activities = set(retryer.call(client.list_activities))
log.info("account has a total of %d activities", len(activities)) log.info("account has a total of %d activities", len(activities))
missing_activities = garminexport.backup.need_backup(activities, backup_dir, format) missing_activities = garminexport.backup.need_backup(activities, backup_dir, export_formats)
backed_up = activities - missing_activities backed_up = activities - missing_activities
log.info("%s contains %d backed up activities", backup_dir, len(backed_up)) log.info("%s contains %d backed up activities", backup_dir, len(backed_up))
@ -65,7 +65,7 @@ def incremental_backup(username: str,
log.info("backing up activity %s from %s (%d out of %d) ...", log.info("backing up activity %s from %s (%d out of %d) ...",
id, start, index + 1, len(missing_activities)) id, start, index + 1, len(missing_activities))
try: try:
garminexport.backup.download(client, activity, retryer, backup_dir, format) garminexport.backup.download(client, activity, retryer, backup_dir, export_formats)
except Exception as e: except Exception as e:
log.error("failed with exception: %s", e) log.error("failed with exception: %s", e)
if not ignore_errors: if not ignore_errors: