Beispiel #1
0
    def start(self):
        """
        \brief Start the daemon
        """
        # Check whether daemon module is properly installed
        if self.check_python_daemon() == False:
            self.terminate()
        import daemon

        # Prepare Options().lock_file
        self.make_lock_file()

        # Prepare the daemon context
        dcontext = daemon.DaemonContext(
            detach_process=(not Options().no_daemon),
            working_directory=Options().working_directory,
            pidfile=Options().lock_file if not Options().no_daemon else None,
            stdin=sys.stdin,
            stdout=sys.stdout,
            stderr=sys.stderr,
            uid=Options().uid,
            gid=Options().gid,
            files_preserve=Log().files_to_keep)

        # Prepare signal handling to stop properly if the daemon is killed
        # Note that signal.SIGKILL can't be handled:
        # http://crunchtools.com/unixlinux-signals-101/
        dcontext.signal_map = {
            signal.SIGTERM: self.signal_handler,
            signal.SIGQUIT: self.signal_handler,
            signal.SIGINT: self.signal_handler
        }

        if Options().debugmode == True:
            self.main()
        else:
            with dcontext:
                self.make_pid_file()
                try:
                    self.main()
                except Exception, why:
                    Log.error("Unhandled exception in start: %s" % why)
# CREATE TABLE test (
#     a INTEGER PRIMARY KEY,
#     b INTEGER
# );
# INSERT INTO test (a, b) VALUES (1,1), (2,2), (3,1), (4,4);
# CREATE TABLE test2 (
#     c INTEGER PRIMARY KEY,
#     d INTEGER REFERENCES test
# );
# INSERT INTO test2 (c, d) VALUES (10,1), (20,2), (30,2);

from manifold.gateways.postgresql import PostgreSQLGateway
from manifold.core.query import Query
from manifold.util.log import Log

l = Log('test_postgresql')


def pg_cb(x):
    print "CALLBACK: %r" % x


# Issue a simple query from the psql gateway

c = {'db_user': '******', 'db_password': None, 'db_name': 'test'}
q = Query(object='test', filters=[['b', ']', 2]], fields=['a', 'b'])
gw = PostgreSQLGateway(router=None,
                       platform='pg',
                       query=q,
                       config=c,
                       user_config=None,