Bug 1341207 - Use MachCommandConditions.is_{git,hg} for mach clobber python. r=chmanchester

--HG--
extra : rebase_source : 4b78d3857cca67455343847ab27902c5877e0a6e
This commit is contained in:
Mike Hommey 2017-02-21 16:04:08 +09:00
parent 3a2a54e7d2
commit 4f2c73ffd9
2 changed files with 12 additions and 6 deletions

View File

@ -777,16 +777,22 @@ class MachCommandConditions(object):
"""Must have a mercurial source checkout."""
if hasattr(cls, 'substs'):
top_srcdir = cls.substs.get('top_srcdir')
return top_srcdir and os.path.isdir(os.path.join(top_srcdir, '.hg'))
return False
elif hasattr(cls, 'topsrcdir'):
top_srcdir = cls.topsrcdir
else:
return False
return top_srcdir and os.path.isdir(os.path.join(top_srcdir, '.hg'))
@staticmethod
def is_git(cls):
"""Must have a git source checkout."""
if hasattr(cls, 'substs'):
top_srcdir = cls.substs.get('top_srcdir')
return top_srcdir and os.path.exists(os.path.join(top_srcdir, '.git'))
return False
elif hasattr(cls, 'topsrcdir'):
top_srcdir = cls.topsrcdir
else:
return False
return top_srcdir and os.path.exists(os.path.join(top_srcdir, '.git'))
class PathArgument(object):

View File

@ -695,9 +695,9 @@ class Clobber(MachCommandBase):
raise
if 'python' in what:
if os.path.isdir(mozpath.join(self.topsrcdir, '.hg')):
if conditions.is_hg(self):
cmd = ['hg', 'purge', '--all', '-I', 'glob:**.py[co]']
elif os.path.isdir(mozpath.join(self.topsrcdir, '.git')):
elif conditions.is_git(self):
cmd = ['git', 'clean', '-f', '-x', '*.py[co]']
else:
cmd = ['find', '.', '-type', 'f', '-name', '*.py[co]', '-delete']