Skip to content

Commit 4245d47

Browse files
committed
Small cleanup
1 parent 75e77c7 commit 4245d47

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

groups.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,6 @@ def rule_sram_migration(ctx: rule.Context, log_file: bool, dry_run: bool, conver
14121412
:param convert_group: Convert group to either 'SRAM' or 'non-SRAM' group.
14131413
:param group_name: Name of the group to be migrated
14141414
"""
1415-
1416-
14171415
if not user.is_rodsadmin(ctx):
14181416
log.write(ctx, "SRAM migration requires rodsadmin privileges")
14191417
return
@@ -1478,4 +1476,3 @@ def rule_sram_migration(ctx: rule.Context, log_file: bool, dry_run: bool, conver
14781476
msi.sudo_obj_meta_add(ctx, group_name, "-u", "sram_co", sram_co, "", "")
14791477
else:
14801478
log.write(ctx, "Could not convert group to {}. Invalid argument.".format(convert_group))
1481-

tools/sram/sram-migration-script.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,53 @@
44
This script should be run before SRAM external users sync so that the sync has accurate user information as input.
55
66
Example:
7-
To migrate SRAM groups to non-SRAM groups and output the results in a log file :
8-
python3 sram-migration-script.py -f sram-groups-to-non-sram.py
7+
To migrate SRAM groups to non-SRAM groups:
8+
python3 sram-migration-script.py -c non-sram -f sram-groups-to-non-sram.csv
99
10-
To output the results in a log file :
11-
python3 sram-migration-script.py -l -f sram-groups-to-non-sram.py
12-
13-
To dry run the migration script :
14-
python3 sram-migration-script.py -d -f sram-groups-to-non-sram.py
10+
To output the results in a log file:
11+
python3 sram-migration-script.py -c non-sram -f sram-groups-to-non-sram.csv -l
1512
13+
To dry run the migration script:
14+
python3 sram-migration-script.py -c non-sram -f sram-groups-to-non-sram.csv -d
1615
"""
1716
import argparse
1817
import subprocess
1918

2019

2120
def parse_args():
21+
"""Parse command-line arguments."""
2222
parser = argparse.ArgumentParser(
2323
prog="sram-migration-script.py",
2424
description=__doc__,
25-
formatter_class=argparse.RawTextHelpFormatter)
26-
parser.add_argument("-l", "--log-file", action='store_true',
27-
help="If log file parameter is true then write to log at: /var/lib/irods/log/sram-migration.log")
28-
parser.add_argument("-d", "--dry-run", action='store_true',
29-
help="Run the migration script offline.")
30-
parser.add_argument("-c", "--convert-group", type=str, required=True,
31-
help="Convert the group to either 'sram' or 'non-sram' group.")
32-
parser.add_argument("-f", "--file-name", type=str, required=True,
33-
help="CSV file containing SRAM group names to be migrated to non-SRAM group.")
25+
formatter_class=argparse.RawTextHelpFormatter
26+
)
27+
parser.add_argument(
28+
"-l", "--log-file",
29+
action='store_true',
30+
help="Write output to log file at /var/lib/irods/log/sram-migration.log"
31+
)
32+
parser.add_argument(
33+
"-d", "--dry-run",
34+
action='store_true',
35+
help="Run the migration script in dry-run mode without making changes"
36+
)
37+
parser.add_argument(
38+
"-c", "--convert-group",
39+
type=str,
40+
required=True,
41+
choices=['sram', 'non-sram'],
42+
help="Convert groups to either 'sram' or 'non-sram'"
43+
)
44+
parser.add_argument(
45+
"-f", "--file-name",
46+
type=str,
47+
required=True,
48+
help="Path to CSV file containing group names to be migrated"
49+
)
3450
return parser.parse_args()
3551

3652
def main():
53+
"""Execute the SRAM migration rule."""
3754
args = parse_args()
3855
rule_name = "/etc/irods/yoda-ruleset/tools/sram/sram-migration.r"
3956
log_loc = f"*log_loc={args.log_file if args.log_file else ''}"

tools/sram/sram-migration.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/irule -r irods_rule_engine_plugin-irods_rule_language-instance -F
22
#
3+
# Migrates groups between SRAM and non-SRAM by reading from a CSV file.
4+
#
35
import csv
46

57
def main(rule_args, callback, rei):
@@ -10,12 +12,11 @@ def main(rule_args, callback, rei):
1012

1113
with open(file_name, "r") as read_groups:
1214
groups = csv.reader(read_groups)
13-
1415

1516
for row in groups:
1617
callback.writeLine("stdout", row[0])
1718
callback.rule_sram_migration(log_loc, dry_run, convert_group, row[0])
1819

1920

2021
input *log_loc="", *dry_run="", *convert_group= "non-sram", *file_name="/etc/irods/yoda-ruleset/tools/sram/test-sram-migration.csv"
21-
output ruleExecOut
22+
output ruleExecOut

0 commit comments

Comments
 (0)