MCPcopy Create free account
hub / github.com/gitless-vcs/gitless / page

Function page

gitless/cli/helpers.py:69–99  ·  view source on GitHub ↗
(fp, repo)

Source from the content-addressed store, hash-verified

67
68
69def page(fp, repo):
70 if not sys.stdout.isatty(): # we are being piped or redirected
71 if sys.platform != 'win32':
72 # Prevent Python from throwing exceptions on SIGPIPE
73 from signal import signal, SIGPIPE, SIG_DFL
74 signal(SIGPIPE, SIG_DFL)
75 # memory-friendly way to output contents of file to stdout
76 with open(fp, 'r') as f:
77 shutil.copyfileobj(f, sys.stdout)
78 return
79
80 # On Windows, we need to call 'more' through cmd.exe (with 'cmd'). The /C is
81 # so that the command window gets closed after 'more' finishes
82 default_pager = 'less' if sys.platform != 'win32' else 'cmd /C more'
83 try:
84 pager = repo.config['core.pager']
85 except KeyError:
86 pager = '' # empty string will evaluate to False below
87 pager = pager or os.environ.get('PAGER', None) or default_pager
88 cmd = shlex.split(pager) # split into constituents
89 if os.path.basename(cmd[0]) == 'less':
90 cmd.extend(['-r', '-f']) # append arguments
91
92 cmd.append(fp) # add file name to page command
93 try:
94 ret = subprocess.call(cmd, stdin=sys.stdin, stdout=sys.stdout)
95 if ret != 0:
96 pprint.err('Call to pager {0} failed'.format(pager))
97 except OSError:
98 pprint.err('Couldn\'t launch pager {0}'.format(pager))
99 pprint.err_exp('change the value of git\'s core.pager setting')
100
101
102class PathProcessor(argparse.Action):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected