mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Create lister.py.
Make module tools/lister.py which lists all files in a directory tracked by git. This is done because lister.py will be used by other scripts in the future which have to introspect files in the repository, like linters, static code checkers, etc.
This commit is contained in:
committed by
Tim Abbott
parent
5c810ad0bc
commit
6954eb072c
19
tools/lister.py
Normal file
19
tools/lister.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def list_files(targets=[]):
|
||||
"""
|
||||
List files tracked by git.
|
||||
Returns a list of files which are either in targets or in directories in targets.
|
||||
If targets is [], list of all tracked files in current directory is returned.
|
||||
"""
|
||||
cmdline = ['git', 'ls-files'] + targets
|
||||
|
||||
files_gen = (x.strip() for x in subprocess.check_output(cmdline, universal_newlines=True).split('\n'))
|
||||
# throw away empty lines and non-files (like symlinks)
|
||||
files = list(filter(os.path.isfile, files_gen))
|
||||
|
||||
return files
|
||||
Reference in New Issue
Block a user