install to qutebrowser's userscripts directory for easy access.

master
Harshad Sharma 7 years ago
parent 49d188e343
commit d591f93551

@ -19,7 +19,7 @@ def dump_to_log(request):
if args.kaboom: if args.kaboom:
raise KaboomError('Oh noes!') raise KaboomError('Oh noes!')
with open('qutescript.debug.log', 'a') as logfile: with open('qutescript.debug.log', 'a') as logfile:
line = json.dumps(request.dump()) line = json.dumps(request.as_dict())
logfile.writelines([line]) logfile.writelines([line])

@ -67,6 +67,7 @@ setup(
], ],
install_requires=[ install_requires=[
# eg: 'aspectlib==1.1.1', 'six>=1.7', # eg: 'aspectlib==1.1.1', 'six>=1.7',
'appdirs==1.4.3',
], ],
extras_require={ extras_require={
# eg: # eg:

@ -24,6 +24,9 @@ import os
parser = argparse.ArgumentParser(description='Qutebrowser userscript.') parser = argparse.ArgumentParser(description='Qutebrowser userscript.')
parser.add_argument('--install', action='store_true', parser.add_argument('--install', action='store_true',
help='Setup permissions and show install instructions.') help='Setup permissions and show install instructions.')
parser.add_argument('--bin', action='store',
help='Used with --install, sets up the command in '
'[AppDir]/qutebrowser/userscripts for easy access.')
class NoSubCommands(Exception): class NoSubCommands(Exception):
@ -42,8 +45,9 @@ def main_cli():
def main_install(): def main_install():
from .installer import install from .installer import install
args = parser.parse_args()
userscript_path = os.path.abspath(sys.argv[0]) userscript_path = os.path.abspath(sys.argv[0])
name = os.path.basename(userscript_path) name = args.bin or os.path.basename(userscript_path)
print(install(userscript_path, name=name)) print(install(userscript_path, name=name))
sys.exit(0) sys.exit(0)

@ -4,14 +4,20 @@ import sys
import os import os
import stat import stat
TEMPLATE = """\ REVIEW_TEMPLATE = """\
Qutebrowser userscript {name!r} was installed at: Qutebrowser userscript {name!r} was installed at:
{path} {userscripts_path!r}
You can try it out by running the command: You can try it out by running the command:
:spawn --userscript {interpreter}{path} :spawn --userscript {name}
"""
LOADER_TEMPLATE = """\
#!/usr/bin/env bash
{interpreter}"{path}" "$@"
""" """
@ -29,6 +35,23 @@ def get_interpreter():
return interpreter return interpreter
def link_to_qutebrowser_userscripts_directory(path, name):
import appdirs
appdir = appdirs.user_data_dir('qutebrowser', 'qutebrowser')
userscripts_dir = os.path.join(appdir, 'userscripts')
userscripts_path = os.path.join(userscripts_dir, name)
interpreter = get_interpreter()
if not os.path.exists(userscripts_dir):
os.makedirs(userscripts_dir, exist_ok=False)
with open(userscripts_path, 'w') as bin_file:
bin_file.write(LOADER_TEMPLATE.format(
interpreter=interpreter,
path=path,
))
setup_permissions(userscripts_path)
return userscripts_path
def install(path, name=None): def install(path, name=None):
""" """
Sets permissions for qutescript at path and returns Sets permissions for qutescript at path and returns
@ -38,5 +61,5 @@ def install(path, name=None):
name = name or os.path.basename(path) name = name or os.path.basename(path)
interpreter = get_interpreter() interpreter = get_interpreter()
setup_permissions(path) setup_permissions(path)
userscripts_path = link_to_qutebrowser_userscripts_directory(path, name)
return TEMPLATE.format(path=path, name=name, interpreter=interpreter) return REVIEW_TEMPLATE.format(userscripts_path=userscripts_path, name=name, interpreter=interpreter)

Loading…
Cancel
Save