~gpanders/gandi-cli

143e789a445ad0ad81e54d889058f6ccb7fa770e — Greg Anders 2 months ago 0b7c2f4
Remove type hints
3 files changed, 13 insertions(+), 24 deletions(-)

M src/gandi/commands/alias.py
M src/gandi/commands/mbox.py
M src/gandi/console.py
M src/gandi/commands/alias.py => src/gandi/commands/alias.py +6 -11
@@ 1,13 1,9 @@
import argparse
import json
from typing import Dict, Optional, Set

import requests

from gandi.auth import GandiAuth


def create_command(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
def create_command(parser):
    subparser = parser.add_parser("alias", help="manage email aliases")
    subparser.add_argument("-i", "--id", metavar="MAILBOX_ID", type=str)
    subparser.add_argument("-d", "--domain", type=str)


@@ 18,10 14,9 @@ def create_command(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
    actions.add_argument("-r", "--remove", metavar="ALIAS", type=str)

    subparser.set_defaults(func=alias)
    return subparser


def alias(config: Dict[str, str], auth: GandiAuth, args: argparse.Namespace) -> bool:
def alias(config, auth, args):
    domain = args.domain if args.domain is not None else config["domain"]
    mailbox_id = args.id if args.id is not None else config["mailbox_id"]
    url = f"https://api.gandi.net/v5/email/mailboxes/{domain}/{mailbox_id}"


@@ 44,7 39,7 @@ def alias(config: Dict[str, str], auth: GandiAuth, args: argparse.Namespace) -> 
    raise AssertionError


def get_aliases(url: str, auth: GandiAuth) -> Optional[Set[str]]:
def get_aliases(url, auth):
    res = requests.get(url, auth=auth)
    if res.status_code != 200:
        return None


@@ 53,7 48,7 @@ def get_aliases(url: str, auth: GandiAuth) -> Optional[Set[str]]:
    return set(data["aliases"])


def add_alias(url: str, auth: GandiAuth, alias: str, aliases: Set[str]) -> bool:
def add_alias(url, auth, alias, aliases):
    if alias in aliases:
        print(f"Alias '{alias}' already exists")
        return False


@@ 65,7 60,7 @@ def add_alias(url: str, auth: GandiAuth, alias: str, aliases: Set[str]) -> bool:
    return True


def remove_alias(url: str, auth: GandiAuth, alias: str, aliases: Set[str]) -> bool:
def remove_alias(url, auth, alias, aliases):
    if alias not in aliases:
        print(f"Alias '{alias}' does not exist")
        return False


@@ 77,7 72,7 @@ def remove_alias(url: str, auth: GandiAuth, alias: str, aliases: Set[str]) -> bo
    return True


def update_aliases(url: str, auth: GandiAuth, aliases: Set[str]) -> bool:
def update_aliases(url, auth, aliases):
    res = requests.patch(url, json={"aliases": list(aliases)}, auth=auth)
    try:
        res.raise_for_status()

M src/gandi/commands/mbox.py => src/gandi/commands/mbox.py +3 -8
@@ 1,13 1,9 @@
import argparse
import json
from typing import Dict, List, Optional

import requests

from gandi.auth import GandiAuth


def create_command(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
def create_command(parser):
    subparser = parser.add_parser("mbox", help="manage email mailboxes")
    subparser.add_argument("-d", "--domain", type=str)



@@ 15,10 11,9 @@ def create_command(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
    actions.add_argument("-l", "--list", action="store_true")

    subparser.set_defaults(func=mbox)
    return subparser


def mbox(config: Dict[str, str], auth: GandiAuth, args: argparse.Namespace) -> bool:
def mbox(config, auth, args):
    try:
        domain = args.domain if args.domain is not None else config["domain"]
        url = f"https://api.gandi.net/v5/email/mailboxes/{domain}"


@@ 50,7 45,7 @@ def mbox(config: Dict[str, str], auth: GandiAuth, args: argparse.Namespace) -> b
    return True


def get_mailboxes(url: str, auth: GandiAuth) -> Optional[List[str]]:
def get_mailboxes(url, auth):
    res = requests.get(url, auth=auth)
    if res.status_code != 200:
        return None

M src/gandi/console.py => src/gandi/console.py +4 -5
@@ 4,13 4,12 @@ import logging
import os
import sys
from pathlib import Path
from typing import Dict

from gandi import __version__, commands
from gandi.auth import GandiAuth


def run() -> None:
def run():
    """Command line entry point"""
    args = parse_args()
    setup_logging(args)


@@ 21,7 20,7 @@ def run() -> None:
    sys.exit(0 if ret else 1)


def parse_args() -> argparse.Namespace:
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--config", type=Path, help="path to config file")
    parser.add_argument(


@@ 46,13 45,13 @@ def parse_args() -> argparse.Namespace:
    return args


def setup_logging(args: argparse.Namespace) -> None:
def setup_logging(args):
    """Setup logging"""
    level = logging.INFO if args.verbose else logging.WARNING
    logging.basicConfig(format="%(message)s", level=level)


def read_config(conf_file: Path = None) -> Dict[str, str]:
def read_config(conf_file=None):
    """Find and read configuration file"""
    if not conf_file:
        xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config")