69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
import argparse
|
|
import logging
|
|
import typing
|
|
import pathlib
|
|
|
|
import taiga_pycli.config
|
|
import taiga_pycli.service
|
|
from taiga_pycli.exceptions import (
|
|
AuthenticationError,
|
|
ValidationError,
|
|
NetworkError,
|
|
TryGoAPIError,
|
|
)
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
if typing.TYPE_CHECKING:
|
|
_SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
|
|
else:
|
|
_SubparserType = typing.Any
|
|
|
|
|
|
def setup_parser(subparsers: _SubparserType) -> None:
|
|
parser = subparsers.add_parser(
|
|
"upload", help="Upload an activity file to the server"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"file_path", type=pathlib.Path, help="Path to the activity file to upload"
|
|
)
|
|
|
|
parser.set_defaults(func=run)
|
|
|
|
|
|
def run(config: taiga_pycli.config.Config, args):
|
|
"""Run the upload command"""
|
|
try:
|
|
clnt = taiga_pycli.service.BackendService(config)
|
|
|
|
_logger.info(f"Uploading file: {args.file_path}")
|
|
|
|
activity_file = clnt.upload_activity_file(args.file_path)
|
|
|
|
print("Upload successful!")
|
|
print(f"File ID: {activity_file.id}")
|
|
print(f"Timestamp: {activity_file.timestamp}")
|
|
print(f"Created at: {activity_file.created_at}")
|
|
|
|
except AuthenticationError as e:
|
|
print(f"Authentication error: {e}")
|
|
print("Please run 'taiga login' first.")
|
|
return 1
|
|
except ValidationError as e:
|
|
print(f"Validation error: {e}")
|
|
return 1
|
|
except NetworkError as e:
|
|
print(f"Network error: {e}")
|
|
return 1
|
|
except TryGoAPIError as e:
|
|
print(f"API error: {e}")
|
|
return 1
|
|
except Exception as e:
|
|
_logger.error(f"Unexpected error during upload: {e}")
|
|
print(f"Unexpected error: {e}")
|
|
return 1
|
|
|
|
return 0
|