-
Notifications
You must be signed in to change notification settings - Fork 219
add support for --search-filename and --terse (REVIEW) #1577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,7 +320,7 @@ def find_easyconfigs(path, ignore_dirs=None): | |
| return files | ||
|
|
||
|
|
||
| def search_file(paths, query, short=False, ignore_dirs=None, silent=False): | ||
| def search_file(paths, query, short=False, ignore_dirs=None, silent=False, filename_only=False, terse=False): | ||
| """ | ||
| Search for a particular file (only prints) | ||
| """ | ||
|
|
@@ -340,7 +340,8 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False): | |
| for path in paths: | ||
| hits = [] | ||
| hit_in_path = False | ||
| print_msg("Searching (case-insensitive) for '%s' in %s " % (query.pattern, path), log=_log, silent=silent) | ||
| if not terse: | ||
| print_msg("Searching (case-insensitive) for '%s' in %s " % (query.pattern, path), log=_log, silent=silent) | ||
|
|
||
| for (dirpath, dirnames, filenames) in os.walk(path, topdown=True): | ||
| for filename in filenames: | ||
|
|
@@ -349,7 +350,10 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False): | |
| var = "CFGS%d" % var_index | ||
| var_index += 1 | ||
| hit_in_path = True | ||
| hits.append(os.path.join(dirpath, filename)) | ||
| if filename_only: | ||
| hits.append(filename) | ||
| else: | ||
| hits.append(os.path.join(dirpath, filename)) | ||
|
|
||
| # do not consider (certain) hidden directories | ||
| # 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): | |
|
|
||
| hits = sorted(hits) | ||
|
|
||
| if hits: | ||
| if hits and not terse: | ||
| common_prefix = det_common_path_prefix(hits) | ||
| if short and common_prefix is not None and len(common_prefix) > len(var) * 2: | ||
| var_lines.append("%s=%s" % (var, common_prefix)) | ||
| hit_lines.extend([" * %s" % os.path.join('$%s' % var, fn[len(common_prefix) + 1:]) for fn in hits]) | ||
| else: | ||
| hit_lines.extend([" * %s" % fn for fn in hits]) | ||
|
|
||
| for line in var_lines + hit_lines: | ||
| print_msg(line, log=_log, silent=silent, prefix=False) | ||
| if terse: | ||
| for line in hits: | ||
| print line | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| else: | ||
| for line in var_lines + hit_lines: | ||
| print_msg(line, log=_log, silent=silent, prefix=False) | ||
|
|
||
|
|
||
| def compute_checksum(path, checksum_type=DEFAULT_CHECKSUM): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -362,13 +362,16 @@ def informative_options(self): | |
| 'choice', 'store_or_None', 'simple', ['simple', 'detailed']), | ||
| 'list-toolchains': ("Show list of known toolchains", | ||
| None, 'store_true', False), | ||
| 'search': ("Search for easyconfig files in the robot directory, print full paths", | ||
| None, 'store', None, {'metavar': 'STR'}), | ||
| 'search-short': ("Search for easyconfig files in the robot directory, print short paths", | ||
| None, 'store', None, 'S', {'metavar': 'STR'}), | ||
| 'search': ("Search for easyconfig files in the robot search path, print full paths", | ||
| None, 'store', None, {'metavar': 'REGEX'}), | ||
| 'search-filename': ("Search for easyconfig files in the robot search path, print only filenames", | ||
| None, 'store', None, {'metavar': 'REGEX'}), | ||
| 'search-short': ("Search for easyconfig files in the robot search path, print short paths", | ||
| None, 'store', None, 'S', {'metavar': 'REGEX'}), | ||
| 'show-default-configfiles': ("Show list of default config files", None, 'store_true', False), | ||
| 'show-default-moduleclasses': ("Show default module classes with description", | ||
| None, 'store_true', False), | ||
| 'terse': ("Terse output (machine-readable)", None, 'store_true', False), | ||
| }) | ||
|
|
||
| self.log.debug("informative_options: descr %s opts %s" % (descr, opts)) | ||
|
|
@@ -566,6 +569,10 @@ def postprocess(self): | |
| if not HAVE_AUTOPEP8: | ||
| raise EasyBuildError("Python 'autopep8' module required to reformat dumped easyconfigs as requested") | ||
|
|
||
| # some options imply enabling --terse | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain why in the comment because this two seem unrelated |
||
| if self.options.last_log: | ||
| self.options.terse = True | ||
|
|
||
| self._postprocess_external_modules_metadata() | ||
|
|
||
| self._postprocess_config() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, this changes functionally? You can now combine
--last-logwith--search?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, that's an unintended side-effect, but does it matter?
you can indeed combine these, but I don't think it makes a lot of sense to do it
doesn't hurt, so fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. Might bite us in the ass later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fine, there's lots of weird combo's of options you can make now.
Using
--last-logand--searchtogether won't break anything (I checked).