コード例 #1
0
ファイル: config.py プロジェクト: noomly/lunatic
    def load(self):
        c.write("loading configuration files...")

        c.write("--loading \'%s\'..." % basename(self.lunatic_conf_path))
        lunatic_conf_str = ""
        with open(self.lunatic_conf_path, encoding='utf-8') as file_1:
            lunatic_conf_str = lunatic_conf_str + file_1.read()

        self.lunatic_conf = yaml.load(lunatic_conf_str)

        for plugin_conf_name in listdir(self.plugins_conf_path):
            plugin_conf_name_split = plugin_conf_name.split('.')

            if isfile(join(self.plugins_conf_path, plugin_conf_name)) and \
                    len(plugin_conf_name_split) == 2 and \
                    plugin_conf_name_split[1] == "yaml":
                c.write("--loading \'%s\'..." % plugin_conf_name)
                plugin_conf_str = ""
                with open(join(self.plugins_conf_path,
                               plugin_conf_name)) as file_1:
                    plugin_conf_str = plugin_conf_str + file_1.read()

                self.plugins_conf[plugin_conf_name_split[0]] = yaml.safe_load(
                    plugin_conf_str)
                self.plugins_conf_save = copy.deepcopy(self.plugins_conf)
                # TODO: compare last both command and if changes -> save to
                # file

        c.write("all configuration files loaded!")
コード例 #2
0
ファイル: session.py プロジェクト: noomly/lunatic
    def __listen(self):
        while threading.main_thread().is_alive():
            try:
                self.recv_data = self.irc.recv(4096).decode('utf-8')
            except socket.timeout:
                pass

            if self.recv_data is not None:
                c.write("RECEIVED : \"%s\"" % self.recv_data)

                recv_data_split = self.recv_data.split(' ')

                if recv_data_split[0] == "PING":
                    self.__send("PONG %s" % recv_data_split[1])
コード例 #3
0
ファイル: lunatic.py プロジェクト: noomly/lunatic
    def __init__(self, irc_session, config):
        self.irc_session = irc_session
        self.config = config

        c.write("loading plugins...")

        self.plugins_ = []
        plugins_name = []
        plugins_path = "lunatic/plugins"
        plugins_path_import = "plugins"

        for plugin_name in listdir(plugins_path):
            plugin_name_split = plugin_name.split('.')

            if isfile(join(plugins_path, plugin_name)) and \
                    len(plugin_name_split) == 2 and \
                    plugin_name_split[1] == "py" and \
                    plugin_name != "__init__.py":

                plugins_name.append(plugin_name_split[0])
                c.write("--found plugin \'%s\'" % plugin_name)

        for plugin_name in plugins_name:
            c.write("--loading plugin \'%s\'..." % plugin_name)
            __import__(
                join(plugins_path_import, plugin_name).replace('/', '.'))
            self.plugins_.append(getattr(plugins, plugin_name))

        for plugin in self.plugins_:
            plugin.load()

        c.write("all plugins loaded!")
コード例 #4
0
ファイル: __main__.py プロジェクト: noomly/lunatic
def main():
    c.write("Lunatic started")

    if c.DEBUG:
        config = Config("lunatic.yaml.debug")
    else:
        config = Config("lunatic.yaml")
    config.load()

    irc_session = Session(config)
    irc_session.connect()

    lunatic = Lunatic(irc_session, config)

    lunatic.loop()
コード例 #5
0
ファイル: config.py プロジェクト: noomly/lunatic
    def save_changes(self):
        c.write("saving configuration files...")

        for plugin_conf_name in self.plugins_conf:
            if self.plugins_conf[plugin_conf_name] != \
               self.plugins_conf_save[plugin_conf_name]:
                c.write("--saving \'%s\'..." % plugin_conf_name)

                file_1 = open(
                    join(self.plugins_conf_path, plugin_conf_name + ".yaml"),
                    'w')

                yaml.dump(self.plugins_conf[plugin_conf_name],
                          file_1,
                          default_flow_style=False)

                file_1.close()
コード例 #6
0
ファイル: session.py プロジェクト: noomly/lunatic
 def __send(self, data):
     c.write("SENT : \"%s\"" % data)
     self.irc.send((data + "\r\n").encode('utf-8'))
コード例 #7
0
import constants
import pack_unpack_c
import pack_unpack_h
import enum_atom
import structs
import sys
import computers_h
import computers_c
import test_h
import test_c
import send_receive
import bus

if __name__ == '__main__':
    specpath = sys.argv[1]
    specfile = open(specpath, 'r')
    system = ParseCAN.spec.System.from_yaml(specfile)
    can = system.protocol['name']['can']

    constants.write(can)
    pack_unpack_c.write(can)
    pack_unpack_h.write(can)
    enum_atom.write(can)
    send_receive.write(can)
    structs.write(can)
    bus.write(can, system.computer)
    computers_h.write(can, system.computer)
    computers_c.write(can, system.computer)
    test_h.write(can)
    test_c.write(can)