Skip to content

Commit 3d1c042

Browse files
committed
gufi_du updates
Added --inodes Added --separate-dirs Reduced number of --verbose prints
1 parent 7d905f5 commit 3d1c042

File tree

4 files changed

+327
-123
lines changed

4 files changed

+327
-123
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
122122
export GUFI_PYTHON_TEST_COVERAGE="coverage run -a"
123123
(${{ github.workspace }}/build/test/regression/gufi_distributed.sh || true) > /dev/null 2>&1
124+
(${{ github.workspace }}/build/test/regression/gufi_du.sh || true) > /dev/null 2>&1
124125
(${{ github.workspace }}/build/test/regression/gufi_find.sh || true) > /dev/null 2>&1
125126
(${{ github.workspace }}/build/test/regression/gufi_getfattr.sh || true) > /dev/null 2>&1
126127
(${{ github.workspace }}/build/test/regression/gufi_ls.sh || true) > /dev/null 2>&1

scripts/gufi_du

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def get_blocksize(value):
7474
str_val = gufi_common.get_blocksize(value)
7575

7676
units = 0 # number of chars to remove
77-
multiplier = 1024
7877
if str_val[-2:] == 'iB':
7978
units -= 2
8079
multiplier = 1024
@@ -123,6 +122,14 @@ def build_expression_parser():
123122
action='store_true',
124123
help='produce a grand total')
125124

125+
parser.add_argument('--inodes',
126+
action='store_true',
127+
help='list inode usage information instead of block usage')
128+
129+
parser.add_argument('-S', '--separate-dirs',
130+
action='store_true',
131+
help='for directories do not include size of subdirectories')
132+
126133
parser.add_argument('-s', '--summarize',
127134
action='store_true',
128135
help='display only a total for each argument')
@@ -138,35 +145,80 @@ def build_expression_parser():
138145
return parser
139146

140147
# process files/links
141-
def nondir(E_col, name):
148+
def nondir(args, name):
149+
if args.inodes:
150+
E_col = '1'
151+
elif args.apparent_size:
152+
E_col = 'size'
153+
else:
154+
E_col = 'blocks'
155+
142156
# isroot is set to 1 since the size should be used for --total
143157
return [
144158
'-y', '0',
145159
'-z', '0',
146160
'-E', 'SELECT level(), 1, {0}, rpath(sname, sroll) || \'/\' || name FROM {1} WHERE name == \'{2}\';'.format(E_col,
147-
gufi_common.VRPENTRIES,
148-
name),
161+
gufi_common.VRPENTRIES,
162+
name),
149163
]
150164

151165
# no flags
152166
# print self and all subdirectories
153-
def none(T_col):
167+
def none(args):
168+
if args.inodes:
169+
T_col = '{0}.totfiles + {0}.totlinks'
170+
elif args.apparent_size:
171+
T_col = '{0}.totsize'
172+
else:
173+
T_col = '{0}.totblocks'
174+
154175
return [
155176
'-a', '2', # run -T on all directories
156-
'-T', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1} LEFT JOIN {2} ON {1}.inode == {2}.inode;'.format(T_col,
177+
'-T', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1} LEFT JOIN {2} ON {1}.inode == {2}.inode;'.format(T_col.format(gufi_common.TREESUMMARY),
157178
gufi_common.TREESUMMARY,
158179
gufi_common.VRSUMMARY),
159180
]
160181

182+
# --separate-dirs
183+
def separate_dirs(args):
184+
if args.inodes:
185+
S_col = 'totfiles + totlinks'
186+
elif args.apparent_size:
187+
S_col = 'totsize'
188+
else:
189+
S_col = 'totblocks'
190+
191+
# summarize is turned on -> get only input path
192+
if args.summarize:
193+
return [
194+
'-y', '0',
195+
'-z', '0',
196+
'-S', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1} WHERE isroot == 1;'.format(S_col,
197+
gufi_common.VRSUMMARY),
198+
]
199+
200+
# get entire subtree
201+
return [
202+
'-S', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1};'.format(S_col,
203+
gufi_common.VRSUMMARY),
204+
]
205+
161206
# --summarize
162207
# print single size for each input path
163-
def summarize(T_col):
208+
def summarize(args):
209+
if args.inodes:
210+
T_col = '{0}.totfiles + {0}.totlinks'
211+
elif args.apparent_size:
212+
T_col = '{0}.totsize'
213+
else:
214+
T_col = '{0}.totblocks'
215+
164216
return [
165217
'-y', '0',
166218
'-z', '0',
167-
'-T', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1} LEFT JOIN {2} ON {1}.inode == {2}.inode WHERE {2}.isroot == 1;'.format(T_col,
168-
gufi_common.TREESUMMARY,
169-
gufi_common.VRSUMMARY),
219+
'-T', 'SELECT level(), isroot, {0}, rpath(sname, sroll) FROM {1} LEFT JOIN {2} ON {1}.inode == {2}.inode WHERE {2}.isroot == 1;'.format(T_col.format(gufi_common.TREESUMMARY),
220+
gufi_common.TREESUMMARY,
221+
gufi_common.VRSUMMARY),
170222
]
171223

172224
# argv[0] should be the command name
@@ -179,6 +231,9 @@ def run(argv, config_path):
179231
parser = build_expression_parser()
180232
args = parser.parse_args(argv[1:])
181233

234+
if args.inodes and (args.apparent_size or args.block_size):
235+
sys.stderr.write("warning: options --apparent-size and -b are ineffective with --inodes\n")
236+
182237
# cache the length of the indexroot + '/'
183238
INDEXROOT_LEN = len(config.indexroot) + 1
184239

@@ -232,14 +287,14 @@ def run(argv, config_path):
232287

233288
# append the queries to run
234289
if basename:
235-
query_cmd += nondir('size' if args.apparent_size else 'blocks', basename)
290+
query_cmd += nondir(args, basename)
236291
else:
237-
T_ACTUAL = '{0}.totblocks'.format(gufi_common.TREESUMMARY)
238-
T_APPARENT = '{0}.totsize'.format(gufi_common.TREESUMMARY)
239-
if args.summarize:
240-
query_cmd += summarize(T_APPARENT if args.apparent_size else T_ACTUAL)
292+
if args.separate_dirs:
293+
query_cmd += separate_dirs(args)
294+
elif args.summarize:
295+
query_cmd += summarize(args)
241296
else:
242-
query_cmd += none(T_APPARENT if args.apparent_size else T_ACTUAL)
297+
query_cmd += none(args)
243298

244299
query_cmd += [fullpath]
245300

@@ -265,13 +320,16 @@ def run(argv, config_path):
265320

266321
rows += 1
267322

268-
raw = int(raw) # block count or octets
323+
raw = int(raw)
269324

270-
# number of blocks used by this directory (including rounding up)
271-
# or logical size
272-
if not args.apparent_size:
273-
raw *= 512
274-
size = (raw // block_size) + ((raw % block_size) != 0) # round up
325+
if args.inodes:
326+
size = raw # count
327+
else:
328+
# number of blocks used by this directory (including rounding up)
329+
# or logical size
330+
if not args.apparent_size:
331+
raw *= 512
332+
size = (raw // block_size) + ((raw % block_size) != 0) # round up
275333

276334
# -s/--summarize removes individual prints
277335
if not args.summarize:
@@ -280,7 +338,7 @@ def run(argv, config_path):
280338
dir_size += size
281339

282340
if args.total:
283-
if (level == '0') and (isroot == '1'):
341+
if args.separate_dirs or ((not args.separate_dirs) and (level == '0') and (isroot == '1')):
284342
total_blocks += size
285343

286344
# -s/--summarize prints a combined size at the end of the current input path

0 commit comments

Comments
 (0)