Exemple #1
0
def sushi_kick(time, server, sender, channel, who, message):
    """ message can be empty """
    stab = main_window.find_server(server)

    if not stab:
        print_error("missing stab '%s'" % (server))
        return

    nick = parse_from(sender)[0]
    tab = main_window.find_tab(server, channel)

    if who == stab.get_nick():
        # we got kicked
        pass

    else:
        tab.nicklist.remove_nick(who)

    msg = format_message("actions",
                         "kick", {
                             "who": who,
                             "channel": channel,
                             "nick": nick,
                             "reason": message
                         },
                         own=(who == stab.get_nick()),
                         highlight=(nick == tab.parent.get_nick()))
    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Exemple #2
0
def sushi_join(time, server, sender, channel):

    server_tab = main_window.find_server(server)

    if not server_tab:
        print_error("Missing server tab for '%s'." % (server))
        return

    tab = main_window.find_tab(server, channel)
    nick = parse_from(sender)[0]

    if nick == server_tab.get_nick():
        # we join
        if not tab:
            tab = tabs.Channel(name=channel, parent=server_tab)

        tab.set_joined(True)
        main_window.update_divider()

    else:
        # somebody joined
        tab.nicklist.add_nick(nick)

    msg = format_message("actions",
                         "join", {
                             "nick": nick,
                             "host": sender,
                             "channel": channel
                         },
                         own=(nick == server_tab.get_nick()),
                         highlight=False)

    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Exemple #3
0
def cmd_overview(main_window, argv):
    """ /overview [<server>] """
    if no_connection():
        return

    if len(argv) == 2:
        if argv[1] not in [n.name for n in main_window.servers]:
            print_error("Server '%s' not found." % (argv[1]))
            return
        server_list = [main_window.find_server(argv[1])]
    else:
        server_list = main_window.servers

    print_normal("Begin overview.")

    for server in server_list:
        if server.connected:
            connected = "connected"
        else:
            connected = "not connected"

        print_normal("Server '%s' (%s)" % (server, connected))

        for child in server.children:
            if type(child) == tabs.Channel:
                if child.joined:
                    joined = "joined"
                else:
                    joined = "not joined"
                print_normal("- Channel '%s' (%s)" % (child.name, joined))
            else:
                print_normal("- Query '%s'" % (child.name))

    print_normal("End of overview.")
Exemple #4
0
def cmd_names(main_window, argv):
    """ /names """
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        print_error("You must be on a channel to use /names.")
        return
    connection.sushi.names(ct.parent.name, ct.name)
Exemple #5
0
def sushi_quit(time, server, sender, message):
    """ message can be empty """
    server_tab = main_window.find_server(server)

    if not server_tab:
        print_error("No server tab for server '%s'." % (server))
        return

    nick = parse_from(sender)[0]

    msg = format_message("actions",
                         "quit", {
                             "nick": nick,
                             "reason": message
                         },
                         own=(nick == server_tab.get_nick()),
                         highlight=False)
    msg.markup_cb = color_nick_markup_cb

    if nick == server_tab.get_nick():
        # we quit
        server_tab.set_connected(False)

        for child in server_tab.children:
            print_tab(child, msg)

    else:
        for tab in server_tab.children:
            if type(tab) == tabs.Channel and tab.nicklist.has_nick(nick):
                tab.nicklist.remove_nick(nick)
                print_tab(tab, msg)
            elif (type(tab) == tabs.Query
                  and tab.name.lower() == nick.lower()):
                print_tab(tab, msg)
Exemple #6
0
def cmd_python(main_window, argv):
    """ /python <code> """
    print_notification("python: Executing...\n")
    try:
        exec(" ".join(argv[1:]))
    except BaseException, e:
        print_error("python: %s\n" % (e))
Exemple #7
0
def sushi_kick(time, server, sender, channel, who, message):
	""" message can be empty """
	stab = main_window.find_server(server)

	if not stab:
		print_error("missing stab '%s'" % (server))
		return

	nick = parse_from(sender)[0]
	tab = main_window.find_tab(server, channel)

	if who == stab.get_nick():
		# we got kicked
		pass

	else:
		tab.nicklist.remove_nick(who)

	msg = format_message("actions", "kick",
		{"who": who,
		 "channel": channel,
		 "nick": nick,
		 "reason": message},
		own = (who == stab.get_nick()),
		highlight = (nick == tab.parent.get_nick()))
	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Exemple #8
0
def sushi_topic(time, server, sender, channel, topic):
    """ sender can be empty """
    tab = main_window.find_tab(server, channel)

    if not tab:
        print_error("No tab '%s' on '%s' for topic setting." %
                    (channel, server))
        return

    tab.set_topic(topic)
    nick = parse_from(sender)[0]

    if sender == "":
        template = "topic_anonymous"
    else:
        template = "topic"

    msg = format_message("actions",
                         template, {
                             "nick": nick,
                             "channel": channel,
                             "topic": topic
                         },
                         own=(tab.parent.get_nick() == nick),
                         highlight=False)
    if nick:
        msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)

    if tab == main_window.current_tab:
        # update topic bar
        main_window.header.set_text(tab.get_topic())
Exemple #9
0
def cmd_names(main_window, argv):
    """ /names """
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        print_error("You must be on a channel to use /names.")
        return
    connection.sushi.names(ct.parent.name, ct.name)
Exemple #10
0
def find_parent_tab(server, target):
	parent = main_window.find_server(server)
	if not parent:
		print_error("parent server '%s' for '%s' not found." % (
			server, target))
		return None
	return parent
Exemple #11
0
def find_parent_tab(server, target):
    parent = main_window.find_server(server)
    if not parent:
        print_error("parent server '%s' for '%s' not found." %
                    (server, target))
        return None
    return parent
Exemple #12
0
def sushi_join(time, server, sender, channel):

	server_tab = main_window.find_server(server)

	if not server_tab:
		print_error("Missing server tab for '%s'." % (server))
		return

	tab = main_window.find_tab(server, channel)
	nick = parse_from(sender)[0]

	if nick == server_tab.get_nick():
		# we join
		if not tab:
			tab = tabs.Channel(name = channel, parent = server_tab)

		tab.set_joined(True)
		main_window.update_divider()

	else:
		# somebody joined
		tab.nicklist.add_nick(nick)

	msg = format_message("actions", "join",
		{"nick": nick,
   		 "host": sender,
		 "channel": channel},
		own = (nick == server_tab.get_nick()),
		highlight = False)

	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Exemple #13
0
def cmd_add_server(main_window, argv):
    """ /add_server <name> <address> <port> <nick> <real> """
    if no_connection():
        return

    if len(argv) != 6:
        print_notification("Usage: /add_server <name> <address> "\
         "<port> <nick> <real>")
        return

    cmd, server_name, address, port, nick, name = argv

    try:
        int(port)
    except ValueError:
        print_error("Invalid value for 'port' given.")
        return

    if server_name in connection.sushi.server_list("", ""):
        print_error("Server with name '%s' already existing." % (server_name))
        return

    pairs = (("address", address), ("port", port), ("nick", nick), ("name",
                                                                    name))
    for key, value in pairs:
        connection.sushi.server_set(server_name, "server", key, value)

    print_notification("Server '%s' successfully added." % (server_name))
Exemple #14
0
def cmd_python(main_window, argv):
    """ /python <code> """
    print_notification("python: Executing...\n")
    try:
        exec(" ".join(argv[1:]))
    except BaseException, e:
        print_error("python: %s\n" % (e))
Exemple #15
0
def sushi_quit(time, server, sender, message):
	""" message can be empty """
	server_tab = main_window.find_server(server)

	if not server_tab:
		print_error("No server tab for server '%s'." % (server))
		return

	nick = parse_from(sender)[0]

	msg = format_message("actions", "quit",
		{"nick": nick,
		 "reason": message},
		own = (nick == server_tab.get_nick()),
		highlight = False)
	msg.markup_cb = color_nick_markup_cb

	if nick == server_tab.get_nick():
		# we quit
		server_tab.set_connected(False)

		for child in server_tab.children:
			print_tab(child, msg)

	else:
		for tab in server_tab.children:
			if type(tab) == tabs.Channel and tab.nicklist.has_nick(nick):
				tab.nicklist.remove_nick(nick)
				print_tab(tab, msg)
			elif (type(tab) == tabs.Query
				and tab.name.lower() == nick.lower()):
				print_tab(tab, msg)
Exemple #16
0
def sushi_topic(time, server, sender, channel, topic):
	""" sender can be empty """
	tab = main_window.find_tab(server, channel)

	if not tab:
		print_error("No tab '%s' on '%s' for topic setting." % (
			channel, server))
		return

	tab.set_topic(topic)
	nick = parse_from(sender)[0]

	if sender == "":
		template = "topic_anonymous"
	else:
		template = "topic"

	msg = format_message("actions", template,
		{"nick": nick,
		 "channel": channel,
		 "topic": topic},
		own = (tab.parent.get_nick() == nick),
		highlight = False)
	if nick:
		msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)

	if tab == main_window.current_tab:
		# update topic bar
		main_window.header.set_text(tab.get_topic())
Exemple #17
0
def cmd_overview(main_window, argv):
    """ /overview [<server>] """
    if no_connection():
        return

    if len(argv) == 2:
        if argv[1] not in [n.name for n in main_window.servers]:
            print_error("Server '%s' not found." % (argv[1]))
            return
        server_list = [main_window.find_server(argv[1])]
    else:
        server_list = main_window.servers

    print_normal("Begin overview.")

    for server in server_list:
        if server.connected:
            connected = "connected"
        else:
            connected = "not connected"

        print_normal("Server '%s' (%s)" % (server, connected))

        for child in server.children:
            if type(child) == tabs.Channel:
                if child.joined:
                    joined = "joined"
                else:
                    joined = "not joined"
                print_normal("- Channel '%s' (%s)" % (child.name, joined))
            else:
                print_normal("- Query '%s'" % (child.name))

    print_normal("End of overview.")
Exemple #18
0
def cmd_add_server(main_window, argv):
    """ /add_server <name> <address> <port> <nick> <real> """
    if no_connection():
        return

    if len(argv) != 6:
        print_notification("Usage: /add_server <name> <address> " "<port> <nick> <real>")
        return

    cmd, server_name, address, port, nick, name = argv

    try:
        int(port)
    except ValueError:
        print_error("Invalid value for 'port' given.")
        return

    if server_name in connection.sushi.server_list("", ""):
        print_error("Server with name '%s' already existing." % (server_name))
        return

    pairs = (("address", address), ("port", port), ("nick", nick), ("name", name))
    for key, value in pairs:
        connection.sushi.server_set(server_name, "server", key, value)

    print_notification("Server '%s' successfully added." % (server_name))
def unload(filename):
    """ Call unload() in the plugin instance,
		unload the module and unregister it.
		On success this function returns True,
		otherwise it returns False.
	"""
    global _plugins

    try:
        entry = _plugins[filename]
    except KeyError:
        print_error("Failed to unload plugin '%s', does not exist." %
                    (filename))
        return False

    # tell the instance, it's time to go
    try:
        entry[PLUGIN_INSTANCE].unload()
    except:
        pass

    _unload_module(entry[PLUGIN_MODNAME])

    # unregister locally
    return _unregister_plugin(filename)
Exemple #20
0
def load_autoloads():
	autoloads = config.get("autoload_plugins").items()
	for opt,filename in autoloads:
		print "autoloading '%s'" % (filename)
		if not load(filename):
			print_error("Failed to load plugin '%s' automatically, "\
				"removing from list." % (filename))
			config.unset("autoload_plugins",opt)
def load_autoloads():
    autoloads = config.get("autoload_plugins").items()
    for opt, filename in autoloads:
        print "autoloading '%s'" % (filename)
        if not load(filename):
            print_error("Failed to load plugin '%s' automatically, "\
             "removing from list." % (filename))
            config.unset("autoload_plugins", opt)
Exemple #22
0
		def subdec(*args, **kwargs):
			parameters = inspect.getargspec(fun)[0]
			param_dict = {}

			for i in range (len(args[:len(parameters)])):
				param_dict[parameters[i]] = args[i]
			param_dict.update (kwargs)

			tab = fun(*args, **kwargs)
			if not tab:
				print_error(msg % param_dict)

			return tab
Exemple #23
0
        def subdec(*args, **kwargs):
            parameters = inspect.getargspec(fun)[0]
            param_dict = {}

            for i in range(len(args[:len(parameters)])):
                param_dict[parameters[i]] = args[i]
            param_dict.update(kwargs)

            tab = fun(*args, **kwargs)
            if not tab:
                print_error(msg % param_dict)

            return tab
Exemple #24
0
def cmd_unload(main_window, argv):
    if len(argv) != 2:
        print_notification("Usage: /unload <filename>")
        return
    name = argv[1]

    if not plugin_control.is_loaded(name):
        print_error("Plugin '%s' is not loaded." % (name))
        return

    if not plugin_control.unload(name):
        print_error("Failed to unload plugin '%s'." % (name))
    else:
        print_notification("Plugin '%s' successfully unloaded." % (name))
Exemple #25
0
def cmd_unload(main_window, argv):
    if len(argv) != 2:
        print_notification("Usage: /unload <filename>")
        return
    name = argv[1]

    if not plugin_control.is_loaded(name):
        print_error("Plugin '%s' is not loaded." % (name))
        return

    if not plugin_control.unload(name):
        print_error("Failed to unload plugin '%s'." % (name))
    else:
        print_notification("Plugin '%s' successfully unloaded." % (name))
Exemple #26
0
def run_tests(path, conn, replaces):
    """Run SQL tests over a connection, returns a dict with results.

    Keyword arguments:
    path     -- String with the path having the SQL files for tests
    conn     -- A db connection (according to Python DB API v2.0)
    replaces -- A dict with replaces to perform at testing code
    """
    files = sorted(glob(path))
    tests = {'total': 0, 'ok': 0, 'errors': 0}
    for file in files:
        tests['total'] += 1
        f = open(file, 'r')
        sentence = f.read()
        for key, elem in replaces.items():
            sentence = sentence.replace(key, elem)
        print_info("Running %s" % file)
        try:
            cursor = conn.cursor()
            cursor.execute(sentence)
            conn.commit()
            cursor.close()
            tests['ok'] += 1
        except Exception as e:
            print_error("Error running test %s" % file)
            try:
                print_error(e.pgcode)
                print_error(e.pgerror)
            except:
                print_error(e)
            conn.rollback()
            tests['errors'] += 1
        f.close()
    return (tests)
Exemple #27
0
def cmd_connect(main_window, argv):
    """ /connect <server> """
    if no_connection():
        return

    if len(argv) != 2:
        print_notification("Usage: /connect <server>")
        return

    if argv[1] not in connection.sushi.server_list("", ""):
        print_error("connect: The server '%(server)s' is not known." % {"server": argv[1]})
        return

    connection.sushi.connect(argv[1])
Exemple #28
0
def run_tests(path, conn, replaces):
    """Run SQL tests over a connection, returns a dict with results.

    Keyword arguments:
    path     -- String with the path having the SQL files for tests
    conn     -- A db connection (according to Python DB API v2.0)
    replaces -- A dict with replaces to perform at testing code
    """
    files = sorted(glob(path))
    tests = {'total': 0, 'ok': 0, 'errors': 0}
    for file in files:
        tests['total'] += 1
        f = open(file, 'r')
        sentence = f.read()
        for key, elem in replaces.items():
            sentence = sentence.replace(key, elem)
        print_info("Running %s" % file)
        try:
            cursor = conn.cursor()
            cursor.execute(sentence)
            conn.commit()
            cursor.close()
            tests['ok'] += 1
        except Exception as e:
            print_error("Error running test %s" % file)
            try:
                print_error(e.pgcode)
                print_error(e.pgerror)
            except:
                print_error(e)
            conn.rollback()
            tests['errors'] += 1
        f.close()
    return(tests)
Exemple #29
0
def send_text(tab, text):
    if no_connection() or type(tab) == tabs.Server or not text:
        return

    server_name = tab.parent.name

    if not tab.connected:
        print_error("Not connected to server " "'%s'." % (server_name))
        return

    if type(tab) == tabs.Channel and not tab.joined:
        print_error("You are not on the channel " "'%s'." % (tab.name))
        return

    connection.sushi.message(server_name, tab.name, text)
Exemple #30
0
def cmd_connect(main_window, argv):
    """ /connect <server> """
    if no_connection():
        return

    if len(argv) != 2:
        print_notification("Usage: /connect <server>")
        return

    if argv[1] not in connection.sushi.server_list("", ""):
        print_error("connect: The server '%(server)s' is not known." %
                    {"server": argv[1]})
        return

    connection.sushi.connect(argv[1])
Exemple #31
0
def cmd_part(main_window, argv):
    """ /part [<reason>] """
    if no_connection():
        return

    if len(argv) == 2:
        reason = " ".join(argv[1:])
    else:
        reason = ""

    ct = main_window.current_tab
    if type(ct) in (tabs.Server, tabs.Query):
        print_error("The current tab is not a channel.")
        return
    else:
        connection.sushi.part(ct.parent.name, ct.name, reason)
def _load_module(filename, mod_info):
    """ wrapper for imp.load_module.
		Returns a tuple with the identifying
		name of the loaded module and the
		module itself if loading was successful.
		Otherwise the function returns (None,None).
	"""
    name = strip_suffix(filename)
    plugin = None
    modname = _module_prefix + name

    try:
        plugin = imp.load_module(modname, *mod_info)

    except ImportError, e:
        print_error("Failure while loading plugin '%s': %s" % (name, e))
Exemple #33
0
def _load_module(filename, mod_info):
	""" wrapper for imp.load_module.
		Returns a tuple with the identifying
		name of the loaded module and the
		module itself if loading was successful.
		Otherwise the function returns (None,None).
	"""
	name = strip_suffix(filename)
	plugin = None
	modname = _module_prefix + name

	try:
		plugin = imp.load_module(modname, *mod_info)

	except ImportError,e:
		print_error("Failure while loading plugin '%s': %s" % (name, e))
Exemple #34
0
def cmd_part(main_window, argv):
    """ /part [<reason>] """
    if no_connection():
        return

    if len(argv) == 2:
        reason = " ".join(argv[1:])
    else:
        reason = ""

    ct = main_window.current_tab
    if type(ct) in (tabs.Server, tabs.Query):
        print_error("The current tab is not a channel.")
        return
    else:
        connection.sushi.part(ct.parent.name, ct.name, reason)
def _find_module(filename):
    """ wrapper for imp.find_module.
		Searches for the module named after
		filename in the configured search
		path (tekka, plugin_dirs).
	"""
    # get the name of the module to search for
    name = strip_suffix(filename)

    mod_info = None
    try:
        mod_info = imp.find_module(
            name, config.get_list("nigiri", "plugin_dirs", []))

    except ImportError, e:
        print_error("Error while finding module for '%s'" % (filename))
        return None
Exemple #36
0
def cmd_remove_server(main_window, argv):
    """ /remove_server <name> """
    if no_connection():
        return

    if len(argv) != 2:
        print_notification("Usage: /remove_server <name>")
        return

    name = argv[1]

    if not name in connection.sushi.server_list("", ""):
        print_error("Server '%s' not known to maki." % (name))
        return

    connection.sushi.server_remove(name, "", "")
    print_notification("Server '%s' successfully removed." % (name))
Exemple #37
0
def send_text(tab, text):
    if no_connection() or type(tab) == tabs.Server or not text:
        return

    server_name = tab.parent.name

    if not tab.connected:
        print_error("Not connected to server "\
         "'%s'." % (server_name))
        return

    if type(tab) == tabs.Channel and not tab.joined:
        print_error("You are not on the channel "\
         "'%s'." % (tab.name))
        return

    connection.sushi.message(server_name, tab.name, text)
Exemple #38
0
def _find_module(filename):
	""" wrapper for imp.find_module.
		Searches for the module named after
		filename in the configured search
		path (tekka, plugin_dirs).
	"""
	# get the name of the module to search for
	name = strip_suffix(filename)

	mod_info = None
	try:
		mod_info = imp.find_module(
			name, config.get_list("nigiri","plugin_dirs",[]))

	except ImportError, e:
		print_error("Error while finding module for '%s'" % (filename))
		return None
Exemple #39
0
def cmd_remove_server(main_window, argv):
    """ /remove_server <name> """
    if no_connection():
        return

    if len(argv) != 2:
        print_notification("Usage: /remove_server <name>")
        return

    name = argv[1]

    if not name in connection.sushi.server_list("", ""):
        print_error("Server '%s' not known to maki." % (name))
        return

    connection.sushi.server_remove(name, "", "")
    print_notification("Server '%s' successfully removed." % (name))
Exemple #40
0
def sushi_nick(time, server, old, new):
    """ old == "" => new == current nick """
    stab = main_window.find_server(server)

    if not stab:
        print_error("missing stab '%s'" % server)
        return

    if not old or old == stab.get_nick():
        stab.set_nick(new)

        if main_window.current_tab in tabs.tree_to_list([stab]):
            main_window.update_divider()

        msg = format_message("actions",
                             "nick", {
                                 "nick": old,
                                 "new_nick": new
                             },
                             own=True,
                             highlight=False)

        current_server_tab_print(server, msg)

    else:
        # print status message in channel tab
        old = connection.parse_from(old)[0]
        new = connection.parse_from(new)[0]

        msg = format_message("actions",
                             "nick", {
                                 "nick": old,
                                 "new_nick": new
                             },
                             own=False,
                             highlight=False)

        msg.markup_cb = color_nick_markup_cb
        msg.markup_cb_kwargs = {"values": ["nick", "new_nick"]}

        for tab in stab.children:
            if type(tab) == tabs.Channel and tab.nicklist.has_nick(old):
                tab.nicklist.rename_nick(old, new)
                print_tab(tab, msg)
Exemple #41
0
def cmd_kick(main_window, argv):
    """ /kick <user> [<reason>]
		Kick a user from the current channel with an optional reason.
	"""
    if len(argv) < 2:
        return print_notification("Usage: /kick <user> [<reason>]")
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        return print_error("You have to be on a channel to do so.")
    connection.sushi.kick(ct.parent.name, ct.name, argv[1], " ".join(argv[2:]))
Exemple #42
0
def parse(main_window, text):
    argv = text.split(" ")

    if not argv or (argv[0] and argv[0][0] != config.get("nigiri", "command_char")):
        return False

    command = strip_command_char(argv[0])

    if not command:
        return False

    try:
        fun = _command_dict[command]
    except KeyError:
        print_error("No such command '%s'.\n" % (command))
    else:
        fun(main_window, argv)

    return True
Exemple #43
0
def cmd_kick(main_window, argv):
    """ /kick <user> [<reason>]
		Kick a user from the current channel with an optional reason.
	"""
    if len(argv) < 2:
        return print_notification("Usage: /kick <user> [<reason>]")
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        return print_error("You have to be on a channel to do so.")
    connection.sushi.kick(ct.parent.name, ct.name, argv[1], " ".join(argv[2:]))
Exemple #44
0
def parse(main_window, text):
    argv = text.split(" ")

    if (not argv or
        (argv[0] and argv[0][0] != config.get("nigiri", "command_char"))):
        return False

    command = strip_command_char(argv[0])

    if not command:
        return False

    try:
        fun = _command_dict[command]
    except KeyError:
        print_error("No such command '%s'.\n" % (command))
    else:
        fun(main_window, argv)

    return True
Exemple #45
0
def sushi_nick(time, server, old, new):
	""" old == "" => new == current nick """
	stab = main_window.find_server(server)

	if not stab:
		print_error("missing stab '%s'" % server)
		return

	if not old or old == stab.get_nick():
		stab.set_nick(new)

		if main_window.current_tab in tabs.tree_to_list([stab]):
			main_window.update_divider()

		msg = format_message("actions", "nick",
			{"nick": old,
			 "new_nick": new},
			own = True,
			highlight = False)

		current_server_tab_print(server, msg)

	else:
		# print status message in channel tab
		old = connection.parse_from(old)[0]
		new = connection.parse_from(new)[0]

		msg = format_message("actions", "nick",
			{"nick": old,
			 "new_nick": new},
			own = False,
			highlight = False)

		msg.markup_cb = color_nick_markup_cb
		msg.markup_cb_kwargs = {"values":["nick","new_nick"]}

		for tab in stab.children:
			if type(tab) == tabs.Channel and tab.nicklist.has_nick(old):
				tab.nicklist.rename_nick(old,new)
				print_tab(tab, msg)
Exemple #46
0
def load(filename):
	""" load a module named after filename in the
		configured search path (tekka, plugin_dirs),
		instance the class named after the module
		(np for np.py) and register the bunch.

		On error this function calls print_error()
		with an specific error message and returns
		False. Otherwise this function returns True.
	"""
	global _plugins

	if _plugins.has_key(filename):
		print_error("A plugin with that name is already loaded.")
		return False

	mod_info = _find_module(filename)

	if not mod_info:
		return False

	modname, plugin = _load_module(filename, mod_info)
	classname = strip_suffix(filename)

	if not plugin:
		_unload_module(modname)
		return False

	try:
		instance = eval ("plugin.%s()" % (classname))

	except BaseException,e:
		logging.debug("plugin %s: %s" % (filename, traceback.format_exc(e)))
		print_error("Error while instancing plugin: %s" % (e))
		_unload_module(modname)
		return False
Exemple #47
0
def unload(filename):
	""" Call unload() in the plugin instance,
		unload the module and unregister it.
		On success this function returns True,
		otherwise it returns False.
	"""
	global _plugins

	try:
		entry = _plugins[filename]
	except KeyError:
		print_error("Failed to unload plugin '%s', does not exist." % (filename))
		return False

	# tell the instance, it's time to go
	try:
		entry[PLUGIN_INSTANCE].unload()
	except:
		pass

	_unload_module(entry[PLUGIN_MODNAME])

	# unregister locally
	return _unregister_plugin(filename)
def load(filename):
    """ load a module named after filename in the
		configured search path (tekka, plugin_dirs),
		instance the class named after the module
		(np for np.py) and register the bunch.

		On error this function calls print_error()
		with an specific error message and returns
		False. Otherwise this function returns True.
	"""
    global _plugins

    if _plugins.has_key(filename):
        print_error("A plugin with that name is already loaded.")
        return False

    mod_info = _find_module(filename)

    if not mod_info:
        return False

    modname, plugin = _load_module(filename, mod_info)
    classname = strip_suffix(filename)

    if not plugin:
        _unload_module(modname)
        return False

    try:
        instance = eval("plugin.%s()" % (classname))

    except BaseException, e:
        logging.debug("plugin %s: %s" % (filename, traceback.format_exc(e)))
        print_error("Error while instancing plugin: %s" % (e))
        _unload_module(modname)
        return False
Exemple #49
0
def run_tests(path, conn, replaces, dbtype):
    """Run SQL tests over a connection, returns a dict with results.

    Keyword arguments:
    path     -- String with the path having the SQL files for tests
    conn     -- A db connection (according to Python DB API v2.0)
    replaces -- A dict with replaces to perform at testing code
    dbtype   -- A string with the database type (postgresql|mssql)
    """
    files = sorted(glob(path))
    tests = {'total': 0, 'ok': 0, 'errors': 0}
    for fname in files:
        test_file = open('%s.json' % fname.rsplit('.', 1)[0], 'r')
        test_properties = load(test_file)
        test_desc = test_properties['test_desc']
        test_number = basename(fname).split('_')[0]
        req_ver = test_properties['server']['version']
        if check_ver(conn, req_ver['min'], req_ver['max'], dbtype):
            tests['total'] += 1
            f = open(fname, 'r')
            sentence = f.read()
            for key, elem in replaces.items():
                sentence = sentence.replace(key, elem)
            print_info("%s: Testing %s" % (test_number, test_desc))
            try:
                cursor = conn.cursor()
                cursor.execute(sentence)
                conn.commit()
                cursor.close()
                tests['ok'] += 1
            except Exception as e:
                print_error("Error running %s (%s)" % (test_desc, fname))
                try:
                    print_error(e.pgcode)
                    print_error(e.pgerror)
                except:
                    print_error(e)
                conn.rollback()
                tests['errors'] += 1
            f.close()
    return(tests)
Exemple #50
0
def run_tests(path, conn, replaces, dbtype):
    """Run SQL tests over a connection, returns a dict with results.

    Keyword arguments:
    path     -- String with the path having the SQL files for tests
    conn     -- A db connection (according to Python DB API v2.0)
    replaces -- A dict with replaces to perform at testing code
    dbtype   -- A string with the database type (postgresql|mssql)
    """
    files = sorted(glob(path))
    tests = {'total': 0, 'ok': 0, 'errors': 0}
    for fname in files:
        test_file = open('%s.json' % fname.rsplit('.', 1)[0], 'r')
        test_properties = load(test_file)
        test_desc = test_properties['test_desc']
        test_number = basename(fname).split('_')[0]
        req_ver = test_properties['server']['version']
        if check_ver(conn, req_ver['min'], req_ver['max'], dbtype):
            tests['total'] += 1
            f = open(fname, 'r')
            sentence = f.read()
            for key, elem in replaces.items():
                sentence = sentence.replace(key, elem)
            print_info("%s: Testing %s" % (test_number, test_desc))
            try:
                cursor = conn.cursor()
                cursor.execute(sentence)
                conn.commit()
                cursor.close()
                tests['ok'] += 1
            except Exception as e:
                print_error("Error running %s (%s)" % (test_desc, fname))
                try:
                    print_error(e.pgcode)
                    print_error(e.pgerror)
                except:
                    print_error(e)
                conn.rollback()
                tests['errors'] += 1
            f.close()
    return (tests)
Exemple #51
0
 def notifier(main_window, argv):
     if not main_window.current_tab:
         return print_error("You have to be on an active tab.")
     return fun(main_window, argv)
Exemple #52
0
def no_connection():
    if not connection.sushi.connected:
        print_error("No connection to maki.")
        return True
    return False
Exemple #53
0
		path (tekka, plugin_dirs).
	"""
	# get the name of the module to search for
	name = strip_suffix(filename)

	mod_info = None
	try:
		mod_info = imp.find_module(
			name, config.get_list("nigiri","plugin_dirs",[]))

	except ImportError, e:
		print_error("Error while finding module for '%s'" % (filename))
		return None

	if not mod_info:
		print_error("No plugin found for filename '%s'" % (filename))
		return None

	return mod_info

def _load_module(filename, mod_info):
	""" wrapper for imp.load_module.
		Returns a tuple with the identifying
		name of the loaded module and the
		module itself if loading was successful.
		Otherwise the function returns (None,None).
	"""
	name = strip_suffix(filename)
	plugin = None
	modname = _module_prefix + name
Exemple #54
0
def cmd_topic(main_window, argv):
    """ /topic [<new topic>] """
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        return print_error("You have to be on a channel to do so.")
    connection.sushi.topic(ct.parent.name, ct.name, " ".join(argv[1:]))
Exemple #55
0
 def display_error(self, error):
     logging.error("%s: %s" % (self._plugin_name, error))
     messages.print_error("%s: %s" % (self._plugin_name, error))
		path (tekka, plugin_dirs).
	"""
    # get the name of the module to search for
    name = strip_suffix(filename)

    mod_info = None
    try:
        mod_info = imp.find_module(
            name, config.get_list("nigiri", "plugin_dirs", []))

    except ImportError, e:
        print_error("Error while finding module for '%s'" % (filename))
        return None

    if not mod_info:
        print_error("No plugin found for filename '%s'" % (filename))
        return None

    return mod_info


def _load_module(filename, mod_info):
    """ wrapper for imp.load_module.
		Returns a tuple with the identifying
		name of the loaded module and the
		module itself if loading was successful.
		Otherwise the function returns (None,None).
	"""
    name = strip_suffix(filename)
    plugin = None
    modname = _module_prefix + name
Exemple #57
0
def cmd_topic(main_window, argv):
    """ /topic [<new topic>] """
    ct = main_window.current_tab
    if type(ct) != tabs.Channel:
        return print_error("You have to be on a channel to do so.")
    connection.sushi.topic(ct.parent.name, ct.name, " ".join(argv[1:]))
Exemple #58
0
def no_connection():
    if not connection.sushi.connected:
        print_error("No connection to maki.")
        return True
    return False
Exemple #59
0
 def display_error(self, error):
     logging.error("%s: %s" % (self._plugin_name, error))
     messages.print_error("%s: %s" % (self._plugin_name, error))
Exemple #60
0
 def notifier(main_window, argv):
     if not main_window.current_tab:
         return print_error("You have to be on an active tab.")
     return fun(main_window, argv)