def find_lines_matching(pattern, sources=None): command = [ 'git', 'grep', '-n', # show line numbers '-I', # exclude binary files pattern, '--' ] if sources: command.extend(sources) command.extend(standard_exclusions()) command_trace.log(command) bufsize = 4096 proc = subprocess.Popen(command, bufsize=bufsize, stdout=subprocess.PIPE) result = [] try: while proc.poll() is None: result.append(proc.stdout.read(bufsize)) except KeyboardInterrupt: proc.terminate() proc.wait() return six.ensure_text(b''.join(result))
def is_revision(word): """Returns true if the given word is a revision name according to git.""" command = ['git', 'rev-parse', word, '--'] with open(os.devnull, 'w') as dev_null: command_trace.log(command) rc = subprocess.call(command, stdout=dev_null, stderr=dev_null) return rc == 0
def _list_files(parent): """Lists files contained directly in the parent directory.""" result = _list_files.cache.get(parent) if result is None: command_trace.log(['ls', parent]) result = os.listdir(parent) _list_files.cache[parent] = result return result
def xcresulttool(*args): """Runs xcresulttool and returns its output as a string.""" cmd = ['xcrun', 'xcresulttool'] cmd.extend(args) command_trace.log(cmd) return subprocess.check_output(cmd)
def find_xcode_major_version(): """Determines the major version number of Xcode.""" cmd = ['xcodebuild', '-version'] command_trace.log(cmd) result = str(subprocess.check_output(cmd)) version = result.split('\n', 1)[0] version = re.sub(r'Xcode ', '', version) version = re.sub(r'\..*', '', version) return int(version)
def _read_output(command): command_trace.log(command) if _dry_run: return checker.Result(0, '') proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output = proc.communicate('')[0] sc = proc.wait() return checker.Result(sc, output)
def _null_split_output(command): """Runs the given command and splits its output on the null byte.""" command_trace.log(command) result = six.ensure_text(subprocess.check_output(command)) return [name for name in result.rstrip().split('\0') if name]