Revision 99c11993 snf-pithos-app/pithos/api/management/commands/pithos-manage-accounts.py
b/snf-pithos-app/pithos/api/management/commands/pithos-manage-accounts.py | ||
---|---|---|
38 | 38 |
from pithos.api.swiss_army import SwissArmy |
39 | 39 |
|
40 | 40 |
|
41 |
def double_list_str(l): |
|
42 |
return '\n'.join(', '.join(sublist) for sublist in l) |
|
43 |
|
|
41 | 44 |
class Command(NoArgsCommand): |
42 | 45 |
help = "Quotas migration helper" |
43 | 46 |
|
44 | 47 |
option_list = NoArgsCommand.option_list + ( |
45 |
make_option('--duplicate', |
|
48 |
make_option('--list-duplicate',
|
|
46 | 49 |
dest='duplicate-accounts', |
47 | 50 |
action="store_true", |
48 |
default=True,
|
|
51 |
default=False,
|
|
49 | 52 |
help="Display case insensitive duplicate accounts."), |
50 |
make_option('--existing',
|
|
53 |
make_option('--list-all',
|
|
51 | 54 |
dest='existing-accounts', |
52 | 55 |
action="store_true", |
53 | 56 |
default=False, |
... | ... | |
56 | 59 |
dest='merge_accounts', |
57 | 60 |
action='store_true', |
58 | 61 |
default=False, |
59 |
help="Merge SOURCE_ACCOUNT and DEST_ACCOUNT."),
|
|
62 |
help="Merge SRC_ACCOUNT and DEST_ACCOUNT."),
|
|
60 | 63 |
make_option('--delete-account', |
61 | 64 |
dest='delete_account', |
62 | 65 |
action='store', |
63 |
help="Account to be deleted."),
|
|
66 |
help="Delete DELETE_ACCOUNT."),
|
|
64 | 67 |
make_option('--src-account', |
65 | 68 |
dest='src_account', |
66 | 69 |
action='store', |
... | ... | |
68 | 71 |
make_option('--dest-account', |
69 | 72 |
dest='dest_account', |
70 | 73 |
action='store', |
71 |
help="Account where SOURCE_ACCOUNT contents will move."),
|
|
74 |
help="Account where SRC_ACCOUNT contents will be copied."),
|
|
72 | 75 |
make_option('--dry', |
73 | 76 |
dest='dry', |
74 | 77 |
action="store_true", |
... | ... | |
79 | 82 |
def handle(self, *args, **options): |
80 | 83 |
try: |
81 | 84 |
utils = SwissArmy() |
82 |
self.strict = options.get('strict') |
|
83 | 85 |
self.dry = options.get('dry') |
84 | 86 |
|
87 |
if not options.get('duplicate-accounts') and \ |
|
88 |
not options.get('existing-accounts') and \ |
|
89 |
not options.get('merge_accounts') and \ |
|
90 |
not options.get('delete_account'): |
|
91 |
self.print_help('pithos-manage-accounts', '') |
|
92 |
|
|
85 | 93 |
if options.get('duplicate-accounts') and \ |
86 | 94 |
not options.get('existing-accounts') and \ |
87 | 95 |
not options.get('merge_accounts') and \ |
88 | 96 |
not options.get('delete_account'): |
89 | 97 |
duplicates = utils.duplicate_accounts() |
90 | 98 |
if duplicates: |
91 |
msg = "The following case insensitive duplicates found: %r"
|
|
92 |
raise CommandError(msg % duplicates)
|
|
99 |
msg = "The following case insensitive duplicates found:\n%s"
|
|
100 |
raise CommandError(msg % double_list_str(duplicates))
|
|
93 | 101 |
else: |
94 | 102 |
print "No duplicate accounts are found." |
95 | 103 |
|
... | ... | |
111 | 119 |
only_stats=True) |
112 | 120 |
|
113 | 121 |
confirm = raw_input("Type 'yes' if you are sure you want" |
114 |
" to remove those entries: ") |
|
122 |
" to move those entries to %s: " %\ |
|
123 |
dest_account) |
|
115 | 124 |
if not confirm == 'yes': |
116 | 125 |
return |
117 | 126 |
else: |
Also available in: Unified diff