-
Notifications
You must be signed in to change notification settings - Fork 14
Implementation of the find repo functionality #56
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
Changes from all commits
d3710a9
13d9a36
455f3db
9082c8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,7 +178,6 @@ def is_curdir_inside_path(base_path): | |
| self.local_repo = (meta['alias'], meta['uid']) | ||
| # Create a Repo object and add it to the list | ||
| repos_list.append(Repo(path=repo_path, meta=meta)) | ||
|
|
||
| return repos_list | ||
|
|
||
| def load_repos(self): | ||
|
|
@@ -1007,20 +1006,73 @@ def unregister_repo(self, repo_path): | |
| return {'return': 0} | ||
|
|
||
| def find(self, run_args): | ||
| repo = run_args.get('item', run_args.get('artifact')) | ||
| repo_split = repo.split(",") | ||
| if len(repo_split) > 1: | ||
| repo_uid = repo_split[1] | ||
| repo_name = repo_split[0] | ||
|
|
||
| lst = [] | ||
| for i in self.repos: | ||
| if repo_uid and i.meta['uid'] == repo_uid: | ||
| lst.append(i) | ||
| elif repo_name == i.meta['alias']: | ||
| lst.append(i) | ||
| try: | ||
| # Get repos_list using the existing method | ||
| repos_list = self.load_repos_and_meta() | ||
| if(run_args.get('item', run_args.get('artifact'))): | ||
|
Contributor
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. Do we need an if condition here since |
||
| repo = run_args.get('item', run_args.get('artifact')) | ||
| else: | ||
| repo = run_args.get('repo', run_args.get('item', run_args.get('artifact'))) | ||
|
|
||
| # Check if repo is None or empty | ||
| if not repo: | ||
| return {"return": 1, "error": "Please enter a Repo Alias, Repo UID, or Repo URL in one of the following formats:\n" | ||
| "- <repo_owner>@<repos_name>\n" | ||
| "- <repo_url>\n" | ||
| "- <repo_uid>\n" | ||
| "- <repo_alias>\n" | ||
| "- <repo_alias>,<repo_uid>"} | ||
|
|
||
| # Handle the different repo input formats | ||
| repo_name = None | ||
| repo_uid = None | ||
|
|
||
| # Check if the repo is in the format of a repo UID (alphanumeric string) | ||
| if self.is_uid(repo): | ||
| repo_uid = repo | ||
| if "," in repo: | ||
| repo_split = repo.split(",") | ||
| repo_name = repo_split[0] | ||
| if len(repo_split) > 1: | ||
| repo_uid = repo_split[1] | ||
| elif "@" in repo: | ||
| repo_name = repo | ||
| elif "github.com" in repo: | ||
| result = self.github_url_to_user_repo_format(repo) | ||
| if result["return"] == 0: | ||
| repo_name = result["value"] | ||
| else: | ||
| return result | ||
|
|
||
| # Check if repo_name exists in repos.json | ||
| matched_repo_path = None | ||
| for repo_obj in repos_list: | ||
| if repo_name and repo_name == os.path.basename(repo_obj.path) : | ||
| matched_repo_path = repo_obj | ||
| break | ||
|
|
||
| # Search through self.repos for matching repos | ||
| lst = [] | ||
| for i in self.repos: | ||
| if repo_uid and i.meta['uid'] == repo_uid: | ||
| lst.append(i) | ||
| elif repo_name == i.meta['alias']: | ||
| lst.append(i) | ||
| elif self.is_uid(repo) and not any(i.meta['uid'] == repo_uid for i in self.repos): | ||
|
Contributor
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. Does this looping create un-necessary complexity as we are already inside a loop which tries to do the same function in more generic way? |
||
| return {"return": 1, "error": f"No repository with UID: '{repo_uid}' was found"} | ||
| elif "," in repo and not matched_repo_path and not any(i.meta['uid'] == repo_uid for i in self.repos) and not any(i.meta['alias'] == repo_name for i in self.repos): | ||
|
Contributor
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. Same here. I think usage of @Sid9993 do you think the code would be more efficient and small if we use the below snippet with revised logic? |
||
| return {"return": 1, "error": f"No repository with alias: '{repo_name}' and UID: '{repo_uid}' was found"} | ||
| elif not matched_repo_path and not any(i.meta['alias'] == repo_name for i in self.repos) and not any(i.meta['uid'] == repo_uid for i in self.repos ): | ||
| return {"return": 1, "error": f"No repository with alias: '{repo_name}' was found"} | ||
|
|
||
| return {'return': 0, 'list': lst} | ||
| # Append the matched repo path | ||
| if(len(lst)==0): | ||
| lst.append(matched_repo_path) | ||
|
|
||
| return {'return': 0, 'list': lst} | ||
| except Exception as e: | ||
| # Return error message if any exception occurs | ||
| return {"return": 1, "error": str(e)} | ||
|
|
||
| def github_url_to_user_repo_format(self, url): | ||
| """ | ||
|
|
@@ -1462,14 +1514,14 @@ def mlcr(): | |
|
|
||
| def process_console_output(res, target, action, run_args): | ||
| if action == "find": | ||
| if "list" not in res: | ||
| return # Exit function if there's an error | ||
|
Contributor
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. The check for key
|
||
| if len(res['list']) == 0: | ||
| logger.warn(f"""No {target} entry found for the specified tags: {run_args['tags']}!""") | ||
| else: | ||
| for item in res['list']: | ||
| logger.info(f"""Item path: {item.path}""") | ||
|
|
||
|
|
||
|
|
||
| # Main CLI function | ||
| def main(): | ||
| parser = argparse.ArgumentParser(prog='mlc', description='A CLI tool for managing repos, scripts, and caches.') | ||
|
|
@@ -1511,9 +1563,8 @@ def main(): | |
| run_args = res['args_dict'] | ||
| if hasattr(args, 'repo') and args.repo: | ||
| run_args['repo'] = args.repo | ||
|
|
||
|
|
||
| if args.command in ['pull', 'rm', 'add']: | ||
|
|
||
| if args.command in ['pull', 'rm', 'add', 'find']: | ||
| if args.target == "repo": | ||
| run_args['repo'] = args.details | ||
|
|
||
|
|
||
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.
Won't the
load_repos_and_metabe automatically called when initialising theActionclass while runningmlc? I think it could be accessed throughself.repos_list.