Beispiel #1
0
def read_history(filename, ptr_buffer):
    global_history = 0

    # get buffer_autoset_option as a fallback. could happen that the localvar is not already set to buffer
    plugin = weechat.buffer_get_string(ptr_buffer, 'localvar_plugin')
    name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
    buffer_autoset_option = (
        'buffer_autoset.buffer.%s.%s.localvar_set_save_history' %
        (plugin, name))
    buffer_autoset_option = weechat.config_get(buffer_autoset_option)

    # global history does not use buffer pointers!
    if filename == filename_global_history:
        global_history = 1

    filename = get_filename_with_path(filename)

    # filename exists?
    if not os.path.isfile(filename):
        return

    # check for buffer history (0, global = 1)
    if global_history == 0 and OPTIONS['save_buffer'].lower() == 'off':
        # localvar_save_history exists for buffer?
        if not ptr_buffer and not buffer_autoset_option and not weechat.buffer_get_string(
                ptr_buffer, 'localvar_save_history'):
            return
    hdata = weechat.hdata_get('history')
    if not hdata:
        return

    try:
        f = open(filename, 'r')
        #        for line in f.xreadlines():    # old python 2.x
        for line in f:  # should also work with python 2.x
            #            line = line.decode('utf-8')
            line = str(line.strip())
            if ptr_buffer:
                # add to buffer history
                weechat.hdata_update(hdata, '', {
                    'buffer': ptr_buffer,
                    'text': line
                })
            else:
                # add to global history
                weechat.hdata_update(hdata, '', {'text': line})
        f.close()
    except:
        if global_history == 1:
            weechat.prnt(
                '', '%s%s: Error loading global history from "%s"' %
                (weechat.prefix('error'), SCRIPT_NAME, filename))
        else:
            name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
            weechat.prnt(
                '',
                '%s%s: Error loading buffer history for buffer "%s" from "%s"'
                % (weechat.prefix('error'), SCRIPT_NAME, name, filename))
        raise
Beispiel #2
0
def get_hdata():
    """Get list of hdata hooked by plugins in a dict 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 = ''
        variables_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 = ', array_size: "%s"' % var_array_size
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "%s"' % var_hdata
                    type_string = weechat.hdata_get_var_type_string(ptr_hdata, key)
                    hdata2.append({'offset': var_offset,
                                   'text': '\'%s\' (%s)' % (key, type_string),
                                   'textlong': '\'%s\' (%s%s%s)' % (key, type_string, var_array_size, var_hdata),
                                   'update': weechat.hdata_update(ptr_hdata, '', { '__update_allowed': key })})
                hdata2 = sorted(hdata2, key=itemgetter('offset'))
                for item in hdata2:
                    if variables:
                        variables += ' +\n'
                    variables += '  %s' % item['textlong']
                    if item['update']:
                        if variables_update:
                            variables_update += ' +\n'
                        variables_update += '  %s' % item['text']
                if weechat.hdata_update(ptr_hdata, '', { '__delete_allowed' : '' }):
                    if variables_update:
                        variables_update += ' +\n'
                    variables_update += '  \'__delete\''
            hdata[plugin][hdata_name]['vars'] = '\n%s' % variables
            hdata[plugin][hdata_name]['vars_update'] = '\n%s' % variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                for item in sorted(string.split(',')):
                    if lists:
                        lists += ' +\n'
                    lists += '  \'%s\'' % item
                lists = '\n%s' % lists
            else:
                lists = '\n  -'
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata
Beispiel #3
0
def read_history(filename, ptr_buffer):
    global_history = 0

    # global history does not use buffer pointers!
    if filename == filename_global_history:
        global_history = 1

    filename = get_filename_with_path(filename)

    # filename exists?
    if not os.path.isfile(filename):
        return

    # check for global history
    if global_history == 0:
        # localvar_save_history exists for buffer?
        if not ptr_buffer or not weechat.buffer_get_string(
                ptr_buffer, 'localvar_save_history'):
            return

    hdata = weechat.hdata_get('history')
    if not hdata:
        return

    try:
        f = open(filename, 'r')
        #        for line in f.xreadlines():    # old python 2.x
        for line in f:  # should also work with python 2.x
            #            line = line.decode('utf-8')
            line = str(line.strip())
            if ptr_buffer:
                # add to buffer history
                weechat.hdata_update(hdata, '', {
                    'buffer': ptr_buffer,
                    'text': line
                })
            else:
                # add to global history
                weechat.hdata_update(hdata, '', {'text': line})
        f.close()
    except:
        if global_history == 1:
            weechat.prnt(
                '', '%s%s: Error loading global history from "%s"' %
                (weechat.prefix('error'), SCRIPT_NAME, filename))
        else:
            name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
            weechat.prnt(
                '',
                '%s%s: Error loading buffer history for buffer "%s" from "%s"'
                % (weechat.prefix('error'), SCRIPT_NAME, name, filename))
        raise
Beispiel #4
0
def read_history(filename,ptr_buffer):
    global filename_global_history
    global_history = 0

    # global history does not use buffer pointers!
    if filename == filename_global_history:
        global_history = 1

    filename = get_filename_with_path(filename)

    # filename exists?
    if not os.path.isfile(filename):
        return

    # check for global history
    if global_history == 0:
#        test = weechat.buffer_get_string(ptr_buffer, 'localvar_save_history')
#        test2 = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
#        weechat.prnt("","ptr: %s test: %s name: %s" % (ptr_buffer,test,test2))
        # localvar_save_history exists for buffer?
        if not ptr_buffer or not weechat.buffer_get_string(ptr_buffer, 'localvar_save_history'):
#            weechat.prnt("","test2")
            return

#    weechat.prnt("","test4")
    hdata = weechat.hdata_get('history')
    if not hdata:
        return

    try:
        f = open(filename, 'r')
#        for line in f.xreadlines():    # old python 2.x
        for line in f:                  # should also work with python 2.x
#            line = line.decode('utf-8')
            line = str(line.strip())
            if ptr_buffer:
                # add to buffer history
                weechat.hdata_update(hdata, '', { 'buffer': ptr_buffer, 'text': line })
            else:
                # add to global history
                weechat.hdata_update(hdata, '', { 'text': line })
        f.close()
    except:
        if global_history == 1:
            weechat.prnt('','%s%s: Error loading global history from "%s"' % (weechat.prefix('error'), SCRIPT_NAME, filename))
        else:
            name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
            weechat.prnt('','%s%s: Error loading buffer history for buffer "%s" from "%s"' % (weechat.prefix('error'), SCRIPT_NAME, name, filename))
        raise
Beispiel #5
0
def read_history(filename,ptr_buffer):
    global_history = 0

    # get buffer_autoset_option as a fallback. could happen that the localvar is not already set to buffer
    plugin = weechat.buffer_get_string(ptr_buffer, 'localvar_plugin')
    name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
    buffer_autoset_option = ('buffer_autoset.buffer.%s.%s.localvar_set_save_history' % (plugin,name))
    buffer_autoset_option = weechat.config_get(buffer_autoset_option)

    # global history does not use buffer pointers!
    if filename == filename_global_history:
        global_history = 1

    filename = get_filename_with_path(filename)

    # filename exists?
    if not os.path.isfile(filename):
        return

    # check for buffer history (0, global = 1)
    if global_history == 0 and OPTIONS['save_buffer'].lower() == 'off':
        # localvar_save_history exists for buffer?
        if not ptr_buffer and not buffer_autoset_option and not weechat.buffer_get_string(ptr_buffer, 'localvar_save_history'):
            return
    hdata = weechat.hdata_get('history')
    if not hdata:
        return

    try:
        f = open(filename, 'r')
#        for line in f.xreadlines():    # old python 2.x
        for line in f:                  # should also work with python 2.x
#            line = line.decode('utf-8')
            line = str(line.strip())
            if ptr_buffer:
                # add to buffer history
                weechat.hdata_update(hdata, '', { 'buffer': ptr_buffer, 'text': line })
            else:
                # add to global history
                weechat.hdata_update(hdata, '', { 'text': line })
        f.close()
    except:
        if global_history == 1:
            weechat.prnt('','%s%s: Error loading global history from "%s"' % (weechat.prefix('error'), SCRIPT_NAME, filename))
        else:
            name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
            weechat.prnt('','%s%s: Error loading buffer history for buffer "%s" from "%s"' % (weechat.prefix('error'), SCRIPT_NAME, name, filename))
        raise
Beispiel #6
0
def hdata_update_history_cmd(data, buffer, args):
    hdata = weechat.hdata_get('history')

    # add to global history
    weechat.hdata_update(hdata, '', { 'text': 'test global 1' })
    weechat.hdata_update(hdata, '', { 'text': 'test global 2' })

    # add to history of core buffer
    core_buffer = weechat.buffer_search_main()
    weechat.hdata_update(hdata, '', { 'buffer': core_buffer, 'text': 'test core buffer 1' })
    weechat.hdata_update(hdata, '', { 'buffer': core_buffer, 'text': 'test core buffer 2' })

    return weechat.WEECHAT_RC_OK
Beispiel #7
0
def hdata_update_history_cmd(data, buffer, args):
    hdata = weechat.hdata_get('history')

    # add to global history
    weechat.hdata_update(hdata, '', {'text': 'test global 1'})
    weechat.hdata_update(hdata, '', {'text': 'test global 2'})

    # add to history of core buffer
    core_buffer = weechat.buffer_search_main()
    weechat.hdata_update(hdata, '', {
        'buffer': core_buffer,
        'text': 'test core buffer 1'
    })
    weechat.hdata_update(hdata, '', {
        'buffer': core_buffer,
        'text': 'test core buffer 2'
    })

    return weechat.WEECHAT_RC_OK
Beispiel #8
0
def get_hdata():
    """
    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 = ''
        variables_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 = \
                            ', array_size: "{0}"'.format(var_array_size)
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "{0}"'.format(var_hdata)
                    type_string = weechat.hdata_get_var_type_string(
                        ptr_hdata, key)
                    hdata2.append({
                        'offset':
                        var_offset,
                        'text':
                        '_{0}_ ({1})'.format(key, type_string),
                        'textlong':
                        '_{0}_   ({1}{2}{3})'.format(key, type_string,
                                                     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 += '{0} +\n'.format(item['textlong'])
                    if item['update']:
                        variables_update += '    {0} +\n'.format(item['text'])
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__create_allowed': ''}):
                    variables_update += '    _{hdata_update_create}_ +\n'
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__delete_allowed': ''}):
                    variables_update += '    _{hdata_update_delete}_ +\n'
            hdata[plugin][hdata_name]['vars'] = variables
            hdata[plugin][hdata_name]['vars_update'] = variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                list_lists = string.split(',')
                lists_std = [
                    l for l in list_lists if not l.startswith('last_')
                ]
                lists_last = [l for l in list_lists if l.startswith('last_')]
                for item in sorted(lists_std) + sorted(lists_last):
                    lists += '_{0}_ +\n'.format(item)
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata
Beispiel #9
0
def get_hdata():
    """
    Get list of hdata hooked by plugins in a dict 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 = ''
        variables_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 = \
                            ', array_size: "{0}"'.format(var_array_size)
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "{0}"'.format(var_hdata)
                    type_string = weechat.hdata_get_var_type_string(ptr_hdata,
                                                                    key)
                    hdata2.append({
                        'offset': var_offset,
                        'text': '\'{0}\' ({1})'.format(key, type_string),
                        'textlong': '\'{0}\' ({1}{2}{3})'.format(
                            key, type_string, 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 += '*** {0}\n'.format(item['textlong'])
                    if item['update']:
                        variables_update += '*** {0}\n'.format(item['text'])
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__create_allowed': ''}):
                    variables_update += '*** \'__create\'\n'
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__delete_allowed': ''}):
                    variables_update += '*** \'__delete\'\n'
            hdata[plugin][hdata_name]['vars'] = variables
            hdata[plugin][hdata_name]['vars_update'] = variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                for item in sorted(string.split(',')):
                    lists += '*** \'{0}\'\n'.format(item)
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata
Beispiel #10
0
def get_hdata():
    """
    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 = ''
        variables_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 = \
                            ', array_size: "{0}"'.format(var_array_size)
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "{0}"'.format(var_hdata)
                    type_string = weechat.hdata_get_var_type_string(ptr_hdata,
                                                                    key)
                    hdata2.append({
                        'offset': var_offset,
                        'text': '_{0}_ ({1})'.format(key, type_string),
                        'textlong': '_{0}_   ({1}{2}{3})'.format(
                            key, type_string, 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 += '{0} +\n'.format(item['textlong'])
                    if item['update']:
                        variables_update += '    {0} +\n'.format(item['text'])
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__create_allowed': ''}):
                    variables_update += '    _{hdata_update_create}_ +\n'
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__delete_allowed': ''}):
                    variables_update += '    _{hdata_update_delete}_ +\n'
            hdata[plugin][hdata_name]['vars'] = variables
            hdata[plugin][hdata_name]['vars_update'] = variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                list_lists = string.split(',')
                lists_std = [l for l in list_lists
                             if not l.startswith('last_')]
                lists_last = [l for l in list_lists
                              if l.startswith('last_')]
                for item in sorted(lists_std) + sorted(lists_last):
                    lists += '_{0}_ +\n'.format(item)
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata
Beispiel #11
0
    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(',')
                    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_')
                    ]
                    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
Beispiel #12
0
def get_hdata():
    """
    Get list of hdata hooked by plugins in a dict 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 = ''
        variables_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 = \
                            ', array_size: "{0}"'.format(var_array_size)
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "{0}"'.format(var_hdata)
                    type_string = weechat.hdata_get_var_type_string(ptr_hdata,
                                                                    key)
                    hdata2.append({
                        'offset': var_offset,
                        'text': '\'{0}\' ({1})'.format(key, type_string),
                        'textlong': '\'{0}\' ({1}{2}{3})'.format(
                            key, type_string, 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 += '*** {0}\n'.format(item['textlong'])
                    if item['update']:
                        variables_update += '*** {0}\n'.format(item['text'])
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__create_allowed': ''}):
                    variables_update += '*** \'__create\'\n'
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__delete_allowed': ''}):
                    variables_update += '*** \'__delete\'\n'
            hdata[plugin][hdata_name]['vars'] = variables
            hdata[plugin][hdata_name]['vars_update'] = variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                for item in sorted(string.split(',')):
                    lists += '*** \'{0}\'\n'.format(item)
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata
Beispiel #13
0
def get_hdata():
    """Get list of hdata hooked by plugins in a dict 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 = ''
        variables_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 = ', array_size: "%s"' % var_array_size
                    var_hdata = weechat.hdata_get_var_hdata(ptr_hdata, key)
                    if var_hdata:
                        var_hdata = ', hdata: "%s"' % var_hdata
                    type_string = weechat.hdata_get_var_type_string(
                        ptr_hdata, key)
                    hdata2.append({
                        'offset':
                        var_offset,
                        'text':
                        '\'%s\' (%s)' % (key, type_string),
                        'textlong':
                        '\'%s\' (%s%s%s)' %
                        (key, type_string, var_array_size, var_hdata),
                        'update':
                        weechat.hdata_update(ptr_hdata, '',
                                             {'__update_allowed': key})
                    })
                hdata2 = sorted(hdata2, key=itemgetter('offset'))
                for item in hdata2:
                    if variables:
                        variables += ' +\n'
                    variables += '  %s' % item['textlong']
                    if item['update']:
                        if variables_update:
                            variables_update += ' +\n'
                        variables_update += '  %s' % item['text']
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__create_allowed': ''}):
                    if variables_update:
                        variables_update += ' +\n'
                    variables_update += '  `__create`'
                if weechat.hdata_update(ptr_hdata, '',
                                        {'__delete_allowed': ''}):
                    if variables_update:
                        variables_update += ' +\n'
                    variables_update += '  `__delete`'
            hdata[plugin][hdata_name]['vars'] = '\n%s' % variables
            hdata[plugin][hdata_name][
                'vars_update'] = '\n%s' % variables_update

            string = weechat.hdata_get_string(ptr_hdata, 'list_keys')
            if string:
                for item in sorted(string.split(',')):
                    if lists:
                        lists += ' +\n'
                    lists += '  \'%s\'' % item
                lists = '\n%s' % lists
            else:
                lists = '\n  -'
            hdata[plugin][hdata_name]['lists'] = lists
    weechat.infolist_free(infolist)
    return hdata