Commit b45e5e40 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Romain Bignon
Browse files

Make the bash completion into a static file

Since we already generate the man pages automatically,
we can generate the bash completions too.
It is much faster and does not risk making any network requests.

fixes #194
parent 779ed946
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2014 Laurent Bachelier
# Copyright(C) 2010-2018 Laurent Bachelier
#
# This file is part of weboob.
#
......@@ -28,13 +28,14 @@
import sys
import tempfile
import time
from datetime import datetime
from weboob.tools.application.base import Application
from textwrap import dedent
from weboob.tools.application.base import Application
BASE_PATH = os.path.join(os.path.dirname(__file__), os.pardir)
DEST_DIR = 'man'
COMP_PATH = 'tools/weboob_bash_completion'
class ManpageHelpFormatter(optparse.HelpFormatter):
......@@ -107,6 +108,7 @@ def format_option_strings(self, option):
def main():
scripts_path = os.path.join(BASE_PATH, "scripts")
files = os.listdir(scripts_path)
completions = dict()
# Create a fake "scripts" modules to import the scripts into
sys.modules["scripts"] = imp.new_module("scripts")
......@@ -132,11 +134,12 @@ def main():
# Find the applications we can handle
for klass in script.__dict__.values():
if inspect.isclass(klass) and issubclass(klass, Application) and klass.VERSION:
analyze_application(klass, fname)
completions[fname] = analyze_application(klass, fname)
finally:
# Cleanup compiled files if needed
if (os.path.isfile(tmpfile + "c")):
os.unlink(tmpfile + "c")
write_completions(completions)
def format_title(title):
......@@ -241,5 +244,37 @@ def analyze_application(app, script_name):
manfile.write('%s\n' % line.lstrip().encode('utf-8'))
print("wrote %s/%s.1" % (DEST_DIR, script_name))
return application._shell_completion_items()
def write_completions(completions):
compscript = dedent('''
# Weboob completion for Bash (automatically generated by tools/make_man.sh)
#
# vim: filetype=sh expandtab softtabstop=4 shiftwidth=4
#
# This file is part of weboob.
#
# This script can be distributed under the same license as the
# weboob or bash packages.
''')
for name, items in completions.items():
compscript += dedent('''
_weboob_{1}()
{{
local cur args
COMPREPLY=()
cur=${{COMP_WORDS[COMP_CWORD]}}
args="{2}"
COMPREPLY=( $(compgen -o default -W "${{args}}" -- "$cur" ) )
}}
complete -F _weboob_{1} {0}
''').format(name, name.replace('-', '_'), ' '.join(items))
with open(os.path.join(BASE_PATH, COMP_PATH), 'w') as f:
f.write(compscript)
if __name__ == '__main__':
sys.exit(main())
# Weboob completion for Bash
# Weboob completion for Bash (automatically generated by tools/make_man.sh)
#
# vim: filetype=sh expandtab softtabstop=4 shiftwidth=4
#
# Copyright(C) 2010-2011 Christophe Benz
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
#
# This script can be distributed under the same license as the
# weboob or bash packages.
_weboob()
_weboob_weboob_config()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboob_config weboob-config
_weboob_weboob_repos()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboob_repos weboob-repos
_weboob_weboob_debug()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboob_debug weboob-debug
_weboob_qcookboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qcookboob qcookboob
_weboob_boobathon()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobathon boobathon
_weboob_galleroob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_galleroob galleroob
_weboob_webcontentedit()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_webcontentedit webcontentedit
_weboob_suboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_suboob suboob
_weboob_wetboobs()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_wetboobs wetboobs
_weboob_boobank()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobank boobank
_weboob_qwebcontentedit()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qwebcontentedit qwebcontentedit
_weboob_qhavedate()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qhavedate qhavedate
_weboob_booblyrics()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_booblyrics booblyrics
_weboob_qboobmsg()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qboobmsg qboobmsg
_weboob_monboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_monboob monboob
_weboob_handjoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_handjoob handjoob
_weboob_translaboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_translaboob translaboob
_weboob_videoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_videoob videoob
_weboob_weboob_config_qt()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboob_config_qt weboob-config-qt
_weboob_flatboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_flatboob flatboob
_weboob_radioob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_radioob radioob
_weboob_qflatboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qflatboob qflatboob
_weboob_geolooc()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_geolooc geolooc
_weboob_weboob_cli()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboob_cli weboob-cli
_weboob_parceloob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_parceloob parceloob
_weboob_qhandjoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qhandjoob qhandjoob
_weboob_cineoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_cineoob cineoob
_weboob_weboorrents()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_weboorrents weboorrents
_weboob_boobmsg()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobmsg boobmsg
_weboob_traveloob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_traveloob traveloob
_weboob_shopoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_shopoob shopoob
_weboob_boobill()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobill boobill
_weboob_boobcoming()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobcoming boobcoming
_weboob_boobtracker()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobtracker boobtracker
_weboob_pastoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_pastoob pastoob
_weboob_boobsize()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobsize boobsize
_weboob_boobooks()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_boobooks boobooks
_weboob_comparoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_comparoob comparoob
_weboob_qbooblyrics()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qbooblyrics qbooblyrics
_weboob_cookboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_cookboob cookboob
_weboob_qcineoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qcineoob qcineoob
_weboob_qvideoob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss"
COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) )
}
complete -F _weboob_qvideoob qvideoob
_weboob_weboob()
{
local cur args
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
args="$(${COMP_WORDS[0]} --shell-completion)"
args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss"