diff options
author | davidovski <david@davidovski.xyz> | 2021-12-22 22:12:13 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2021-12-22 22:12:13 +0000 |
commit | 6394e9d1192e6171f6497675bad68bc1cb353084 (patch) | |
tree | f765a0bd4348c0213d4a8d9855565e8c96c710e8 /src/verbs/search.py | |
parent | da670d28e3b79d97d22234c7caeefdff01de2a2a (diff) |
added info, search and file queries
Diffstat (limited to 'src/verbs/search.py')
-rw-r--r-- | src/verbs/search.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/verbs/search.py b/src/verbs/search.py new file mode 100644 index 0000000..b67f5a1 --- /dev/null +++ b/src/verbs/search.py @@ -0,0 +1,38 @@ +import os +import sys +import colors +import util +import shutil + +from verbs.install import find_package, retrieve_package_info +from verbs.sync import sync + +def list_repos(repos, packages_dir, sources): + return [ + f"{repo}/{file}" for repo in repos for file in os.listdir(os.path.join(packages_dir, repo)) + ] + +def search(args, options, config): + if not options["l"]: + sync(args, options, config) + + if len(args) > 0: + packages = list_repos(config["repos"], config["dir"]["packages"], config["sources"]) + for package in args: + + # TODO fuzzy searching here + results = [p for p in packages if package.lower() in p.lower()] + + if len(results) > 0: + print(colors.GREEN + f"Search results for {package}:") + for r in results: + print(colors.LIGHT_GREEN + f"\t{r}") + + sys.exit(0) + else: + print(colors.RED + f"Package {package} could not be found") + sys.exit(1) + else: + print(colors.LIGHT_RED + "Nothing to do") + + |