4 import os, re, platform, subprocess, sys
10 system = platform.system()
11 if system ==
'Linux' and "microsoft" not in platform.uname()[3].lower():
18 Yield all files found in root, using relative names ('root/a' would be yielded as 'a') 20 for (path,subdirs,leafs)
in os.walk( root ):
23 yield os.path.relpath( path +
'/' + leaf, root ).replace(
'\\',
'/' )
27 Yield all files in given directory (including sub-directories) that fit the given mask 28 :param dir: directory in which to search 29 :param mask: mask to compare file names to 31 pattern = re.compile( mask )
33 if pattern.search( leaf ):
38 :param path_to_file: path to a file 39 :return: whether the file is an executable or not 43 return os.access(path_to_file, os.X_OK)
45 return path_to_file.endswith(
'.exe')
53 def _grep( pattern, lines, context ):
55 helper function for grep 61 match = pattern.search( line )
63 context[
'index'] = index
64 context[
'line'] = line
65 context[
'match'] = match
74 pattern = re.compile( expr )
77 context[
'filename'] = filename
78 with open( filename, errors =
'ignore' )
as file:
83 with open( filename, errors =
'ignore' )
as file:
def remove_newlines(lines)
def is_executable(path_to_file)
def _grep(pattern, lines, context)