Annotate tools/lister.py.

This commit is contained in:
Eklavya Sharma
2016-05-01 09:12:26 +05:30
parent 247cdf578b
commit 27f12b2de3
2 changed files with 11 additions and 5 deletions

View File

@@ -9,8 +9,10 @@ import re
from collections import defaultdict from collections import defaultdict
import argparse import argparse
from six.moves import filter from six.moves import filter
from typing import Union, List, Dict
def get_ftype(fpath, use_shebang): def get_ftype(fpath, use_shebang):
# type: (str, bool) -> str
ext = os.path.splitext(fpath)[1] ext = os.path.splitext(fpath)[1]
if ext: if ext:
return ext[1:] return ext[1:]
@@ -38,6 +40,7 @@ def get_ftype(fpath, use_shebang):
def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False, def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
exclude=[], group_by_ftype=False): exclude=[], group_by_ftype=False):
# type: (List[str], List[str], bool, bool, List[str], bool) -> Union[Dict[str, List[str]], List[str]]
""" """
List files tracked by git. List files tracked by git.
Returns a list of files which are either in targets or in directories in targets. Returns a list of files which are either in targets or in directories in targets.
@@ -63,7 +66,8 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
# throw away empty lines and non-files (like symlinks) # throw away empty lines and non-files (like symlinks)
files = list(filter(os.path.isfile, files_gen)) files = list(filter(os.path.isfile, files_gen))
result = defaultdict(list) if group_by_ftype else [] result_dict = defaultdict(list) # type: Dict[str, List[str]]
result_list = [] # type: List[str]
for fpath in files: for fpath in files:
# this will take a long time if exclude is very large # this will take a long time if exclude is very large
@@ -87,11 +91,14 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
continue continue
if group_by_ftype: if group_by_ftype:
result[filetype].append(fpath) result_dict[filetype].append(fpath)
else: else:
result.append(fpath) result_list.append(fpath)
return result if group_by_ftype:
return result_dict
else:
return result_list
if __name__=="__main__": if __name__=="__main__":
parser = argparse.ArgumentParser(description="List files tracked by git and optionally filter by type") parser = argparse.ArgumentParser(description="List files tracked by git and optionally filter by type")

View File

@@ -18,7 +18,6 @@ bots/zephyr_mirror_backend.py
docs/conf.py docs/conf.py
puppet/zulip_internal/files/postgresql/pg_backup_and_purge.py puppet/zulip_internal/files/postgresql/pg_backup_and_purge.py
tools/deprecated/ tools/deprecated/
tools/lister.py
zproject/ zproject/
zerver/lib/actions.py zerver/lib/actions.py
zerver/lib/bugdown/fenced_code.py zerver/lib/bugdown/fenced_code.py