Skip to content

Commit e848760

Browse files
committed
Support for hsi chgrp.
1 parent 7c1ac14 commit e848760

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

tests/test.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def exit():
6666
# TODO: Change the hpss directory to a dir that's accessable to everyone
6767
HPSS_PATH='/home/z/zshaheen/zstash_test'
6868

69-
7069
# Create files and directories
7170
print('Creating files.')
7271
if not os.path.exists('zstash_test'):
@@ -98,6 +97,20 @@ def exit():
9897
output, err = run_cmd(cmd)
9998
str_in(output+err, 'Transferring file to HPSS')
10099

100+
print('Testing chgrp')
101+
GROUP = 'acme'
102+
print('First, make sure that the files are not already in the {} group'.format(GROUP))
103+
cmd = 'hsi ls -l {}'.format(HPSS_PATH)
104+
output, err = run_cmd(cmd)
105+
str_not_in(output+err, GROUP)
106+
print('Running zstash chgrp')
107+
cmd = 'zstash chgrp -R {} {}'.format(GROUP, HPSS_PATH)
108+
output, err = run_cmd(cmd)
109+
print('Now check that the files are in the {} group'.format(GROUP))
110+
cmd = 'hsi ls -l {}'.format(HPSS_PATH)
111+
output, err = run_cmd(cmd)
112+
str_in(output+err, 'acme')
113+
101114
print('Running update on the newly created directory, nothing should happen')
102115
os.chdir('zstash_test')
103116
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
@@ -178,4 +191,3 @@ def exit():
178191
print('*'*40)
179192
print('All of the tests passed! :)')
180193
print('*'*40)
181-

zstash/chgrp.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
import argparse
3+
from hpss import hpss_chgrp
4+
5+
def chgrp():
6+
7+
# Parser
8+
parser = argparse.ArgumentParser(
9+
usage='zstash chgrp [<args>] group hpss_archive',
10+
description='Change the group of an HPSS repository.')
11+
parser.add_argument('group', type=str, help='new group name of file(s)')
12+
parser.add_argument('hpss', type=str, help='path to HPSS storage')
13+
parser.add_argument('-R', action='store_const', const=True, help='recurse through subdirectories')
14+
15+
args = parser.parse_args(sys.argv[2:])
16+
recurse = True if args.R else False
17+
hpss_chgrp(args.hpss, args.group, recurse)
18+

zstash/hpss.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from subprocess import Popen, PIPE
66

77

8-
# Put file to hpss
98
def hpss_put(hpss, file, keep=True):
9+
"""
10+
Put a file to the HPSS archive.
11+
"""
1012

1113
logging.info('Transferring file to HPSS: %s' % (file))
1214
path, name = os.path.split(file)
@@ -36,8 +38,10 @@ def hpss_put(hpss, file, keep=True):
3638
os.remove(file)
3739

3840

39-
# Get file from hpss
4041
def hpss_get(hpss, file):
42+
"""
43+
Get ia file from the HPSS archive.
44+
"""
4145

4246
logging.info('Transferring from HPSS: %s' % (file))
4347
path, name = os.path.split(file)
@@ -63,3 +67,22 @@ def hpss_get(hpss, file):
6367
# Back to original working directory
6468
if path != '':
6569
os.chdir(cwd)
70+
71+
def hpss_chgrp(hpss, group, recurse=False):
72+
"""
73+
Change the group of the HPSS archive.
74+
"""
75+
if recurse:
76+
cmd = 'hsi chgrp -R {} {}'.format(group, hpss)
77+
else:
78+
cmd = 'hsi chgrp {} {}'.format(group, hpss)
79+
80+
p1 = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
81+
(stdout, stderr) = p1.communicate()
82+
status = p1.returncode
83+
if status != 0:
84+
logging.error('Changing group of HPSS archive {} to {}'.format())
85+
logging.debug('stdout:\n%s', stdout)
86+
logging.debug('stderr:\n%s', stderr)
87+
raise Exception
88+

zstash/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from create import create
1010
from update import update
1111
from extract import extract
12+
from chgrp import chgrp
1213

1314

1415
# -----------------------------------------------------------------------------
@@ -39,6 +40,8 @@ def main():
3940
update()
4041
elif args.command == 'extract':
4142
extract()
43+
elif args.command == 'chgrp':
44+
chgrp()
4245
else:
4346
print 'Unrecognized command'
4447
parser.print_help()

0 commit comments

Comments
 (0)