Commit 6ebe68a7 authored by maruel@chromium.org's avatar maruel@chromium.org

Make the member variable 'protected' in the python sense.

Review URL: http://codereview.chromium.org/113899

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@17039 0039d316-1c4b-4281-b951-d872f2087c98
parent e1a524ff
...@@ -36,11 +36,6 @@ import gclient ...@@ -36,11 +36,6 @@ import gclient
import presubmit_canned_checks import presubmit_canned_checks
# Matches key/value (or "tag") lines in changelist descriptions.
_tag_line_re = re.compile(
'^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
class NotImplementedException(Exception): class NotImplementedException(Exception):
"""We're leaving placeholders in a bunch of places to remind us of the """We're leaving placeholders in a bunch of places to remind us of the
design of the API, but we have not implemented all of it yet. Implement as design of the API, but we have not implemented all of it yet. Implement as
...@@ -59,7 +54,6 @@ def normpath(path): ...@@ -59,7 +54,6 @@ def normpath(path):
return os.path.normpath(path) return os.path.normpath(path)
class OutputApi(object): class OutputApi(object):
"""This class (more like a module) gets passed to presubmit scripts so that """This class (more like a module) gets passed to presubmit scripts so that
they can specify various types of results. they can specify various types of results.
...@@ -413,36 +407,49 @@ class SvnAffectedFile(AffectedFile): ...@@ -413,36 +407,49 @@ class SvnAffectedFile(AffectedFile):
class GclChange(object): class GclChange(object):
"""A gcl change. See gcl.ChangeInfo for more info.""" """Describe a change.
Used directly by the presubmit scripts to query the current change being
tested.
Instance members:
tags: Dictionnary of KEY=VALUE pairs found in the change description.
self.KEY: equivalent to tags['KEY']
"""
# Matches key/value (or "tag") lines in changelist descriptions.
_tag_line_re = re.compile(
'^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
def __init__(self, change_info, repository_root=''): def __init__(self, change_info, repository_root=''):
self.name = change_info.name # Do not keep a reference to the original change_info.
self.full_description = change_info.description self._name = change_info.name
self.repository_root = repository_root self._full_description = change_info.description
self._repository_root = repository_root
# From the description text, build up a dictionary of key/value pairs # From the description text, build up a dictionary of key/value pairs
# plus the description minus all key/value or "tag" lines. # plus the description minus all key/value or "tag" lines.
self.description_without_tags = [] self._description_without_tags = []
self.tags = {} self.tags = {}
for line in change_info.description.splitlines(): for line in change_info.description.splitlines():
m = _tag_line_re.match(line) m = self._tag_line_re.match(line)
if m: if m:
self.tags[m.group('key')] = m.group('value') self.tags[m.group('key')] = m.group('value')
else: else:
self.description_without_tags.append(line) self._description_without_tags.append(line)
# Change back to text and remove whitespace at end. # Change back to text and remove whitespace at end.
self.description_without_tags = '\n'.join(self.description_without_tags) self._description_without_tags = '\n'.join(self._description_without_tags)
self.description_without_tags = self.description_without_tags.rstrip() self._description_without_tags = self._description_without_tags.rstrip()
self.affected_files = [ self._affected_files = [
SvnAffectedFile(info[1], info[0].strip(), repository_root) SvnAffectedFile(info[1], info[0].strip(), repository_root)
for info in change_info.files for info in change_info.files
] ]
def Change(self): def Change(self):
"""Returns the change name.""" """Returns the change name."""
return self.name return self._name
def DescriptionText(self): def DescriptionText(self):
"""Returns the user-entered changelist description, minus tags. """Returns the user-entered changelist description, minus tags.
...@@ -451,15 +458,15 @@ class GclChange(object): ...@@ -451,15 +458,15 @@ class GclChange(object):
(whitespace permitted before and around) is considered a tag line. Such (whitespace permitted before and around) is considered a tag line. Such
lines are stripped out of the description this function returns. lines are stripped out of the description this function returns.
""" """
return self.description_without_tags return self._description_without_tags
def FullDescriptionText(self): def FullDescriptionText(self):
"""Returns the complete changelist description including tags.""" """Returns the complete changelist description including tags."""
return self.full_description return self._full_description
def RepositoryRoot(self): def RepositoryRoot(self):
"""Returns the repository root for this change, as an absolute path.""" """Returns the repository root for this change, as an absolute path."""
return self.repository_root return self._repository_root
def __getattr__(self, attr): def __getattr__(self, attr):
"""Return keys directly as attributes on the object. """Return keys directly as attributes on the object.
...@@ -480,9 +487,9 @@ class GclChange(object): ...@@ -480,9 +487,9 @@ class GclChange(object):
[AffectedFile(path, action), AffectedFile(path, action)] [AffectedFile(path, action), AffectedFile(path, action)]
""" """
if include_dirs: if include_dirs:
affected = self.affected_files affected = self._affected_files
else: else:
affected = filter(lambda x: not x.IsDirectory(), self.affected_files) affected = filter(lambda x: not x.IsDirectory(), self._affected_files)
if include_deletes: if include_deletes:
return affected return affected
......
...@@ -137,7 +137,7 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -137,7 +137,7 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit_files) presubmit_files)
def testTagLineRe(self): def testTagLineRe(self):
m = presubmit._tag_line_re.match(' BUG =1223, 1445 \t') m = presubmit.GclChange._tag_line_re.match(' BUG =1223, 1445 \t')
self.failUnless(m) self.failUnless(m)
self.failUnlessEqual(m.group('key'), 'BUG') self.failUnlessEqual(m.group('key'), 'BUG')
self.failUnlessEqual(m.group('value'), '1223, 1445') self.failUnlessEqual(m.group('value'), '1223, 1445')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment