Simplify routine used to get the list of files from git

This change remove duplicated code
This commit is contained in:
Gonzalo Odiard 2015-05-07 13:30:52 -03:00 committed by Sam Parkinson
parent 34b0e17e95
commit bbdebce0d4

View File

@ -169,6 +169,7 @@ class Packager(object):
os.mkdir(self.config.dist_dir) os.mkdir(self.config.dist_dir)
def get_files_in_git(self): def get_files_in_git(self):
git_ls = None
try: try:
git_ls = subprocess.Popen(['git', 'ls-files'], git_ls = subprocess.Popen(['git', 'ls-files'],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -176,37 +177,34 @@ class Packager(object):
except OSError: except OSError:
logging.warn('Packager: git is not installed, ' logging.warn('Packager: git is not installed, '
'fall back to filtered list') 'fall back to filtered list')
return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES)
stdout, _ = git_ls.communicate() if git_ls is not None:
if git_ls.returncode: stdout, _ = git_ls.communicate()
# Fall back to filtered list if git_ls.returncode:
logging.warn('Packager: this is not a git repository, ' # Fall back to filtered list
'fall back to filtered list') logging.warn('Packager: this is not a git repository, '
return list_files(self.config.source_dir, 'fall back to filtered list')
IGNORE_DIRS, IGNORE_FILES) elif stdout:
if stdout: # pylint: disable=E1103
# pylint: disable=E1103 git_output = [path.strip() for path in
git_output = [path.strip() for path in stdout.strip('\n').split('\n')]
stdout.strip('\n').split('\n')] files = []
files = [] for line in git_output:
for line in git_output: ignore = False
ignore = False for directory in IGNORE_DIRS:
for directory in IGNORE_DIRS: if line.startswith(directory + '/'):
if line.startswith(directory + '/'): ignore = True
ignore = True break
break if not ignore:
if not ignore: files.append(line)
files.append(line)
for pattern in IGNORE_FILES: for pattern in IGNORE_FILES:
files = [f for f in files if not fnmatch(f, pattern)] files = [f for f in files if not fnmatch(f, pattern)]
return files return files
else:
return list_files(self.config.source_dir, return list_files(self.config.source_dir,
IGNORE_DIRS, IGNORE_FILES) IGNORE_DIRS, IGNORE_FILES)
class XOPackager(Packager): class XOPackager(Packager):