PATH:
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
#!/usr/libexec/platform-python """Tools for invoking editors programmatically.""" from __future__ import print_function import locale import os.path import subprocess import tempfile from distutils.spawn import find_executable __all__ = [ 'edit', 'get_editor', 'EditorError', ] __version__ = '0.4' class EditorError(RuntimeError): pass def get_default_editors(): # TODO: Make platform-specific return [ 'vim', 'emacs', 'nano', ] def get_editor_args(editor): if editor in ['vim', 'gvim']: return '-f -o' elif editor == 'emacs': return '-nw' elif editor == 'gedit': return '-w --new-window' elif editor == 'nano': return '-R' else: return '' def get_platform_editor_var(): # TODO: Make platform specific return "$EDITOR" def get_editor(): # Get the editor from the environment. Prefer VISUAL to EDITOR editor = os.environ.get('VISUAL') or os.environ.get('EDITOR') if editor: return editor # None found in the environment. Fallback to platform-specific defaults. for ed in get_default_editors(): path = find_executable(ed) if path is not None: return path raise EditorError("Unable to find a viable editor on this system." "Please consider setting your %s variable" % get_platform_editor_var()) def edit(filename=None, contents=None): editor = get_editor() args = get_editor_args(os.path.basename(editor)) args = [editor] + args.split(' ') if filename is None: tmp = tempfile.NamedTemporaryFile() filename = tmp.name if contents is not None: with open(filename, mode='wb') as f: f.write(contents) args += [filename] proc = subprocess.Popen(args, close_fds=True) proc.communicate() with open(filename, mode='rb') as f: return f.read() def _get_editor(ns): print(get_editor()) def _edit(ns): contents = ns.contents if contents is not None: contents = contents.encode(locale.getpreferredencoding()) print(edit(filename=ns.path, contents=contents)) if __name__ == '__main__': import argparse ap = argparse.ArgumentParser() sp = ap.add_subparsers() cmd = sp.add_parser('get-editor') cmd.set_defaults(cmd=_get_editor) cmd = sp.add_parser('edit') cmd.set_defaults(cmd=_edit) cmd.add_argument('path', type=str, nargs='?') cmd.add_argument('--contents', type=str) ns = ap.parse_args() ns.cmd(ns)
[+]
filelock
[+]
jsonschema-3.2.0-py3.7.egg-info
[+]
clsummary
[+]
_distutils_hack
[+]
alembic-0.8.3-py3.7.egg-info
[+]
schema-0.7.1-py3.7.egg-info
[+]
setuptools
[+]
vendors_api
[-] schema.py
[edit]
[+]
pyparsing
[+]
cllimits_validator
[+]
importlib_metadata
[+]
idna
[-] PySocks-1.5.7-py3.7.egg-info
[edit]
[+]
certifi-2018.4.16-py3.7.egg-info
[+]
attrs-21.2.0-py3.7.egg-info
[+]
prettytable-0.7.2-py3.7.egg-info
[+]
clconfigure
[+]
pip
[+]
jinja2
[+]
xray
[+]
aiosignal
[+]
sentry_sdk-1.3.1-py3.7.egg-info
[+]
clevents
[-] editor.py
[edit]
[+]
filelock-0.0.0-py3.7.egg-info
[-] sockshandler.py
[edit]
[+]
pip-20.2.4.dist-info
[+]
ssa
[+]
raven
[+]
pyparsing-3.0.9.dist-info
[+]
babel
[+]
chardet-3.0.4-py3.7.egg-info
[+]
libpasteurize
[+]
__pycache__
[+]
cl_dom_collector
[+]
zipp-0.0.0-py3.7.egg-info
[-] docopt.py
[edit]
[+]
virtualenv
[-] six.py
[edit]
[+]
future
[-] zipp.py
[edit]
[+]
pkg_resources
[+]
jwt
[-] distlib-0.3.4-py3.7.egg-info
[edit]
[+]
docopt-0.6.2-py3.7.egg-info
[+]
attr
[+]
importlib_metadata-0.0.0-py3.7.egg-info
[-] typing_extensions.py
[edit]
[+]
clconfig
[+]
async_timeout-4.0.2-py3.7.egg-info
[+]
certifi
[+]
nose-1.3.7-py3.7.egg-info
[+]
charset_normalizer-2.0.12-py3.7.egg-info
[+]
async_timeout
[+]
aiosignal-1.2.0a0-py3.7.egg-info
[+]
requests
[+]
nose
[+]
clselect
[+]
sentry_sdk
[+]
python_editor-0.4-py3.7.egg-info
[+]
clsentry
[+]
Jinja2-3.0.3-py3.7.egg-info
[+]
libfuturize
[+]
clcommon
[+]
six-1.15.0-py3.7.egg-info
[+]
mako
[+]
cldashboard
[-] distutils-precedence.pth
[edit]
[+]
platformdirs
[+]
typing_extensions-3.7.4.3-py3.7.egg-info
[+]
lve_utils
[+]
pytz-2017.2-py3.7.egg-info
[+]
svgwrite-1.3.0-py3.7.egg-info
[+]
charset_normalizer
[+]
setuptools-58.3.0.dist-info
[+]
clveconfig
[+]
lvestats
[+]
clwizard
[+]
virtualenv-20.13.0-py3.7.egg-info
[+]
chardet
[+]
lvemanager
[-] socks.py
[edit]
[-] prettytable.py
[edit]
[+]
Babel-2.9.1-py3.7.egg-info
[+]
jsonschema
[+]
raven-6.3.0-py3.7.egg-info
[+]
alembic
[+]
urllib3
[+]
svgwrite
[+]
requests-2.26.0-py3.7.egg-info
[+]
clquota
[+]
urllib3-1.26.6-py3.7.egg-info
[+]
clselector
[+]
idna-2.5-py3.7.egg-info
[+]
Mako-1.1.0-py3.7.egg-info
[+]
..
[+]
pytz
[+]
platformdirs-0.0.0-py3.7.egg-info
[+]
cllimitslib_v2
[+]
future-0.17.0-py3.7.egg-info
[+]
distlib
[+]
PyJWT-2.1.0-py3.7.egg-info
[+]
past