-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcommands.py
More file actions
80 lines (65 loc) · 2.07 KB
/
commands.py
File metadata and controls
80 lines (65 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
# This file is part of the CloudBlue Connect connect-cli.
# Copyright (c) 2019-2025 CloudBlue. All Rights Reserved.
import warnings
import click
from connect.cli.core import group
from connect.cli.core.config import pass_config
from connect.cli.core.terminal import console
from connect.cli.plugins.customer.export import dump_customers
from connect.cli.plugins.customer.sync import CustomerSynchronizer
@group(name='customer', short_help='Export/synchronize customers.')
def grp_customer():
pass # pragma: no cover
@grp_customer.command(
name='export',
short_help='Export customers to an excel file.',
)
@click.option(
'--output_path',
'-p',
'output_path',
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help='Directory where to store the export.',
)
@click.option(
'--out',
'-o',
'output_file',
type=click.Path(exists=False, file_okay=True, dir_okay=False),
help='Output Excel file name.',
)
@pass_config
def cmd_export_customers(config, output_path, output_file):
acc_id = config.active.id
outfile = dump_customers(
client=config.active.client,
output_file=output_file,
output_path=output_path,
account_id=acc_id,
)
console.secho(
f'\nCustomers of account {acc_id} have been successfully exported to {outfile}',
fg='green',
)
@grp_customer.command(
name='sync',
short_help='Synchronize customers from an excel file.',
)
@click.argument('input_file', metavar='input_file', nargs=1, required=True) # noqa: E304
@pass_config
def cmd_sync_customers(config, input_file):
acc_id = config.active.id
if '.xlsx' not in input_file:
input_file = f'{input_file}/{input_file}.xlsx'
synchronizer = CustomerSynchronizer(
client=config.active.client,
account_id=acc_id,
)
warnings.filterwarnings('ignore', category=UserWarning)
synchronizer.open(input_file, 'Customers')
synchronizer.sync()
synchronizer.save(input_file)
synchronizer.stats.print()
def get_group():
return grp_customer