コード例 #1
0
ファイル: dbqueue.py プロジェクト: Loffe/errors-included
import Queue
import re
import data as data
import simplejson as json
from data import NetworkInQueueItem, NetworkOutQueueItem
from shared.util import getLogger, print_color
log = getLogger("server.log")

class DatabaseQueue(Queue.Queue):
    direction_in, direction_out = range(2)

    def __init__(self, database, direction):
        Queue.Queue.__init__(self)
        self.item_type = [data.NetworkInQueueItem, data.NetworkOutQueueItem][direction]
        self.db = database

    # Return the number of items that are currently enqueued
    def _qsize(self):
        # @TODO
        return 2

    # Check whether the queue is empty
    def _empty(self):
        session = self.db._Session()
        if self.item_type == data.NetworkOutQueueItem:
            print "sending few (no) messages!"
            return session.query(data.NetworkOutQueueItem).filter(data.NetworkOutQueueItem.sent == 0).count() == 0
        if self.item_type == data.NetworkInQueueItem:
            return session.query(data.NetworkInQueueItem).filter(data.NetworkInQueueItem.sent == 0).count() == 0
        session.close()
コード例 #2
0
ファイル: networkqueue.py プロジェクト: Loffe/errors-included
import gobject
import socket
import threading
import Queue

import shared.data
from shared.dbqueue import DatabaseInQueue, DatabaseOutQueue

from shared.util import getLogger
log = getLogger("nw-queue.log")

class NetworkQueue(gobject.GObject):
    queue = None
    socket = None

    def __init__(self, socket, databasequeue):
        self.__gobject_init__()
        self.socket = socket
        self.queue = databasequeue

    def replace_socket(self, socket):
        print self.__class__.__name__, "got a new socket"
        self.socket = socket

gobject.type_register(NetworkQueue)
gobject.signal_new("socket-broken", NetworkQueue, gobject.SIGNAL_RUN_FIRST,
                   gobject.TYPE_NONE, ())

class NetworkOutQueue(NetworkQueue):
    sending = False
    need_connection = True
コード例 #3
0
ファイル: main.py プロジェクト: Loffe/errors-included
#!/usr/bin/env python
# coding: utf-8

from shared.util import getLogger
log = getLogger("client.log")
log.debug("main imported log")
import clientgui

if __name__ == "__main__":
    log.debug("__main__")

    # Create and run GUI
    gui = clientgui.ClientGui()
    gui.run()
コード例 #4
0
import config
import dbus
import dbus.mainloop.glib
import dbus.service
import gobject
import select
import shared.data
import socket
import subprocess
import sys
import threading
import time
from shared.networkqueue import NetworkOutQueue, NetworkInQueue
from shared.util import getLogger
log = getLogger("queue.log")

class ClientNetworkHandler(dbus.service.Object):
    output = None
    input = None
    server = ()
    socket = None
    connected = False
    closing = False
    use_backup = False

    def __init__(self):
        log.info("Queue startin up")
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.session_bus = dbus.SessionBus()
        self.name = dbus.service.BusName("included.errors.Client", self.session_bus)
        dbus.service.Object.__init__(self, self.session_bus,