Skip to content

Commit 20caa7b

Browse files
committed
add support for --search-filename and --terse
1 parent 6aff22f commit 20caa7b

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

easybuild/main.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def main(args=None, logfile=None, do_build=None, testing=False):
178178

179179
# initialise logging for main
180180
global _log
181-
_log, logfile = init_logging(logfile, logtostdout=options.logtostdout, silent=testing or options.last_log)
181+
_log, logfile = init_logging(logfile, logtostdout=options.logtostdout, silent=testing or options.terse)
182182

183183
# disallow running EasyBuild as root
184184
if os.getuid() == 0:
@@ -223,22 +223,13 @@ def main(args=None, logfile=None, do_build=None, testing=False):
223223
# print location to last log file, and exit
224224
last_log = find_last_log(logfile) or '(none)'
225225
print_msg(last_log, log=_log, prefix=False)
226-
cleanup(logfile, eb_tmpdir, testing, silent=True)
227-
sys.exit(0)
228226

229227
# check whether packaging is supported when it's being used
230228
if options.package:
231229
check_pkg_support()
232230
else:
233231
_log.debug("Packaging not enabled, so not checking for packaging support.")
234232

235-
# update session state
236-
eb_config = eb_go.generate_cmd_line(add_default=True)
237-
modlist = session_module_list(testing=testing) # build options must be initialized first before 'module list' works
238-
init_session_state.update({'easybuild_configuration': eb_config})
239-
init_session_state.update({'module_list': modlist})
240-
_log.debug("Initial session state: %s" % init_session_state)
241-
242233
# GitHub integration
243234
if options.review_pr or options.new_pr or options.update_pr:
244235
if options.review_pr:
@@ -254,18 +245,31 @@ def main(args=None, logfile=None, do_build=None, testing=False):
254245
sys.exit(0)
255246

256247
# search for easyconfigs, if a query is specified
257-
query = options.search or options.search_short
248+
query = options.search or options.search_filename or options.search_short
258249
if query:
259-
search_easyconfigs(query, short=not options.search)
250+
search_easyconfigs(query, short=options.search_short, filename_only=options.search_filename,
251+
terse=options.terse)
252+
253+
# non-verbose cleanup and exit after printing terse info
254+
if options.terse:
255+
cleanup(logfile, eb_tmpdir, testing, silent=True)
256+
sys.exit(0)
257+
258+
# update session state
259+
eb_config = eb_go.generate_cmd_line(add_default=True)
260+
modlist = session_module_list(testing=testing) # build options must be initialized first before 'module list' works
261+
init_session_state.update({'easybuild_configuration': eb_config})
262+
init_session_state.update({'module_list': modlist})
263+
_log.debug("Initial session state: %s" % init_session_state)
260264

261265
# determine easybuild-easyconfigs package install path
262266
easyconfigs_pkg_paths = get_paths_for(subdir=EASYCONFIGS_PKG_SUBDIR)
263267
if not easyconfigs_pkg_paths:
264268
_log.warning("Failed to determine install path for easybuild-easyconfigs package.")
265269

266270
# command line options that do not require any easyconfigs to be specified
267-
no_ec_opts = [options.aggregate_regtest, options.new_pr, options.review_pr, options.search, options.search_short,
268-
options.regtest, options.update_pr]
271+
no_ec_opts = [options.aggregate_regtest, options.new_pr, options.review_pr, options.search,
272+
options.search_filename, options.search_short, options.regtest, options.update_pr]
269273

270274
# determine paths to easyconfigs
271275
paths = det_easyconfig_paths(orig_paths)

easybuild/tools/filetools.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def find_easyconfigs(path, ignore_dirs=None):
320320
return files
321321

322322

323-
def search_file(paths, query, short=False, ignore_dirs=None, silent=False):
323+
def search_file(paths, query, short=False, ignore_dirs=None, silent=False, filename_only=False, terse=False):
324324
"""
325325
Search for a particular file (only prints)
326326
"""
@@ -340,7 +340,8 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False):
340340
for path in paths:
341341
hits = []
342342
hit_in_path = False
343-
print_msg("Searching (case-insensitive) for '%s' in %s " % (query.pattern, path), log=_log, silent=silent)
343+
if not terse:
344+
print_msg("Searching (case-insensitive) for '%s' in %s " % (query.pattern, path), log=_log, silent=silent)
344345

345346
for (dirpath, dirnames, filenames) in os.walk(path, topdown=True):
346347
for filename in filenames:
@@ -349,7 +350,10 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False):
349350
var = "CFGS%d" % var_index
350351
var_index += 1
351352
hit_in_path = True
352-
hits.append(os.path.join(dirpath, filename))
353+
if filename_only:
354+
hits.append(filename)
355+
else:
356+
hits.append(os.path.join(dirpath, filename))
353357

354358
# do not consider (certain) hidden directories
355359
# note: we still need to consider e.g., .local !
@@ -359,16 +363,20 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False):
359363

360364
hits = sorted(hits)
361365

362-
if hits:
366+
if hits and not terse:
363367
common_prefix = det_common_path_prefix(hits)
364368
if short and common_prefix is not None and len(common_prefix) > len(var) * 2:
365369
var_lines.append("%s=%s" % (var, common_prefix))
366370
hit_lines.extend([" * %s" % os.path.join('$%s' % var, fn[len(common_prefix) + 1:]) for fn in hits])
367371
else:
368372
hit_lines.extend([" * %s" % fn for fn in hits])
369373

370-
for line in var_lines + hit_lines:
371-
print_msg(line, log=_log, silent=silent, prefix=False)
374+
if terse:
375+
for line in hits:
376+
print line
377+
else:
378+
for line in var_lines + hit_lines:
379+
print_msg(line, log=_log, silent=silent, prefix=False)
372380

373381

374382
def compute_checksum(path, checksum_type=DEFAULT_CHECKSUM):

easybuild/tools/options.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,16 @@ def informative_options(self):
362362
'choice', 'store_or_None', 'simple', ['simple', 'detailed']),
363363
'list-toolchains': ("Show list of known toolchains",
364364
None, 'store_true', False),
365-
'search': ("Search for easyconfig files in the robot directory, print full paths",
366-
None, 'store', None, {'metavar': 'STR'}),
367-
'search-short': ("Search for easyconfig files in the robot directory, print short paths",
368-
None, 'store', None, 'S', {'metavar': 'STR'}),
365+
'search': ("Search for easyconfig files in the robot search path, print full paths",
366+
None, 'store', None, {'metavar': 'REGEX'}),
367+
'search-filename': ("Search for easyconfig files in the robot search path, print only filenames",
368+
None, 'store', None, {'metavar': 'REGEX'}),
369+
'search-short': ("Search for easyconfig files in the robot search path, print short paths",
370+
None, 'store', None, 'S', {'metavar': 'REGEX'}),
369371
'show-default-configfiles': ("Show list of default config files", None, 'store_true', False),
370372
'show-default-moduleclasses': ("Show default module classes with description",
371373
None, 'store_true', False),
374+
'terse': ("Terse output (machine-readable)", None, 'store_true', False),
372375
})
373376

374377
self.log.debug("informative_options: descr %s opts %s" % (descr, opts))
@@ -566,6 +569,10 @@ def postprocess(self):
566569
if not HAVE_AUTOPEP8:
567570
raise EasyBuildError("Python 'autopep8' module required to reformat dumped easyconfigs as requested")
568571

572+
# some options imply enabling --terse
573+
if self.options.last_log:
574+
self.options.terse = True
575+
569576
self._postprocess_external_modules_metadata()
570577

571578
self._postprocess_config()

easybuild/tools/robot.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def resolve_dependencies(easyconfigs, retain_all_deps=False, minimal_toolchains=
258258
return ordered_ecs
259259

260260

261-
def search_easyconfigs(query, short=False):
261+
def search_easyconfigs(query, short=False, filename_only=False, terse=False):
262262
"""Search for easyconfigs, if a query is provided."""
263263
robot_path = build_option('robot_path')
264264
if robot_path:
@@ -267,4 +267,5 @@ def search_easyconfigs(query, short=False):
267267
search_path = [os.getcwd()]
268268
ignore_dirs = build_option('ignore_dirs')
269269
silent = build_option('silent')
270-
search_file(search_path, query, short=short, ignore_dirs=ignore_dirs, silent=silent)
270+
search_file(search_path, query, short=short, ignore_dirs=ignore_dirs, silent=silent, filename_only=filename_only,
271+
terse=terse)

0 commit comments

Comments
 (0)