Esempio n. 1
0
def bootstrap_tray():
    BUF_SIZE = 65536
    weechat.mkdir_parents(plugin_dir, 0o755)

    if weechat.config_get_plugin("icon") == "weechat":
        # Download icon
        icon = plugin_dir + "/icons/weechat.png"
        if not path.exists(icon):
            weechat.mkdir_parents(plugin_dir + "/icons", 0o755)
            weechat.hook_process_hashtable("url:" + WEECHAT_ICON_URL,
                                           {"file_out": icon + ".tmp"},
                                           30 * 1000, "process_download_cb",
                                           "")
            time.sleep(0.5)
            sha512 = hashlib.sha512()
            f = open(icon + ".tmp", 'rb')
            sha512.update(f.read())
            if sha512.hexdigest() != WEECHAT_ICON_SHA512:
                printc("weechat icon failed sha512sum; got " +
                       sha512.hexdigest())
                return 1
            else:
                rename(icon + ".tmp", icon)

    if weechat.config_get_plugin("alt-icon") == "null":
        icon = plugin_dir + "/icons/null.png"
        if not path.exists(icon):
            weechat.mkdir_parents(plugin_dir + "/icons", 0o755)
            weechat.hook_process_hashtable("url:" + NULL_ICON_URL,
                                           {"file_out": icon + ".tmp"},
                                           30 * 1000, "process_download_cb",
                                           "")
            time.sleep(0.5)
            sha512 = hashlib.sha512()
            f = open(icon + ".tmp", 'rb')
            sha512.update(f.read())
            if sha512.hexdigest() != NULL_ICON_SHA512:
                printc("null icon failed sha512sum; got " + sha512.hexdigest())
                return 1
            else:
                rename(icon + ".tmp", icon)

    # Download tray icon script
    script = plugin_dir + "/systray.py"
    if not path.exists(script):
        weechat.hook_process_hashtable("url:" + SYSTRAY_PY_URL,
                                       {"file_out": script + ".tmp"},
                                       30 * 1000, "process_download_cb", "")
        time.sleep(1)
        sha512 = hashlib.sha512()
        f = open(script + ".tmp", 'rb')
        sha512.update(f.read())
        if sha512.hexdigest() != SYSTRAY_PY_SHA512:
            printc("systray.py failed sha512sum; got " + sha512.hexdigest())
            return 1
        else:
            rename(script + ".tmp", script)

    state.BOOTSTRAPPED = True
Esempio n. 2
0
def testapigen_cmd_cb(data, buf, args):
    """Callback for WeeChat command /testapigen."""
    def print_error(msg):
        """Print an error message on core buffer."""
        weechat.prnt('', '%s%s' % (weechat.prefix('error'), msg))

    try:
        source_script, output_dir = args.split()
    except ValueError:
        print_error('ERROR: invalid arguments for /testapigen')
        return weechat.WEECHAT_RC_OK
    if not weechat.mkdir_parents(output_dir, 0o755):
        print_error('ERROR: invalid directory: %s' % output_dir)
        return weechat.WEECHAT_RC_OK
    ret_code, error = generate_scripts(source_script, output_dir)
    if error:
        print_error(error)
    return weechat.WEECHAT_RC_OK if ret_code == 0 else weechat.WEECHAT_RC_ERROR
Esempio n. 3
0
def testapigen_cmd_cb(data, buf, args):
    """Callback for WeeChat command /testapigen."""

    def print_error(msg):
        """Print an error message on core buffer."""
        weechat.prnt('', '%s%s' % (weechat.prefix('error'), msg))

    try:
        source_script, output_dir = args.split()
    except ValueError:
        print_error('ERROR: invalid arguments for /testapigen')
        return weechat.WEECHAT_RC_OK
    if not weechat.mkdir_parents(output_dir, 0o755):
        print_error('ERROR: invalid directory: %s' % output_dir)
        return weechat.WEECHAT_RC_OK
    ret_code, error = generate_scripts(source_script, output_dir)
    if error:
        print_error(error)
    return weechat.WEECHAT_RC_OK if ret_code == 0 else weechat.WEECHAT_RC_ERROR