Exemple #1
0
 def __init__(self):
     super(TopupParser, self).__init__('UNKN', 'INVL', 'TopupParser')
     self.agent_manager = ManageAgent(self.dbconn, self.cacheconn)
     self.dm = DepositMutation(5, self.dbconn, self.cacheconn)
     self.um = UnitMutation(5, self.dbconn, self.cacheconn)
     self.hlrmap = HLRMap(self.dbconn, self.cacheconn)
     cdf = config.DEFAULT_EXPIRE
     self.c_product = DBCache(const.PRODUCT_PREFIX, cdf, const.PRODUCT_SQL)
     self.c_price = DBCache(const.AGENTPRICE_PREFIX, cdf, const.AGENTPRICE_SQL)
     self.c_operator = DBCache(const.OPERATOR_PREFIX, cdf, const.OPERATOR_SQL,
                               user_func={'prefix': lambda x: x.split(',')})
     map(lambda x: x.setConn(self.dbconn, self.cacheconn), [
             self.c_product,
             self.c_price,
             self.c_operator,
         ])
     self.rx_check, self.rx_topup, self.rx_separator = (None, None, None)
     self._init2()
     self.log = mylogger('TopupParser', 'topupparser.log')
     self.to_db = []
     self.parsed = []
     self.handler = [
             self.check,
         ]
     self.processUNKN = self.process
Exemple #2
0
 def __init__(self):
     super(LoadBalance, self).__init__("LB")
     self.operator = self._loadOperator()
     self.c_product = DBCache(const.PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.PRODUCT_SQL)
     self.c_op_product = DBCache(const.OP_PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.OP_PRODUCT_SQL)
     self.c_device = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL)
     self.c_base_price = DBCache(const.CHIP_BASE_PRICE_PREFIX, config.DEFAULT_EXPIRE, const.CHIP_BASE_PRICE_SQL)
     map(
         lambda x: x.setConn(self.dbconn, self.cacheconn),
         [self.c_product, self.c_op_product, self.c_device, self.c_base_price],
     )
     # self.hlr_cache = HLRCacheForLB(self.dbconn, self.cacheconn)
     # self.hlr_cache.cacheAllTopupDevice()
     self.lb = LBTopup(self.dbconn)
     self.lb.cleanRebuild()
     self.hm = HLRMap(self.dbconn, self.cacheconn)
     self.hm.rebuild()
     self.dm = DepositMutation(5, self.dbconn, self.cacheconn)
     self.last_op_prod = None
     self.last_device = None
     self.last_hlr_id = None
     self.last_tr_id = None
     self.last_tr_data = None
     self.change_method = None
     self.log = mylogger("LoadBalance", "loadbalance.log")
Exemple #3
0
 def __init__(self):
     BaseComponent.__init__(self, 'YM')
     self.c_mutdepo = DBCache(const.MUTATION_PREFIX, config.DEFAULT_EXPIRE,
         const.MUTATION_SQL)
     self.c_mutdepo.setConn(self.dbconn, self.cacheconn)
     self.c_ym_handler = DBCache2(const.YM_HANDLER_PREFIX, config.DEFAULT_EXPIRE,
         const.YM_HANDLER_SQL)
     self.c_ym_handler.setConn(self.dbconn, self.cacheconn)
     self.rrb = {}
     self.prepareCache()
     self.ymgate = '{0}@{1}'.format(config.IMGATE, config.MSG_SERVER)
     self.log = mylogger('YMHandler', 'YMHandler.log')
Exemple #4
0
 def __init__(self):
     BaseComponent.__init__(self, "AU")
     self.c_operator = DBCache(
         const.OPERATOR_PREFIX,
         config.DEFAULT_EXPIRE,
         const.OPERATOR_SQL,
         user_func={"prefix": lambda x: x.split(",")},
     )
     self.c_product = DBCache(const.PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.PRODUCT_SQL)
     self.c_agentprice = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE, const.AGENTPRICE_SQL)
     self.dm = DepositMutation(5, self.dbconn, self.cacheconn)
     self.um = UnitMutation(5, self.dbconn, self.cacheconn)
     self.log = mylogger("Authorizer", "authorizer.log")
Exemple #5
0
 def __init__(self, username, password, realm, resource, msg_queue=None, prtimeout=10):
     self.log = mylogger('XMPPMessaging', 'msg.log')
     self.next_keepalive = datetime.now() + timedelta(seconds=15)
     self.go = True
     self.message_queue = msg_queue
     self.username = username
     self.password = password
     self.realm = realm
     self.resource = resource
     self.connect(username, password, realm, resource)
     # incoming message thread
     self.process_thread = threading.Thread(target=self._tprocess,
                                            args=(prtimeout,))
     self.process_thread.start()
     self.client.sendInitPresence(0)
     self.send_lock = threading.Lock()
Exemple #6
0
 def __init__(self, port, emulate_type=False, persistent=False):
     self.persistent = False
     self.port = port
     self.log = mylogger("Device", "md_{0}.log".format(port))
     self.fail_sms_count = 0
     self.saengine = sqlalchemy.create_engine(lconf.DBCONN_URI)
     SABase.metadata.create_all(self.saengine)
     self.sasession = scoped_session(sessionmaker(bind=self.saengine))
     self.persistent = persistent
     self.me = device.Device(self.port, emulate_type)
     if persistent:
         self.ser = serial.Serial(
             r"{0}{1}{2}".format(self.me.prefix, self.me.infix, self.me.port),
             self.me.baudrate,
             timeout=0.5,
             writeTimeout=0.5,
             rtscts=10,
             dsrdtr=0,
         )
         self.me.setPersistent(self.ser)
     self.detectMEType()
     self.cmd_handler = {"SMSG": self.commandSMSG, "JBDV": self.commandJBDV, "RCMD": self.reconnect}
Exemple #7
0
 def __init__(self, port, emulate_type=True):
     if "linux" in sys.platform:
         self.prefix = "/dev/"
         self.infix = "tty"
     else:
         self.prefix = "\\\\.\\"
         self.infix = "COM"
     self.emulate_type = emulate_type
     self.persistent = False
     self.ser = None
     self.baudrate = BAUDRATE.pop(0)
     self.valid_port = True
     self.log = mylogger("Device", "{0}.log".format(port))
     self.port = port
     self.buffer = ""
     self.pdu = messaging.PDU()
     self.modem_type = 0
     if not self.confirmBaudRate():
         self.valid_port = False
         return
     self.modem_type = self.getModemType()
     self.initModem()
Exemple #8
0
 def __init__(self):
     XMPPClient.__init__(self, lconf.SERVERNAME, {
         'user': lconf.LEAFSERVER,
         'pass': lconf.LEAFSERVER_PASS,
         'realm': lconf.MSG_SERVER,
     })
     self.log = mylogger('LeafController', 'leaf.log')
     self.shutdown = False
     self.notify_in = '{0}@{1}/{2}'.format(lconf.NOTIFYIN, lconf.MSG_SERVER,
                                           lconf.ROOT_SERVER_NAME)
     self.rexes.insert(0, (r'^{0}@{1}(/[^:]+)?:(?P<command>\w+)=(?P<param>'
         '[^,]*)$'.format(lconf.NOTIFYOUT, lconf.MSG_SERVER),
         self.handleLeafCommand))
     self.pdu = messaging.PDU()
     self.check_sms = False
     if 'linux' in sys.platform:
         p = '/home/szhan/Dev'
     else:
         p = sys.path[0]
     self.saengine = sqlalchemy.create_engine(lconf.DBCONN_URI)
     SABase.metadata.create_all(self.saengine)
     self.sasession = scoped_session(sessionmaker(bind=self.saengine))
     threading.Thread(target=self.sendMessageToCore).start()
Exemple #9
0
 def __init__(self):
     BaseComponent.__init__(self, 'MC')
     self.logger = mylogger('SanityCheck')
Exemple #10
0
 def __init__(self):
     BaseComponent.__init__(self, 'MC')
     self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE,
         const.DEVICES_SQL)
     self.logger = mylogger('MassStockCheck')
Exemple #11
0
 def __init__(self):
     BaseComponent.__init__(self, 'OC')
     self.log = mylogger('OtherCommand', 'othercommand.log')
     self.num = {}
     self.dev = {}
Exemple #12
0
 def __init__(self):
     self.pin = hashlib.md5('!elogic123').hexdigest()
     self.device_update = {}
     self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE,
         const.DEVICES_SQL)
     self.logger = mylogger('AdminHelper')
Exemple #13
0
import traceback
from datetime import datetime

from pulsa import config
from pulsa.common import const
from pulsa.comp.CheckTicket import CheckTicket
from pulsa.comp.bca import BCA
from pulsa.comp.mandiri import Mandiri
from pulsa.helper.log import mylogger


__BANK_SIGNAL = '__bank_signal'


if __name__ =='__main__':
    banklog = mylogger('Bank', 'bank.log')
    ct = CheckTicket()
    banks = [
            BCA(ct.dbconn),
            Mandiri(ct.dbconn),
        ]
    while True:
        if ct.cacheconn.get(__BANK_SIGNAL) in (0, '0'):
            time.sleep(10)
            continue
        else:
            i = datetime.now()
            for b in banks:
                try:
                    if ct.cacheconn.get(__BANK_SIGNAL) in (0, '0'):
                        break
Exemple #14
0
import multiprocessing
import time
import Queue
import traceback

from pulsa import config
from pulsa.comp.NotifyDispatch import NotifyIn, notifyOut
from pulsa.comp.ConfigHandler import ConfigHandler
from pulsa.comp.OtherCmd import OtherCommand
from pulsa.helper.log import mylogger

core1log = mylogger('Core1', 'core1.log')

def prNotifyIn():
    global core1log
    ni = NotifyIn(config.ROOT_SERVER_NAME,
    {'user': config.NOTIFYIN,
    'pass': config.NOTIFYIN_PASS,
    'realm': config.MSG_SERVER})
    while True:
        try:
            ni.processMsgNoWait()
        except Queue.Empty:
            if not ni.flushToDB():
                time.sleep(1)
                ni.dbKeepAlive()
        except:
            errorstr = traceback.format_exc()
            print errorstr
            core1log.error('<NotifyIn>\n{0}'.format(errorstr))
            # raw_input()
Exemple #15
0
 def __init__(self):
     self.logger = mylogger('H2HServer', 'h2hserver.log')
Exemple #16
0
from pulsa.comp.Authorizer import Authorizer
from pulsa.comp.NotifyDispatch import NotifyIn, notifyOut
from pulsa.comp.LoadBalance import LoadBalance
from pulsa.comp.IMHandler import IMDispatch
from pulsa.comp.HPSync import BaseSync
from pulsa.comp.Sync import LowPrioritySync
from pulsa.comp.ConfigHandler import ConfigHandler
from pulsa.comp.H2HHandler import H2HHandler
from pulsa.comp.YMHandler import YMHandler
from pulsa.comp.FrameLogic import FrameLogic
from pulsa.comp.Broadcast import Broadcast
from pulsa.comp.Stock import Stock
from pulsa.comp.TopupParser import *
from pulsa.helper.log import mylogger

core2log = mylogger('Core2', 'core2.log')


def prAuthorizer():
    global core2log
    shutdown = False
    auth = Authorizer()
    while not shutdown:
        try:
            job = auth.authorize()
            if not job:
                time.sleep(1)
        except:
            errorstr = traceback.format_exc()
            print errorstr
            core2log.error('<Authorizer>\n{0}'.format(errorstr))