コード例 #1
0
ファイル: cli.py プロジェクト: nictuku/nwu
 def __init__(self, config=None, initialize=True):
     # FIXME: remove this 'initialize' check
     # it's used the tests, but I could simply override the class instead
     if initialize:
         if not config:
             config = Config()
         # FIXME: use nwu.server.app instead when it's available
         db_bind(config.get("database", "connection_string",
             "sqlite:////var/lib/nwu/nwu.db"))
コード例 #2
0
ファイル: node_sync.py プロジェクト: nictuku/nwu
    def store_spool(self, spool, item_list, wipe_old=False):
        """Stores data in the services pool directory.
        
        It takes a list of itens, each of which contains a list of
        "section", "option" and "value".

        Security is a must here.
        """
        log.debug("Writing spool of type '%s" % spool)
        # FIXME: check for right permissions in the spool dir and files
        spool_path = "/var/spool/nwu/nw.%s" % spool
        if wipe_old == True:
            try:
                os.unlink(spool_path)
            except:
                pass
            else:
                log.info("Deleted old spool file.")
        store = Config(spool_path)

        for it in item_list:
            if type(it) is not list or len(it) < 2:
                raise Exception, "item_list is not right."
            section = it[0]
            option = it[1]
            if len(it) > 2:
                value = it[2]
            else:
                value = "placeholder"
            if option == "":
                option = "placeholder"
            log.debug("Found " + str(section) + ": " + str(option))
            if not store.has_section(section):
                # create section in the task file
                store.add_section(section)
            store.set(section, option, value)
        try:
            updt_spool = open(spool_path, "w")
            # XXX: What happens with updt_spool here? Looks unused.
            #      Either way, udpt_spool.close() might be missing here.
        except:
            log.error("!!! Problem writing to spool directory in " + spool_path + ".")
            pass
        else:
            log.info("Updating spool file for " + spool + ".")
            store.write(updt_spool)