Skip to content

Commit ad570f6

Browse files
committed
Client: Add csv option to list scopes rucio#7415
1 parent e383672 commit ad570f6

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

lib/rucio/client/commands/bin_legacy/rucio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ def list_scopes(args, client, logger, console, spinner):
546546
spinner.start()
547547

548548
scopes = client.list_scopes()
549-
if cli_config == 'rich':
549+
550+
if args.csv:
551+
print(*(scope for scope in scopes), sep=',')
552+
elif cli_config == 'rich':
550553
table = generate_table([[scope] for scope in sorted(scopes)], headers=['SCOPE'], col_alignments=['left'])
551554
spinner.stop()
552555
print_output(table, console=console, no_pager=args.no_pager)
@@ -2476,6 +2479,7 @@ def get_parser():
24762479
''')
24772480

24782481
scope_list_parser.set_defaults(function=list_scopes)
2482+
scope_list_parser.add_argument("--csv", action='store_true', help='List scopes as a csv')
24792483

24802484
# The close command
24812485
close_parser = subparsers.add_parser('close', help='Close a dataset or container.')

lib/rucio/client/commands/bin_legacy/rucio_admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,10 @@ def list_scopes(args, client, logger, console, spinner):
768768
scopes = client.list_scopes_for_account(args.account)
769769
else:
770770
scopes = client.list_scopes()
771-
if cli_config == 'rich':
771+
772+
if args.csv:
773+
print(*(scope for scope in scopes if "mock" not in scopes), sep=',')
774+
elif cli_config == 'rich':
772775
scopes = [[scope] for scope in sorted(scopes) if 'mock' not in scope]
773776
table = generate_table(scopes, headers=['SCOPE'], col_alignments=['left'])
774777
spinner.stop()
@@ -2125,6 +2128,7 @@ def get_parser():
21252128
'\n')
21262129
list_scope_parser.set_defaults(which='list_scopes')
21272130
list_scope_parser.add_argument('--account', dest='account', action='store', help='Account name')
2131+
list_scope_parser.add_argument("--csv", action='store_true', help='List scopes as a csv')
21282132

21292133
# The config subparser
21302134
config_parser = subparsers.add_parser('config',

lib/rucio/client/commands/scope.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def usage_example(self) -> list[str]:
3939

4040
def list_namespace(self, parser: "ArgumentParser") -> None:
4141
parser.add_argument("-a", "--account", help="Account name for filtering, attribution")
42+
parser.add_argument("--csv", action="store_true", help="Output the list of scopes as a csv")
4243

4344
def add_namespace(self, parser: "ArgumentParser") -> None:
4445
parser.add_argument("-a", "--account", help="Account name for filtering, attribution", required=True)

tests/test_bin_rucio.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,35 @@ def test_add_scope(self):
205205
print(out, err)
206206
assert 'Added new scope to account: %s-%s\n' % (tmp_scp, tmp_acc) in out
207207

208+
def test_list_scopes(self):
209+
"""CLIENT(USER/ADMIN): List scope"""
210+
tmp_account = account_name_generator()
211+
execute(f'rucio-admin account add {tmp_account}')
212+
213+
tmp_scope = scope_name_generator()
214+
tmp_scope = tmp_scope.replace("mock", "testing") # admin filters out mock scopes
215+
execute(f'rucio-admin scope add --account {tmp_account} --scope {tmp_scope}')
216+
217+
cmd = "rucio-admin scope list"
218+
exitcode, out, err = execute(cmd)
219+
assert exitcode == 0
220+
assert tmp_scope in out.split('\n')
221+
222+
cmd = "rucio-admin scope list --csv"
223+
exitcode, out, err = execute(cmd)
224+
assert exitcode == 0
225+
assert tmp_scope in [o.rstrip('\n') for o in out.split(',')]
226+
227+
cmd = "rucio list-scopes"
228+
exitcode, out, err = execute(cmd)
229+
assert exitcode == 0
230+
assert tmp_scope in out.split('\n')
231+
232+
cmd = "rucio list-scopes --csv"
233+
exitcode, out, err = execute(cmd)
234+
assert exitcode == 0
235+
assert tmp_scope in [o.rstrip('\n') for o in out.split(',')]
236+
208237
def test_add_rse(self):
209238
"""CLIENT(ADMIN): Add RSE"""
210239
tmp_val = rse_name_generator()

0 commit comments

Comments
 (0)