Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1045)

Side by Side Diff: gclient.py

Issue 113968: Add code to handle errors in .gclient configuration files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2008 Google Inc. All Rights Reserved. 3 # Copyright 2008 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 def __init__(self, root_dir, options): 933 def __init__(self, root_dir, options):
934 self._root_dir = root_dir 934 self._root_dir = root_dir
935 self._options = options 935 self._options = options
936 self._config_content = None 936 self._config_content = None
937 self._config_dict = {} 937 self._config_dict = {}
938 self._deps_hooks = [] 938 self._deps_hooks = []
939 939
940 def SetConfig(self, content): 940 def SetConfig(self, content):
941 self._config_dict = {} 941 self._config_dict = {}
942 self._config_content = content 942 self._config_content = content
943 exec(content, self._config_dict) 943 try:
944 exec(content, self._config_dict)
945 except SyntaxError, e:
946 try:
947 # Try to construct a human readable error message
948 error_message = [
949 'There is a syntax error in your configuration file.',
950 'Line #%s, character %s:' % (e.lineno, e.offset),
951 '"%s"' % re.sub(r'[\r\n]*$', '', e.text) ]
952 except:
953 # Something went wrong, re-raise the original exception
954 raise e
955 else:
956 # Raise a new exception with the human readable message:
957 raise Error('\n'.join(error_message))
944 958
945 def SaveConfig(self): 959 def SaveConfig(self):
946 FileWrite(os.path.join(self._root_dir, self._options.config_filename), 960 FileWrite(os.path.join(self._root_dir, self._options.config_filename),
947 self._config_content) 961 self._config_content)
948 962
949 def _LoadConfig(self): 963 def _LoadConfig(self):
950 client_source = FileRead(os.path.join(self._root_dir, 964 client_source = FileRead(os.path.join(self._root_dir,
951 self._options.config_filename)) 965 self._options.config_filename))
952 self.SetConfig(client_source) 966 self.SetConfig(client_source)
953 967
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1736
1723 if "__main__" == __name__: 1737 if "__main__" == __name__:
1724 try: 1738 try:
1725 result = Main(sys.argv) 1739 result = Main(sys.argv)
1726 except Error, e: 1740 except Error, e:
1727 print >> sys.stderr, "Error: %s" % str(e) 1741 print >> sys.stderr, "Error: %s" % str(e)
1728 result = 1 1742 result = 1
1729 sys.exit(result) 1743 sys.exit(result)
1730 1744
1731 # vim: ts=2:sw=2:tw=80:et: 1745 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698