Skip to content

Commit a80839a

Browse files
committed
gufi_du updates
Added --inodes Added --separate-dirs Reduced number of --verbose prints in tests doc updates
1 parent 7d905f5 commit a80839a

File tree

6 files changed

+475
-127
lines changed

6 files changed

+475
-127
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

docs/latex/sections/gufi_du.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ \subsection{Flags}
9898
\hline
9999
-c, -{}-total & produce a grand total \\
100100
\hline
101+
-{}-inodes & list inode usage information instead of block usage \\
102+
\hline
103+
-S, -{}-separate-dirs & for directories do not include size of subdirectories \\
104+
\hline
101105
-s, -{}-summarize & display only a total for each argument \\
102106
\hline
103107
\end{tabularx}

docs/latex/sections/user_env.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262

6363
\section{Environment}
6464

65-
Users interact with GUFI using \gufifind, \gufils, \gufistat, and
66-
\gufistats. These are wrapper scripts that access the actual
65+
Users interact with GUFI using \gufidu, \gufifind, \gufils, \gufistat,
66+
and \gufistats. These are wrapper scripts that access the actual
6767
implementations of these files.
6868

6969
These wrapper scripts use a configuration file (that is readable but

scripts/gufi_du

Lines changed: 82 additions & 26 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

@@ -257,21 +312,22 @@ def run(argv, config_path):
257312
if not line:
258313
break
259314

315+
# if line exists, there is content
260316
line = line.strip().decode()
261-
if line == '':
262-
continue
263-
264317
level, isroot, raw, name = line.split(DELIM, 3)
265318

266319
rows += 1
267320

268-
raw = int(raw) # block count or octets
321+
raw = int(raw)
269322

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
323+
if args.inodes:
324+
size = raw # count
325+
else:
326+
# number of blocks used by this directory (including rounding up)
327+
# or logical size
328+
if not args.apparent_size:
329+
raw *= 512
330+
size = (raw // block_size) + ((raw % block_size) != 0) # round up
275331

276332
# -s/--summarize removes individual prints
277333
if not args.summarize:
@@ -280,7 +336,7 @@ def run(argv, config_path):
280336
dir_size += size
281337

282338
if args.total:
283-
if (level == '0') and (isroot == '1'):
339+
if args.separate_dirs or ((not args.separate_dirs) and (level == '0') and (isroot == '1')):
284340
total_blocks += size
285341

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

0 commit comments

Comments
 (0)