File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
2+ import sys
23
34from gitopscli .cliparser import create_cli
45from gitopscli .commands .add_pr_comment import pr_comment_command
56from gitopscli .commands .create_preview import create_preview_command
67from gitopscli .commands .deploy import deploy_command
78from gitopscli .commands .sync_apps import sync_apps_command
9+ from gitopscli .gitops_exception import GitOpsException
810
911
1012def main ():
@@ -13,16 +15,19 @@ def main():
1315 args = create_cli ()
1416
1517 if args .command == "deploy" :
16- deploy_command (** vars (args ))
17-
18- if args .command == "sync-apps" :
19- sync_apps_command (** vars (args ))
20-
21- if args .command == "add-pr-comment" :
22- pr_comment_command (** vars (args ))
23-
24- if args .command == "create-preview" :
25- create_preview_command (** vars (args ))
18+ command = deploy_command
19+ elif args .command == "sync-apps" :
20+ command = sync_apps_command
21+ elif args .command == "add-pr-comment" :
22+ command = pr_comment_command
23+ elif args .command == "create-preview" :
24+ command = create_preview_command
25+
26+ try :
27+ command (** vars (args ))
28+ except GitOpsException as ex :
29+ logging .error (ex )
30+ sys .exit (1 )
2631
2732
2833if __name__ == "__main__" :
Original file line number Diff line number Diff line change 55
66from gitopscli .git .create_git import create_git
77from gitopscli .yaml .yaml_util import update_yaml_file , yaml_dump
8+ from gitopscli .gitops_exception import GitOpsException
89
910
1011def deploy_command (
@@ -46,7 +47,11 @@ def deploy_command(
4647 logging .info ("Master checkout successful" )
4748 git .new_branch (branch )
4849 logging .info ("Created branch %s" , branch )
50+
4951 full_file_path = git .get_full_file_path (file )
52+ if not os .path .isfile (full_file_path ):
53+ raise GitOpsException (f"No such file: { file } " )
54+
5055 updated_values = {}
5156 for key in values :
5257 value = values [key ]
Original file line number Diff line number Diff line change 88
99from gitopscli .git .create_git import create_git
1010from gitopscli .yaml .yaml_util import merge_yaml_element
11+ from gitopscli .gitops_exception import GitOpsException
1112
1213
1314def sync_apps_command (
@@ -92,7 +93,9 @@ def __find_apps_config_from_repo(apps_git, root_git):
9293 if "applications" in app_config_content and app_config_content ["applications" ] is not None :
9394 apps_from_other_repos += app_config_content ["applications" ].keys ()
9495 if found_app_config_file is None :
95- raise Exception (f"Could't find config file with .repository={ apps_git .get_clone_url ()} in apps/ directory" )
96+ raise GitOpsException (
97+ f"Could't find config file with .repository={ apps_git .get_clone_url ()} in apps/ directory"
98+ )
9699 return found_app_config_file , found_app_config_file_name , apps_from_other_repos
97100
98101
@@ -134,4 +137,4 @@ def __get_application_directories(full_file_path):
134137def __check_if_app_already_exists (apps_dirs , apps_from_other_repos ):
135138 for app_key in apps_dirs :
136139 if app_key in apps_from_other_repos :
137- raise Exception ( "application: " + app_key + " already exists in a different repository" )
140+ raise GitOpsException ( f "application: { app_key } already exists in a different repository" )
Original file line number Diff line number Diff line change 1+ class GitOpsException (Exception ):
2+ pass
You can’t perform that action at this time.
0 commit comments