예제 #1
0
 def insert_msg_to_db(self, outp):
     """Insert received sms into database."""
     if not self.cfg.has_section('database'):
         raise ConfigError('database not in sections')
     cfg = dict(self.cfg.items('database'))
     db = DbLink(**cfg)
     uuid = db.insert_msg(*outp)
     db.close()
예제 #2
0
 def run(self):
     """Check database from time to time. Send contents to triage using web services."""
     cfg = dict(self.cfg.items('database'))
     while True:
         try:
             msg = self.db.get_earliest_msg()
         except MySQLdb.OperationalError:
             self.db = DbLink(**cfg)
             msg = self.db.get_earliest_msg()
         if msg:
             res = WsLink().push_msg(*msg)
             if not res:
                 try:
                     self.db.del_msg(uuid)
                 except MySQLdb.OperationalError:
                     self.db = DbLink(**cfg)
                     self.db.del_msg(uuid)
             else:
                 log.error(res)
         time.sleep(self.sleep)
예제 #3
0
 def setUp(self):
     self.xml = XmlWrapper(minidom.parse(os.path.join(PATH, 'test', "mhlink.test")))
     tags = self.xml.test.database.children()
     
     db_params = {}
     for elem in tags:
         elem_name = str(elem.__str__().strip())
         if not elem_name:
             continue
         db_params[elem_name] = str(elem.get_text())
     
     self.reader = DbLink(**db_params)
예제 #4
0
 def __init__(self, config_file):
     self.cfg = ConfigParser.ConfigParser()
     self.cfg.read(config_file)
     
     try:
         self.sleep = int(self.cfg.get('database', 'sleep'))
         cfg = dict(self.cfg.items('database'))
         self.db = DbLink(**cfg)
     except ConfigParser.NoSectionError:
         raise ConfigError("'database' section not in config file")
     except ConfigParser.NoOptionError:
         raise ConfigError("'sleep' option missing in 'database' section")
예제 #5
0
class MsgProcess:
    def __init__(self, config_file):
        self.cfg = ConfigParser.ConfigParser()
        self.cfg.read(config_file)
        
        try:
            self.sleep = int(self.cfg.get('database', 'sleep'))
            cfg = dict(self.cfg.items('database'))
            self.db = DbLink(**cfg)
        except ConfigParser.NoSectionError:
            raise ConfigError("'database' section not in config file")
        except ConfigParser.NoOptionError:
            raise ConfigError("'sleep' option missing in 'database' section")
    
    def run(self):
        """Check database from time to time. Send contents to triage using web services."""
        cfg = dict(self.cfg.items('database'))
        while True:
            try:
                msg = self.db.get_earliest_msg()
            except MySQLdb.OperationalError:
                self.db = DbLink(**cfg)
                msg = self.db.get_earliest_msg()
            if msg:
                res = WsLink().push_msg(*msg)
                if not res:
                    try:
                        self.db.del_msg(uuid)
                    except MySQLdb.OperationalError:
                        self.db = DbLink(**cfg)
                        self.db.del_msg(uuid)
                else:
                    log.error(res)
            time.sleep(self.sleep)
    
    def close(self):
        """Close database connection."""
        self.db.close()
예제 #6
0
 def get_db_response(self, config, kw, lang):
     """Get automated response using keyword."""
     db = DbLink(**cfg)
     resp = db.get_response(kw, lang)
     db.close()
     return resp
예제 #7
0
class DbLinkTest(unittest.TestCase):
    """DbLink tests."""
    
    def setUp(self):
        self.xml = XmlWrapper(minidom.parse(os.path.join(PATH, 'test', "mhlink.test")))
        tags = self.xml.test.database.children()
        
        db_params = {}
        for elem in tags:
            elem_name = str(elem.__str__().strip())
            if not elem_name:
                continue
            db_params[elem_name] = str(elem.get_text())
        
        self.reader = DbLink(**db_params)
    
    def tearDown(self):
        self.reader.close()
    
    def test_set_uuid(self):
        """set_uuid() should return a string containing uuid (without spatial uniqueness)"""
        uuid = self.reader.set_uuid()
        print uuid
        print self.reader.set_uuid()
        self.assertTrue(isinstance(uuid, str))
    
    def test_get(self):
        pass#print self.reader.set_uuid()
    
    def test_insert(self):
        pass
    
    def test_delete(self):
        pass
    
    def test_get_response(self):
        pass
    
    def test_get_earliest_msg(self):
        print self.reader.get_earliest_msg()
    
    def test_get_msg(self):
        pass
    
    def test_get_contents(self):
        pass
    
    def test_get_headers(self):
        pass
    
    def test_get_attachments(self):
        pass
    
    def test_set_uuid(self):
        pass
    
    def test_insert_response(self):
        pass
    
    def test_insert_msg(self):
        pass
    
    def test_insert_contents(self):
        pass
    
    def test_insert_headers(self):
        pass
    
    def test_insert_attachments(self):
        pass
    
    def test_del_response(self):
        pass
    
    def test_del_msg(self):
        pass
    
    def test_del_contents(self):
        pass
        
    def test_del_headers(self):
        pass
    
    def test_del_attachments(self):
        pass
예제 #8
0
 def insert_msg_to_db(self, outp):
     """Insert received email into database."""
     cfg = dict(self.cfg.items('database'))
     db = DbLink(**cfg)
     uuid = db.insert_msg(*outp)
     db.close()