2020-05-02 17:23:31 +02:00
|
|
|
|
#!/usr/bin/env python3
|
2011-07-03 15:47:50 +02:00
|
|
|
|
#
|
2021-01-02 21:34:16 +01:00
|
|
|
|
# Copyright (C) 2008-2021 Sébastien Helleu <flashcode@flashtux.org>
|
2011-07-03 15:47:50 +02:00
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program 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 General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2018-11-29 23:16:07 +01:00
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2011-07-03 15:47:50 +02:00
|
|
|
|
#
|
|
|
|
|
|
2014-05-11 08:15:18 +02:00
|
|
|
|
"""
|
2019-11-22 20:57:59 +01:00
|
|
|
|
Documentation generator for WeeChat: build include files with:
|
|
|
|
|
|
|
|
|
|
- commands
|
|
|
|
|
- config options
|
|
|
|
|
- default aliases
|
|
|
|
|
- IRC colors
|
|
|
|
|
- infos
|
|
|
|
|
- infos hashtable
|
|
|
|
|
- infolists
|
|
|
|
|
- hdata
|
|
|
|
|
- completions
|
|
|
|
|
- URL options
|
|
|
|
|
- plugins priority.
|
|
|
|
|
|
|
|
|
|
Instructions to build config files yourself in WeeChat directories
|
|
|
|
|
(replace "path" with the path to the docgen.py script in WeeChat repository):
|
|
|
|
|
|
|
|
|
|
weechat -t -r "/python load /path/docgen.py;/docgen;/quit"
|
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
There's one output file per language (where xx is language):
|
|
|
|
|
|
|
|
|
|
/path/xx/includes/autogen.xx.adoc
|
|
|
|
|
|
|
|
|
|
This script requires Python 3.6+.
|
2014-05-11 08:15:18 +02:00
|
|
|
|
"""
|
|
|
|
|
|
2013-11-02 18:19:28 +01:00
|
|
|
|
SCRIPT_NAME = 'docgen'
|
|
|
|
|
SCRIPT_AUTHOR = 'Sébastien Helleu <flashcode@flashtux.org>'
|
2020-05-02 17:23:31 +02:00
|
|
|
|
SCRIPT_VERSION = '0.3'
|
2011-07-03 15:47:50 +02:00
|
|
|
|
SCRIPT_LICENSE = 'GPL3'
|
2013-11-02 18:19:28 +01:00
|
|
|
|
SCRIPT_DESC = 'Documentation generator for WeeChat'
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
|
|
|
|
SCRIPT_COMMAND = 'docgen'
|
|
|
|
|
|
2014-05-11 08:15:18 +02:00
|
|
|
|
IMPORT_OK = True
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
2015-11-30 10:24:18 +01:00
|
|
|
|
# pylint: disable=wrong-import-position
|
2011-07-03 15:47:50 +02:00
|
|
|
|
try:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
from collections import defaultdict
|
|
|
|
|
from operator import itemgetter
|
2013-11-02 18:19:28 +01:00
|
|
|
|
import gettext
|
|
|
|
|
import hashlib
|
2020-05-03 14:03:50 +02:00
|
|
|
|
import inspect
|
2013-11-02 18:19:28 +01:00
|
|
|
|
import os
|
|
|
|
|
import re
|
2020-05-02 17:23:31 +02:00
|
|
|
|
except ImportError as exc:
|
|
|
|
|
print(f'Missing package(s) for {SCRIPT_NAME}: {exc}')
|
2014-05-11 08:15:18 +02:00
|
|
|
|
IMPORT_OK = False
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
2015-11-30 10:24:18 +01:00
|
|
|
|
try:
|
|
|
|
|
import weechat # pylint: disable=import-error
|
|
|
|
|
except ImportError:
|
|
|
|
|
print('This script must be run under WeeChat.')
|
|
|
|
|
print('Get WeeChat now at: https://weechat.org/')
|
|
|
|
|
IMPORT_OK = False
|
|
|
|
|
|
2011-07-03 15:47:50 +02:00
|
|
|
|
# list of locales for which we want to build doc files to include
|
2019-11-22 20:59:06 +01:00
|
|
|
|
LOCALE_LIST = (
|
|
|
|
|
'de_DE',
|
|
|
|
|
'en_US',
|
|
|
|
|
'fr_FR',
|
|
|
|
|
'it_IT',
|
|
|
|
|
'ja_JP',
|
|
|
|
|
'pl_PL',
|
2021-06-13 16:28:33 +02:00
|
|
|
|
'sr_RS',
|
2019-11-22 20:59:06 +01:00
|
|
|
|
)
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
|
|
|
|
# all commands/options/.. of following plugins will produce a file
|
|
|
|
|
# non-listed plugins will be ignored
|
|
|
|
|
# value: "c" = plugin may have many commands
|
|
|
|
|
# "o" = write config options for plugin
|
|
|
|
|
# if plugin is listed without "c", that means plugin has only one command
|
|
|
|
|
# /name (where "name" is name of plugin)
|
|
|
|
|
# Note: we consider core is a plugin called "weechat"
|
2014-05-11 08:15:18 +02:00
|
|
|
|
PLUGIN_LIST = {
|
2013-11-02 18:19:28 +01:00
|
|
|
|
'sec': 'o',
|
|
|
|
|
'weechat': 'co',
|
|
|
|
|
'alias': '',
|
2017-03-25 12:14:50 +01:00
|
|
|
|
'buflist': 'co',
|
2014-02-15 12:47:52 +01:00
|
|
|
|
'charset': 'o',
|
2014-03-10 14:26:23 +01:00
|
|
|
|
'exec': 'o',
|
2014-02-15 12:47:52 +01:00
|
|
|
|
'fifo': 'o',
|
2017-06-25 21:24:42 +02:00
|
|
|
|
'fset': 'o',
|
2013-11-02 18:19:28 +01:00
|
|
|
|
'irc': 'co',
|
2014-02-15 12:47:52 +01:00
|
|
|
|
'logger': 'o',
|
|
|
|
|
'relay': 'o',
|
|
|
|
|
'script': 'o',
|
2018-01-15 21:32:24 +01:00
|
|
|
|
'perl': 'o',
|
|
|
|
|
'python': 'o',
|
|
|
|
|
'ruby': 'o',
|
|
|
|
|
'lua': 'o',
|
|
|
|
|
'tcl': 'o',
|
|
|
|
|
'guile': 'o',
|
|
|
|
|
'javascript': 'o',
|
|
|
|
|
'php': 'o',
|
2019-01-27 14:59:22 +01:00
|
|
|
|
'spell': 'o',
|
2014-02-15 12:47:52 +01:00
|
|
|
|
'trigger': 'o',
|
2014-02-21 16:32:34 +01:00
|
|
|
|
'xfer': 'co',
|
2021-06-28 20:27:08 +02:00
|
|
|
|
'typing': 'o',
|
2013-11-02 18:19:28 +01:00
|
|
|
|
}
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
|
|
|
|
# options to ignore
|
2014-05-11 08:15:18 +02:00
|
|
|
|
IGNORE_OPTIONS = (
|
|
|
|
|
r'charset\.decode\..*',
|
|
|
|
|
r'charset\.encode\..*',
|
|
|
|
|
r'irc\.msgbuffer\..*',
|
|
|
|
|
r'irc\.ctcp\..*',
|
|
|
|
|
r'irc\.ignore\..*',
|
|
|
|
|
r'irc\.server\..*',
|
|
|
|
|
r'logger\.level\..*',
|
|
|
|
|
r'logger\.mask\..*',
|
|
|
|
|
r'relay\.port\..*',
|
2019-01-27 14:59:22 +01:00
|
|
|
|
r'spell\.dict\..*',
|
|
|
|
|
r'spell\.option\..*',
|
2014-05-11 08:15:18 +02:00
|
|
|
|
r'trigger\.trigger\..*',
|
|
|
|
|
r'weechat\.palette\..*',
|
|
|
|
|
r'weechat\.proxy\..*',
|
|
|
|
|
r'weechat\.bar\..*',
|
|
|
|
|
r'weechat\.debug\..*',
|
|
|
|
|
r'weechat\.notify\..*',
|
2013-11-02 18:19:28 +01:00
|
|
|
|
)
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
|
|
|
|
# completions to ignore
|
2014-05-11 08:15:18 +02:00
|
|
|
|
IGNORE_COMPLETIONS_ITEMS = (
|
2013-11-02 18:19:28 +01:00
|
|
|
|
'docgen.*',
|
|
|
|
|
)
|
|
|
|
|
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def translate(string):
|
|
|
|
|
"""Translate a string."""
|
2020-05-03 14:48:25 +02:00
|
|
|
|
return _(string) if string else string
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def escape(string):
|
|
|
|
|
"""Escape a string."""
|
|
|
|
|
return string.replace('|', '\\|')
|
|
|
|
|
|
|
|
|
|
|
2019-11-22 20:59:58 +01:00
|
|
|
|
def sha256_file(filename, default=None):
|
|
|
|
|
"""Return SHA256 checksum of a file."""
|
|
|
|
|
try:
|
|
|
|
|
with open(filename, 'rb') as _file:
|
|
|
|
|
checksum = hashlib.sha256(_file.read()).hexdigest()
|
|
|
|
|
except IOError:
|
|
|
|
|
checksum = default
|
|
|
|
|
return checksum
|
|
|
|
|
|
|
|
|
|
|
2020-05-03 14:48:25 +02:00
|
|
|
|
class WeechatDoc(): # pylint: disable=too-few-public-methods
|
2020-05-03 14:03:50 +02:00
|
|
|
|
"""A class to read documentation from WeeChat API."""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def read_doc(self):
|
|
|
|
|
"""Get documentation from WeeChat API."""
|
|
|
|
|
functions = sorted([
|
|
|
|
|
func[0]
|
|
|
|
|
for func in inspect.getmembers(self, predicate=inspect.isfunction)
|
|
|
|
|
if func[0].startswith('_read_')
|
|
|
|
|
])
|
|
|
|
|
return {
|
|
|
|
|
function[6:]: getattr(self, function)()
|
|
|
|
|
for function in functions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_user_commands():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins commands as dictionary with 3 indexes:
|
|
|
|
|
plugin, command, xxx.
|
|
|
|
|
"""
|
|
|
|
|
commands = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'command')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
if plugin in PLUGIN_LIST:
|
|
|
|
|
command = weechat.infolist_string(infolist, 'command')
|
|
|
|
|
if command == plugin or 'c' in PLUGIN_LIST[plugin]:
|
|
|
|
|
for key in ('description', 'args', 'args_description',
|
|
|
|
|
'completion'):
|
|
|
|
|
commands[plugin][command][key] = \
|
|
|
|
|
weechat.infolist_string(infolist, key)
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_user_options():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins config options as dictionary with
|
|
|
|
|
4 indexes: config, section, option, xxx.
|
|
|
|
|
"""
|
|
|
|
|
options = \
|
|
|
|
|
defaultdict(lambda: defaultdict(lambda: defaultdict(defaultdict)))
|
|
|
|
|
infolist = weechat.infolist_get('option', '', '')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
full_name = weechat.infolist_string(infolist, 'full_name')
|
|
|
|
|
if not re.search('|'.join(IGNORE_OPTIONS), full_name):
|
|
|
|
|
config = weechat.infolist_string(infolist, 'config_name')
|
|
|
|
|
if config in PLUGIN_LIST and 'o' in PLUGIN_LIST[config]:
|
|
|
|
|
section = weechat.infolist_string(infolist, 'section_name')
|
|
|
|
|
option = weechat.infolist_string(infolist, 'option_name')
|
|
|
|
|
for key in ('type', 'string_values', 'default_value',
|
|
|
|
|
'description'):
|
|
|
|
|
options[config][section][option][key] = \
|
|
|
|
|
weechat.infolist_string(infolist, key)
|
|
|
|
|
for key in ('min', 'max', 'null_value_allowed'):
|
|
|
|
|
options[config][section][option][key] = \
|
|
|
|
|
weechat.infolist_integer(infolist, key)
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_infos():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins infos as dictionary with 3 indexes:
|
|
|
|
|
plugin, name, xxx.
|
|
|
|
|
"""
|
|
|
|
|
infos = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'info')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
info_name = weechat.infolist_string(infolist, 'info_name')
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
for key in ('description', 'args_description'):
|
|
|
|
|
infos[plugin][info_name][key] = \
|
|
|
|
|
weechat.infolist_string(infolist, key)
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return infos
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_infos_hashtable():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins infos (hashtable) as dictionary with
|
|
|
|
|
3 indexes: plugin, name, xxx.
|
|
|
|
|
"""
|
|
|
|
|
infos_hashtable = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'info_hashtable')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
info_name = weechat.infolist_string(infolist, 'info_name')
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
for key in ('description', 'args_description',
|
|
|
|
|
'output_description'):
|
|
|
|
|
infos_hashtable[plugin][info_name][key] = \
|
|
|
|
|
weechat.infolist_string(infolist, key)
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return infos_hashtable
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_infolists():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins infolists as dictionary with 3 indexes:
|
|
|
|
|
plugin, name, xxx.
|
|
|
|
|
"""
|
|
|
|
|
infolists = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'infolist')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
infolist_name = weechat.infolist_string(infolist, 'infolist_name')
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
for key in ('description', 'pointer_description',
|
|
|
|
|
'args_description'):
|
|
|
|
|
infolists[plugin][infolist_name][key] = \
|
|
|
|
|
weechat.infolist_string(infolist, key)
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return infolists
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_hdata(): # pylint: disable=too-many-locals
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins hdata as dictionary with 3 indexes:
|
|
|
|
|
plugin, name, xxx.
|
|
|
|
|
"""
|
|
|
|
|
hdata = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'hdata')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
hdata_name = weechat.infolist_string(infolist, 'hdata_name')
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
hdata[plugin][hdata_name]['description'] = \
|
|
|
|
|
weechat.infolist_string(infolist, 'description')
|
|
|
|
|
variables = ''
|
|
|
|
|
vars_update = ''
|
|
|
|
|
lists = ''
|
|
|
|
|
ptr_hdata = weechat.hdata_get(hdata_name)
|
|
|
|
|
if ptr_hdata:
|
|
|
|
|
hdata2 = []
|
|
|
|
|
string = weechat.hdata_get_string(ptr_hdata, 'var_keys_values')
|
|
|
|
|
if string:
|
|
|
|
|
for item in string.split(','):
|
|
|
|
|
key = item.split(':')[0]
|
|
|
|
|
var_offset = weechat.hdata_get_var_offset(
|
|
|
|
|
ptr_hdata,
|
|
|
|
|
key,
|
|
|
|
|
)
|
|
|
|
|
var_array_size = \
|
|
|
|
|
weechat.hdata_get_var_array_size_string(
|
|
|
|
|
ptr_hdata,
|
|
|
|
|
'',
|
|
|
|
|
key,
|
|
|
|
|
)
|
|
|
|
|
if var_array_size:
|
|
|
|
|
var_array_size = \
|
|
|
|
|
f', array_size: "{var_array_size}"'
|
|
|
|
|
var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
|
|
|
|
|
if var_hdata:
|
|
|
|
|
var_hdata = f', hdata: "{var_hdata}"'
|
|
|
|
|
type_string = weechat.hdata_get_var_type_string(
|
|
|
|
|
ptr_hdata,
|
|
|
|
|
key,
|
|
|
|
|
)
|
|
|
|
|
hdata2.append({
|
|
|
|
|
'offset': var_offset,
|
|
|
|
|
'text': f'_{key}_ ({type_string})',
|
|
|
|
|
'textlong': (f'_{key}_ ({type_string}'
|
|
|
|
|
f'{var_array_size}{var_hdata})'),
|
|
|
|
|
'update': weechat.hdata_update(
|
|
|
|
|
ptr_hdata, '', {'__update_allowed': key}),
|
|
|
|
|
})
|
|
|
|
|
hdata2 = sorted(hdata2, key=itemgetter('offset'))
|
|
|
|
|
for item in hdata2:
|
|
|
|
|
variables += f'{item["textlong"]} +\n'
|
|
|
|
|
if item['update']:
|
|
|
|
|
vars_update += f' {item["text"]} +\n'
|
|
|
|
|
if weechat.hdata_update(ptr_hdata, '',
|
|
|
|
|
{'__create_allowed': ''}):
|
|
|
|
|
vars_update += ' _{hdata_update_create}_ +\n'
|
|
|
|
|
if weechat.hdata_update(ptr_hdata, '',
|
|
|
|
|
{'__delete_allowed': ''}):
|
|
|
|
|
vars_update += ' _{hdata_update_delete}_ +\n'
|
|
|
|
|
hdata[plugin][hdata_name]['vars'] = variables
|
|
|
|
|
hdata[plugin][hdata_name]['vars_update'] = vars_update.rstrip()
|
|
|
|
|
|
|
|
|
|
string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
|
|
|
|
|
if string:
|
|
|
|
|
list_lists = string.split(',')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
lists_std = [lst for lst in list_lists
|
|
|
|
|
if not lst.startswith('last_')]
|
|
|
|
|
lists_last = [lst for lst in list_lists
|
|
|
|
|
if lst.startswith('last_')]
|
2020-05-03 14:03:50 +02:00
|
|
|
|
for item in sorted(lists_std) + sorted(lists_last):
|
|
|
|
|
lists += f'_{item}_ +\n'
|
|
|
|
|
hdata[plugin][hdata_name]['lists'] = lists
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return hdata
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_completions():
|
|
|
|
|
"""
|
|
|
|
|
Get list of WeeChat/plugins completions as dictionary with 3 indexes:
|
|
|
|
|
plugin, item, xxx.
|
|
|
|
|
"""
|
|
|
|
|
completions = defaultdict(lambda: defaultdict(defaultdict))
|
|
|
|
|
infolist = weechat.infolist_get('hook', '', 'completion')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
completion_item = weechat.infolist_string(infolist,
|
|
|
|
|
'completion_item')
|
|
|
|
|
if not re.search('|'.join(IGNORE_COMPLETIONS_ITEMS),
|
|
|
|
|
completion_item):
|
|
|
|
|
plugin = (weechat.infolist_string(infolist, 'plugin_name')
|
|
|
|
|
or 'weechat')
|
|
|
|
|
completions[plugin][completion_item]['description'] = \
|
|
|
|
|
weechat.infolist_string(infolist, 'description')
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return completions
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_url_options():
|
|
|
|
|
"""
|
|
|
|
|
Get list of URL options as list of dictionaries.
|
|
|
|
|
"""
|
|
|
|
|
url_options = []
|
|
|
|
|
infolist = weechat.infolist_get('url_options', '', '')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
url_options.append({
|
|
|
|
|
'name': weechat.infolist_string(infolist, 'name').lower(),
|
|
|
|
|
'option': weechat.infolist_integer(infolist, 'option'),
|
|
|
|
|
'type': weechat.infolist_string(infolist, 'type'),
|
|
|
|
|
'constants': weechat.infolist_string(
|
|
|
|
|
infolist, 'constants').lower().replace(',', ', ')
|
|
|
|
|
})
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return url_options
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_user_default_aliases():
|
|
|
|
|
"""
|
|
|
|
|
Get list of default aliases as list of dictionaries.
|
|
|
|
|
"""
|
|
|
|
|
default_aliases = []
|
|
|
|
|
infolist = weechat.infolist_get('alias_default', '', '')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
default_aliases.append({
|
|
|
|
|
'name': '/' + weechat.infolist_string(infolist, 'name'),
|
|
|
|
|
'command': '/' + weechat.infolist_string(infolist, 'command'),
|
|
|
|
|
'completion': weechat.infolist_string(infolist, 'completion'),
|
|
|
|
|
})
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return default_aliases
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_user_irc_colors():
|
|
|
|
|
"""
|
|
|
|
|
Get list of IRC colors as list of dictionaries.
|
|
|
|
|
"""
|
|
|
|
|
irc_colors = []
|
|
|
|
|
infolist = weechat.infolist_get('irc_color_weechat', '', '')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
irc_colors.append({
|
|
|
|
|
'color_irc': weechat.infolist_string(infolist, 'color_irc'),
|
|
|
|
|
'color_weechat': weechat.infolist_string(infolist,
|
|
|
|
|
'color_weechat'),
|
|
|
|
|
})
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return irc_colors
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _read_api_plugins_priority():
|
|
|
|
|
"""
|
|
|
|
|
Get priority of default WeeChat plugins as a dictionary.
|
|
|
|
|
"""
|
|
|
|
|
plugins_priority = {}
|
|
|
|
|
infolist = weechat.infolist_get('plugin', '', '')
|
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
|
name = weechat.infolist_string(infolist, 'name')
|
|
|
|
|
priority = weechat.infolist_integer(infolist, 'priority')
|
|
|
|
|
if priority in plugins_priority:
|
|
|
|
|
plugins_priority[priority].append(name)
|
|
|
|
|
else:
|
|
|
|
|
plugins_priority[priority] = [name]
|
|
|
|
|
weechat.infolist_free(infolist)
|
|
|
|
|
return plugins_priority
|
|
|
|
|
|
|
|
|
|
|
2020-05-03 14:48:25 +02:00
|
|
|
|
class AutogenDoc():
|
2015-03-11 20:15:23 +01:00
|
|
|
|
"""A class to write auto-generated doc files."""
|
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def __init__(self, weechat_doc, doc_directory, locale):
|
2015-03-11 20:15:23 +01:00
|
|
|
|
"""Initialize auto-generated doc file."""
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.doc_directory = doc_directory
|
|
|
|
|
self.locale = locale
|
|
|
|
|
self.count_files = 0
|
|
|
|
|
self.count_updated = 0
|
2020-05-03 14:48:25 +02:00
|
|
|
|
self.filename = None
|
|
|
|
|
self.filename_tmp = None
|
|
|
|
|
self._file = None
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.install_translations()
|
|
|
|
|
self.write_autogen_files(weechat_doc)
|
|
|
|
|
|
|
|
|
|
def install_translations(self):
|
|
|
|
|
"""Install translations."""
|
|
|
|
|
trans = gettext.translation(
|
|
|
|
|
'weechat',
|
|
|
|
|
weechat.info_get('weechat_localedir', ''),
|
|
|
|
|
languages=[f'{self.locale}.UTF-8'],
|
|
|
|
|
fallback=True,
|
|
|
|
|
)
|
|
|
|
|
trans.install()
|
|
|
|
|
|
|
|
|
|
def open_file(self, name):
|
2020-05-03 14:48:25 +02:00
|
|
|
|
"""Open temporary auto-generated file."""
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.filename = os.path.join(
|
|
|
|
|
self.doc_directory,
|
2020-05-03 14:48:25 +02:00
|
|
|
|
self.locale[:2],
|
2020-05-03 14:03:50 +02:00
|
|
|
|
'includes',
|
2020-05-03 14:48:25 +02:00
|
|
|
|
f'autogen_{name}.{self.locale[:2]}.adoc',
|
2020-05-03 14:03:50 +02:00
|
|
|
|
)
|
2020-05-02 17:23:31 +02:00
|
|
|
|
self.filename_tmp = f'{self.filename}.tmp'
|
2015-03-11 20:15:23 +01:00
|
|
|
|
self._file = open(self.filename_tmp, 'w')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def write_autogen_files(self, weechat_doc):
|
|
|
|
|
"""Write auto-generated files."""
|
|
|
|
|
for name, doc in weechat_doc.items():
|
|
|
|
|
self.open_file(name)
|
|
|
|
|
self.write_autogen_file(name, doc)
|
|
|
|
|
self.update_autogen_file()
|
|
|
|
|
|
|
|
|
|
def write_autogen_file(self, name, doc):
|
|
|
|
|
"""Write auto-generated file."""
|
2020-05-02 17:23:31 +02:00
|
|
|
|
self.write('//')
|
|
|
|
|
self.write('// This file is auto-generated by script docgen.py.')
|
|
|
|
|
self.write('// DO NOT EDIT BY HAND!')
|
|
|
|
|
self.write('//')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
getattr(self, f'_write_{name}')(doc)
|
2015-03-11 20:15:23 +01:00
|
|
|
|
|
2020-05-03 14:48:25 +02:00
|
|
|
|
def write(self, *args):
|
2015-03-11 20:15:23 +01:00
|
|
|
|
"""Write a line in auto-generated doc file."""
|
2020-05-03 14:48:25 +02:00
|
|
|
|
if args:
|
|
|
|
|
if len(args) > 1:
|
|
|
|
|
self._file.write(args[0] % args[1:])
|
|
|
|
|
else:
|
|
|
|
|
self._file.write(args[0])
|
2020-05-02 17:23:31 +02:00
|
|
|
|
self._file.write('\n')
|
2015-03-11 20:15:23 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def update_autogen_file(self):
|
2015-03-11 20:15:23 +01:00
|
|
|
|
"""Update doc file if needed (if content has changed)."""
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.count_files += 1
|
2015-03-11 20:15:23 +01:00
|
|
|
|
# close temp file
|
|
|
|
|
self._file.close()
|
2019-11-22 20:59:58 +01:00
|
|
|
|
sha_old = sha256_file(self.filename, 'old')
|
|
|
|
|
sha_new = sha256_file(self.filename_tmp, 'new')
|
2015-03-11 20:15:23 +01:00
|
|
|
|
# compare checksums
|
2019-11-22 20:59:58 +01:00
|
|
|
|
if sha_old != sha_new:
|
2015-03-11 20:15:23 +01:00
|
|
|
|
# update doc file
|
|
|
|
|
if os.path.exists(self.filename):
|
|
|
|
|
os.unlink(self.filename)
|
|
|
|
|
os.rename(self.filename_tmp, self.filename)
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.count_updated += 1
|
2015-03-11 20:15:23 +01:00
|
|
|
|
else:
|
|
|
|
|
os.unlink(self.filename_tmp)
|
core: add priority in plugins to initialize them in order
Current order is: charset, logger, exec, trigger, aspell, alias, fifo, xfer,
irc, relay, guile/lua/perl/python/ruby/tcl, script.
2015-01-15 07:40:38 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def __str__(self):
|
|
|
|
|
"""Get status string."""
|
|
|
|
|
if self.count_updated > 0:
|
|
|
|
|
color_count = weechat.color('yellow')
|
|
|
|
|
color_updated = weechat.color('green')
|
|
|
|
|
color_reset = weechat.color('reset')
|
|
|
|
|
str_updated = (f', {color_count}{self.count_updated} '
|
|
|
|
|
f'{color_updated}updated{color_reset}')
|
|
|
|
|
else:
|
|
|
|
|
str_updated = ''
|
|
|
|
|
return f'{self.locale}: {self.count_files} files{str_updated}'
|
core: add priority in plugins to initialize them in order
Current order is: charset, logger, exec, trigger, aspell, alias, fifo, xfer,
irc, relay, guile/lua/perl/python/ruby/tcl, script.
2015-01-15 07:40:38 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def _write_user_commands(self, commands):
|
|
|
|
|
"""Write commands."""
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in commands:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write()
|
|
|
|
|
self.write(f'// tag::{plugin}_commands[]')
|
2015-08-20 07:36:22 +02:00
|
|
|
|
for i, command in enumerate(sorted(commands[plugin])):
|
|
|
|
|
if i > 0:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write()
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_cmd = commands[plugin][command]
|
|
|
|
|
args = translate(_cmd['args'])
|
2011-07-03 15:47:50 +02:00
|
|
|
|
args_formats = args.split(' || ')
|
2013-11-02 18:19:28 +01:00
|
|
|
|
desc = translate(_cmd['description'])
|
|
|
|
|
args_desc = translate(_cmd['args_description'])
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(f'[[command_{plugin}_{command}]]')
|
|
|
|
|
self.write(f'* `+{command}+`: {desc}\n')
|
|
|
|
|
self.write('----')
|
2013-11-02 18:19:28 +01:00
|
|
|
|
prefix = '/' + command + ' '
|
2011-07-03 15:47:50 +02:00
|
|
|
|
if args_formats != ['']:
|
|
|
|
|
for fmt in args_formats:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(prefix + fmt)
|
2011-07-03 15:47:50 +02:00
|
|
|
|
prefix = ' ' * len(prefix)
|
2013-11-02 18:19:28 +01:00
|
|
|
|
if args_desc:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write()
|
|
|
|
|
self.write(args_desc)
|
|
|
|
|
self.write('----')
|
|
|
|
|
self.write(f'// end::{plugin}_commands[]')
|
2011-07-03 15:47:50 +02:00
|
|
|
|
|
2020-05-03 14:48:25 +02:00
|
|
|
|
# pylint: disable=too-many-locals,too-many-branches
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def _write_user_options(self, options):
|
|
|
|
|
"""Write config options."""
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for config in options:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write()
|
|
|
|
|
self.write(f'// tag::{config}_options[]')
|
2015-08-20 07:36:22 +02:00
|
|
|
|
i = 0
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for section in sorted(options[config]):
|
|
|
|
|
for option in sorted(options[config][section]):
|
2015-08-20 07:36:22 +02:00
|
|
|
|
if i > 0:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write()
|
2015-08-20 07:36:22 +02:00
|
|
|
|
i += 1
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_opt = options[config][section][option]
|
|
|
|
|
opt_type = _opt['type']
|
|
|
|
|
string_values = _opt['string_values']
|
|
|
|
|
default_value = _opt['default_value']
|
|
|
|
|
opt_min = _opt['min']
|
|
|
|
|
opt_max = _opt['max']
|
|
|
|
|
null_value_allowed = _opt['null_value_allowed']
|
|
|
|
|
desc = translate(_opt['description'])
|
2011-07-03 15:47:50 +02:00
|
|
|
|
type_nls = translate(opt_type)
|
|
|
|
|
values = ''
|
|
|
|
|
if opt_type == 'boolean':
|
|
|
|
|
values = 'on, off'
|
|
|
|
|
elif opt_type == 'integer':
|
|
|
|
|
if string_values:
|
|
|
|
|
values = string_values.replace('|', ', ')
|
|
|
|
|
else:
|
2020-05-02 17:23:31 +02:00
|
|
|
|
values = f'{opt_min} .. {opt_max}'
|
2011-07-03 15:47:50 +02:00
|
|
|
|
elif opt_type == 'string':
|
|
|
|
|
if opt_max <= 0:
|
|
|
|
|
values = _('any string')
|
|
|
|
|
elif opt_max == 1:
|
|
|
|
|
values = _('any char')
|
|
|
|
|
elif opt_max > 1:
|
2020-05-02 17:23:31 +02:00
|
|
|
|
values = (_('any string')
|
|
|
|
|
+ '(' + _('max chars') + ': '
|
|
|
|
|
+ opt_max + ')')
|
2011-07-03 15:47:50 +02:00
|
|
|
|
else:
|
|
|
|
|
values = _('any string')
|
2020-05-02 17:23:31 +02:00
|
|
|
|
default_value = ('"%s"' %
|
|
|
|
|
default_value.replace('"', '\\"'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
elif opt_type == 'color':
|
|
|
|
|
values = _('a WeeChat color name (default, black, '
|
2013-11-02 18:19:28 +01:00
|
|
|
|
'(dark)gray, white, (light)red, '
|
|
|
|
|
'(light)green, brown, yellow, (light)blue, '
|
|
|
|
|
'(light)magenta, (light)cyan), a terminal '
|
|
|
|
|
'color number or an alias; attributes are '
|
|
|
|
|
'allowed before color (for text color '
|
|
|
|
|
'only, not background): \"*\" for bold, '
|
|
|
|
|
'\"!\" for reverse, \"/\" for italic, '
|
|
|
|
|
'\"_\" for underline')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(f'* [[option_{config}.{section}.{option}]] '
|
|
|
|
|
f'*{config}.{section}.{option}*')
|
|
|
|
|
self.write('** %s: pass:none[%s]',
|
|
|
|
|
_('description'), desc.replace(']', '\\]'))
|
|
|
|
|
self.write('** %s: %s', _('type'), type_nls)
|
|
|
|
|
self.write('** %s: %s', _('values'), values)
|
|
|
|
|
self.write('** %s: `+%s+`',
|
|
|
|
|
_('default value'), default_value)
|
2011-07-03 15:47:50 +02:00
|
|
|
|
if null_value_allowed:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('** %s',
|
|
|
|
|
_('undefined value allowed (null)'))
|
|
|
|
|
self.write(f'// end::{config}_options[]')
|
|
|
|
|
|
|
|
|
|
def _write_user_default_aliases(self, default_aliases):
|
|
|
|
|
"""Write default aliases."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::default_aliases[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="2m,5m,5",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s\n',
|
|
|
|
|
_('Alias'), _('Command'), _('Completion'))
|
2017-08-12 14:32:09 +02:00
|
|
|
|
for alias in default_aliases:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s | %s',
|
|
|
|
|
escape(alias['name']),
|
|
|
|
|
escape(alias['command']),
|
|
|
|
|
escape(alias['completion'] or '-'))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::default_aliases[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_user_irc_colors(self, irc_colors):
|
|
|
|
|
"""Write IRC colors."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::irc_colors[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="50%",cols="^2m,3",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s\n', _('IRC color'), _('WeeChat color'))
|
2015-03-11 20:15:23 +01:00
|
|
|
|
for color in irc_colors:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s',
|
|
|
|
|
escape(color['color_irc']),
|
|
|
|
|
escape(color['color_weechat']))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::irc_colors[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_infos(self, infos):
|
|
|
|
|
"""Write infos."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::infos[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="^1,^2,6,6",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s | %s\n',
|
|
|
|
|
_('Plugin'), _('Name'), _('Description'), _('Arguments'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in sorted(infos):
|
|
|
|
|
for info in sorted(infos[plugin]):
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_inf = infos[plugin][info]
|
|
|
|
|
desc = translate(_inf['description'])
|
2021-02-25 19:06:47 +01:00
|
|
|
|
args_desc = translate(_inf['args_description']) or '-'
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s | %s | %s\n',
|
|
|
|
|
escape(plugin), escape(info), escape(desc),
|
|
|
|
|
escape(args_desc))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::infos[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_infos_hashtable(self, infos_hashtable):
|
|
|
|
|
"""Write infos hashtable."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::infos_hashtable[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="^1,^2,6,6,8",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s | %s | %s\n',
|
|
|
|
|
_('Plugin'), _('Name'), _('Description'),
|
|
|
|
|
_('Hashtable (input)'), _('Hashtable (output)'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in sorted(infos_hashtable):
|
|
|
|
|
for info in sorted(infos_hashtable[plugin]):
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_inh = infos_hashtable[plugin][info]
|
|
|
|
|
desc = translate(_inh['description'])
|
2021-02-25 19:06:47 +01:00
|
|
|
|
args_desc = translate(_inh['args_description']) or '-'
|
2013-11-02 18:19:28 +01:00
|
|
|
|
output_desc = translate(_inh['output_description']) or '-'
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s | %s | %s | %s\n',
|
|
|
|
|
escape(plugin), escape(info), escape(desc),
|
|
|
|
|
escape(args_desc), escape(output_desc))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::infos_hashtable[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_infolists(self, infolists):
|
|
|
|
|
"""Write infolists."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::infolists[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="^1,^2,5,5,5",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s | %s | %s\n',
|
|
|
|
|
_('Plugin'), _('Name'), _('Description'), _('Pointer'),
|
|
|
|
|
_('Arguments'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in sorted(infolists):
|
|
|
|
|
for infolist in sorted(infolists[plugin]):
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_inl = infolists[plugin][infolist]
|
|
|
|
|
desc = translate(_inl['description'])
|
|
|
|
|
pointer_desc = translate(_inl['pointer_description']) or '-'
|
|
|
|
|
args_desc = translate(_inl['args_description']) or '-'
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s | %s | %s | %s\n',
|
|
|
|
|
escape(plugin), escape(infolist), escape(desc),
|
|
|
|
|
escape(pointer_desc), escape(args_desc))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::infolists[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_hdata(self, hdata):
|
|
|
|
|
"""Write hdata."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::hdata[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(':hdata_update_create: __create')
|
|
|
|
|
self.write(':hdata_update_delete: __delete')
|
|
|
|
|
self.write('[width="100%",cols="^1,^2,2,2,5",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s | %s | %s\n',
|
|
|
|
|
_('Plugin'), _('Name'), _('Description'), _('Lists'),
|
|
|
|
|
_('Variables'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in sorted(hdata):
|
|
|
|
|
for hdata_name in sorted(hdata[plugin]):
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_hda = hdata[plugin][hdata_name]
|
2020-05-02 17:23:31 +02:00
|
|
|
|
anchor = f'hdata_{hdata_name}'
|
2013-11-02 18:19:28 +01:00
|
|
|
|
desc = translate(_hda['description'])
|
|
|
|
|
variables = _hda['vars']
|
2020-05-02 17:23:31 +02:00
|
|
|
|
vars_update = _hda['vars_update']
|
2013-11-02 18:19:28 +01:00
|
|
|
|
lists = _hda['lists']
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(f'| {escape(plugin)}')
|
|
|
|
|
self.write(f'| [[{escape(anchor)}]]<<{escape(anchor)},'
|
|
|
|
|
f'{escape(hdata_name)}>>')
|
|
|
|
|
self.write(f'| {escape(desc)}')
|
2020-05-02 17:23:31 +02:00
|
|
|
|
str_lists = escape(lists) if lists else '-'
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write(f'| {str_lists}')
|
|
|
|
|
self.write(f'| {escape(variables)}')
|
2020-05-02 17:23:31 +02:00
|
|
|
|
if vars_update:
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('*%s* +\n%s',
|
|
|
|
|
_('Update allowed:'), escape(vars_update))
|
|
|
|
|
self.write()
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::hdata[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_completions(self, completions):
|
|
|
|
|
"""Write completions."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::completions[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="^1,^2,7",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s | %s\n',
|
|
|
|
|
_('Plugin'), _('Name'), _('Description'))
|
2011-07-03 15:47:50 +02:00
|
|
|
|
for plugin in sorted(completions):
|
|
|
|
|
for completion_item in sorted(completions[plugin]):
|
2013-11-02 18:19:28 +01:00
|
|
|
|
_cmp = completions[plugin][completion_item]
|
|
|
|
|
desc = translate(_cmp['description'])
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s | %s\n',
|
|
|
|
|
escape(plugin), escape(completion_item),
|
|
|
|
|
escape(desc))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::completions[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_url_options(self, url_options):
|
|
|
|
|
"""Write URL options."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::url_options[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('[width="100%",cols="2,^1,7",options="header"]')
|
|
|
|
|
self.write('|===')
|
|
|
|
|
self.write('| %s | %s ^(1)^ | %s ^(2)^\n',
|
|
|
|
|
_('Option'), _('Type'), _('Constants'))
|
2012-01-16 19:52:08 +01:00
|
|
|
|
for option in url_options:
|
|
|
|
|
constants = option['constants']
|
|
|
|
|
if constants:
|
|
|
|
|
constants = ' ' + constants
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('| %s | %s |%s\n',
|
|
|
|
|
escape(option['name']), escape(option['type']),
|
|
|
|
|
escape(constants))
|
|
|
|
|
self.write('|===')
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::url_options[]')
|
2020-05-03 14:03:50 +02:00
|
|
|
|
|
|
|
|
|
def _write_api_plugins_priority(self, plugins_priority):
|
|
|
|
|
"""Write plugins priority."""
|
|
|
|
|
self.write()
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// tag::plugins_priority[]')
|
core: add priority in plugins to initialize them in order
Current order is: charset, logger, exec, trigger, aspell, alias, fifo, xfer,
irc, relay, guile/lua/perl/python/ruby/tcl, script.
2015-01-15 07:40:38 +01:00
|
|
|
|
for priority in sorted(plugins_priority, reverse=True):
|
|
|
|
|
plugins = ', '.join(sorted(plugins_priority[priority]))
|
2020-05-03 14:03:50 +02:00
|
|
|
|
self.write('. %s (%s)', escape(plugins), priority)
|
2020-06-28 10:26:04 +02:00
|
|
|
|
self.write('// end::plugins_priority[]')
|
core: add priority in plugins to initialize them in order
Current order is: charset, logger, exec, trigger, aspell, alias, fifo, xfer,
irc, relay, guile/lua/perl/python/ruby/tcl, script.
2015-01-15 07:40:38 +01:00
|
|
|
|
|
2019-11-22 21:00:58 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
def docgen_cmd_cb(data, buf, args):
|
|
|
|
|
"""Callback for /docgen command."""
|
|
|
|
|
doc_directory = data
|
|
|
|
|
locales = args.split(' ') if args else sorted(LOCALE_LIST)
|
|
|
|
|
|
|
|
|
|
weechat_doc = WeechatDoc().read_doc()
|
2019-11-22 21:00:58 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
weechat.prnt('', '-' * 75)
|
|
|
|
|
|
|
|
|
|
for locale in locales:
|
|
|
|
|
autogen = AutogenDoc(weechat_doc, doc_directory, locale)
|
|
|
|
|
weechat.prnt('', f'docgen: {autogen}')
|
2019-11-22 21:00:58 +01:00
|
|
|
|
|
2020-05-03 14:03:50 +02:00
|
|
|
|
weechat.prnt('', '-' * 75)
|
2019-11-22 21:00:58 +01:00
|
|
|
|
|
2011-07-03 15:47:50 +02:00
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
2013-11-02 18:19:28 +01:00
|
|
|
|
|
2014-05-11 08:15:18 +02:00
|
|
|
|
def docgen_completion_cb(data, completion_item, buf, completion):
|
2011-07-03 15:47:50 +02:00
|
|
|
|
"""Callback for completion."""
|
2014-05-11 08:15:18 +02:00
|
|
|
|
for locale in LOCALE_LIST:
|
2020-05-08 10:49:20 +02:00
|
|
|
|
weechat.completion_list_add(completion, locale, 0,
|
|
|
|
|
weechat.WEECHAT_LIST_POS_SORT)
|
2011-07-03 15:47:50 +02:00
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
2013-11-02 18:19:28 +01:00
|
|
|
|
|
2014-05-11 08:15:18 +02:00
|
|
|
|
if __name__ == '__main__' and IMPORT_OK:
|
2013-11-02 18:19:28 +01:00
|
|
|
|
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
|
|
|
|
|
SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
|
2020-05-03 14:03:50 +02:00
|
|
|
|
weechat.hook_command(
|
|
|
|
|
SCRIPT_COMMAND,
|
|
|
|
|
'Documentation generator.',
|
|
|
|
|
'[locales]',
|
|
|
|
|
'locales: list of locales to build (by default build all locales)',
|
|
|
|
|
'%(docgen_locales)|%*',
|
|
|
|
|
'docgen_cmd_cb',
|
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
|
)
|
|
|
|
|
weechat.hook_completion(
|
|
|
|
|
'docgen_locales',
|
|
|
|
|
'locales for docgen',
|
|
|
|
|
'docgen_completion_cb',
|
|
|
|
|
'',
|
|
|
|
|
)
|