Quelle generate-bash-completion.py
Sprache: Python
#!/usr/bin/env python3 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. #
"""
Script to generate LibreOffice bash_completion file for the main applications """
# default names of lowrappers # use "" for name if you want to disable any wrapper
APPS = { 'office': App("libreoffice", 'openoffice', ALLDOCS), # libreoffice should contain all 'office_short': App("loffice", 'ooffice', ALLDOCS), # libreoffice should contain all 'master': App("", '', MASTERDOCS), 'base': App("lobase", 'oobase', BASEDOCS), 'calc': App("localc", 'oocalc', CALCDOCS), 'draw': App("lodraw", 'oodraw', DRAWDOCS), 'impress': App("loimpress", 'ooimpress', IMPRESSDOCS), 'math': App("lomath", 'oomath', MATHDOCS), 'template': App("lofromtemplate", 'oofromtemplate', TEMPLATES), 'unopkg': App("unopkg", 'unopkg', EXTENSIONS), # unopkg is a standalone tool 'web': App("loweb", 'ooweb', WEBDOCS), 'writer': App("lowriter", 'oowriter', WRITERDOCS + MASTERDOCS)
}
def check_open(filename, mode): try: with open(filename, mode): pass except OSError as e:
mode = 'reading'if mode == 'r'else'writing'
sys.exit("Error: can't open %s for %s: %s" % (filename, mode, e))
def print_app_suffixes_check(out, app): ifnot app.suffix_list:
sys.exit('Error: No suffix defined for %s' % app.name)
suffix_str = '|'.join(['%s|%s' % (s, s.upper()) for s in app.suffix_list])
out.write(" %s)\t\te=\'!*.+(%s)\' ;;\n" % (app.name, suffix_str))
def print_suffixes_check(out): for app in APPS.values(): ifnot app.name: # skip the disabled wrapper continue
print_app_suffixes_check(out, app)
def main():
parser = argparse.ArgumentParser(description='Script to Generate bash completion for LO wrappers',
epilog='The other options allows to redefine the wrapper names.\n' 'The value "" can be used to disable any wrapper.',
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('input_file')
parser.add_argument('output_file')
parser.add_argument('--binsuffix', metavar='suffix',
help='defines a suffix that is added after each wrapper')
parser.add_argument('--compat-oowrappers', metavar='', nargs=0, action=SetAppCompatName, default=False,
help='set wrapper names to the old default oo* wrapper names') for app in APPS:
parser.add_argument('--%s' % app, metavar='wrapper_name', action=SetAppName)
# add binsuffix if args.binsuffix: for app in APPS.values(): if app.name:
app.name += args.binsuffix
if args.compat_oowrappers:
office_shell_function = '_ooexp_' else:
office_shell_function = '_loexp_'
# the last app will be printed without the final backslash
apps_to_print = ' \\\n'.join(['\t\t\t\t\t%s' % app.name for app in APPS.values() if app.name])
with open(args.input_file, 'r') as in_fh, open(args.output_file, 'w') as out_fh: for line in in_fh:
line = line.replace('@OFFICE_SHELL_FUNCTION@', office_shell_function) if'@BASH_COMPLETION_SUFFIXES_CHECKS@'in line:
print_suffixes_check(out_fh) elif'@BASH_COMPLETION_OOO_APPS@'in line: ifnot apps_to_print:
sys.exit('Error: No LO wrapper was selected')
out_fh.write('%s\n' % apps_to_print) else:
out_fh.write(line)
if __name__ == '__main__':
main()
# vim: set shiftwidth=4 softtabstop=4 expandtab:
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.