From 807c446de2abda0001bc8d416d928bae434bd4e9 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Sat, 10 Jul 2010 00:45:28 +0000 Subject: [PATCH] Add exception management on invalid codereview.settings. Add gclient_utils.Error trapping. Review URL: http://codereview.chromium.org/2942005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@52029 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/gcl.py b/gcl.py index c98c11ee7..dc73e1a0a 100755 --- a/gcl.py +++ b/gcl.py @@ -175,9 +175,13 @@ def GetCodeReviewSetting(key): settings_file = GetCachedFile(CODEREVIEW_SETTINGS_FILE) if settings_file: for line in settings_file.splitlines(): - if not line or line.startswith("#"): + if not line or line.startswith('#'): continue - k, v = line.split(": ", 1) + if not ':' in line: + raise gclient_utils.Error( + '%s is invalid, please fix. It\'s content:\n\n%s' % + (CODEREVIEW_SETTINGS_FILE, settings_file)) + k, v = line.split(': ', 1) CODEREVIEW_SETTINGS[k] = v CODEREVIEW_SETTINGS.setdefault('__just_initialized', None) return CODEREVIEW_SETTINGS.get(key, "") @@ -1308,18 +1312,21 @@ def main(argv): # Create the directories where we store information about changelists if it # doesn't exist. - if not os.path.exists(GetInfoDir()): - os.mkdir(GetInfoDir()) - if not os.path.exists(GetChangesDir()): - os.mkdir(GetChangesDir()) - if not os.path.exists(GetCacheDir()): - os.mkdir(GetCacheDir()) - - if command: - return command(argv[1:]) - # Unknown command, try to pass that to svn - return CMDpassthru(argv) - + try: + if not os.path.exists(GetInfoDir()): + os.mkdir(GetInfoDir()) + if not os.path.exists(GetChangesDir()): + os.mkdir(GetChangesDir()) + if not os.path.exists(GetCacheDir()): + os.mkdir(GetCacheDir()) + + if command: + return command(argv[1:]) + # Unknown command, try to pass that to svn + return CMDpassthru(argv) + except gclient_utils.Error, e: + print('Got an exception') + print(str(e)) if __name__ == "__main__": sys.exit(main(sys.argv[1:]))