当前位置: 首页>>代码示例>>Python>>正文


Python database.DbHelper类代码示例

本文整理汇总了Python中domogik.common.database.DbHelper的典型用法代码示例。如果您正苦于以下问题:Python DbHelper类的具体用法?Python DbHelper怎么用?Python DbHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DbHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

def upgrade():
    db = DbHelper()
    with db.session_scope():
        db.add_user_account_with_person('Anonymous', 'Anonymous', 'Rest', 'Anonymous')
    del db
        
    pass
开发者ID:domogik,项目名称:domogik,代码行数:7,代码来源:404f46a359dc_add_anonymous.py

示例2: test_user_config_file

def test_user_config_file(user_home, user_entry):
    info("Check user config file contents")
    import ConfigParser
    config = ConfigParser.ConfigParser()
    config.read("/etc/domogik/domogik.cfg")

    #check [domogik] section
    dmg = dict(config.items('domogik'))
    database = dict(config.items('database'))
    admin = dict(config.items('admin'))
    butler = dict(config.items('butler'))
    backup = dict(config.items('backup'))
    ok("Config file correctly loaded")

    info("Parse [domogik] section")
    import domogik

    #Check ix xpl port is not used
    _check_port_availability("0.0.0.0", 3865, udp = True)
    ok("xPL hub IP/port is not bound by anything else")

    parent_conn, child_conn = Pipe()
    p = Process(target=_test_user_can_write, args=(child_conn, dmg['log_dir_path'],user_entry,))
    p.start()
    p.join()
    assert parent_conn.recv(), "The directory %s for log does not exist or does not have right permissions" % dmg['log_dir_path']

    assert dmg['log_level'] in ['debug','info','warning','error','critical'], "The log_level parameter does not have a good value. Must \
            be one of debug,info,warning,error,critical"
    ### obsolete
    #if not os.path.isdir(dmg['src_prefix'] + '/share/domogik'):
    #    try:
    #        f = os.listdir("%s/share/domogik" % dmg['src_prefix'])
    #        f.close()
    #    except OSError:
    #        fail("Can't access %s/share/domogik. Check %s is available for domogik user (if you are in development mode, be sure the directory which contains the sources is available for domogik user)." % (dmg['src_prefix'],dmg['src_prefix']))
    #        exit()
    ok("[domogik] section seems good")

    # check [database] section
    info("Parse [database] section")
    assert database['type'] == 'mysql', "Only mysql database type is supported at the moment"

    uid = user_entry.pw_uid
    os.setreuid(0,uid)
    old_home = os.environ['HOME']
    os.environ['HOME'] = user_home
    from domogik.common.database import DbHelper
    d = DbHelper()
    os.setreuid(0,0)
    os.environ['HOME'] = old_home
    assert d.get_engine() != None, "Engine is not set, it seems something went wrong during connection to the database"

    ok("[database] section seems good")

    # Check [admin] section
    info("Parse [admin] section")
    for ipadd in get_ip_for_interfaces(admin['interfaces'].split(",")):
        _check_port_availability(ipadd, admin['port'])
    ok("Admin server IP/port is not bound by anything else")
开发者ID:domogik,项目名称:domogik,代码行数:60,代码来源:test_config.py

示例3: _callback

 def _callback(self, message):
     """ Callback for the xpl message
     @param message : the Xpl message received
     """
     self._log_stats.debug("Stat received for device {0}." \
             .format(self._dev['name']))
     current_date = calendar.timegm(time.gmtime())
     stored_value = None
     try:
         # find what parameter to store
         for param in self._stat.params:
             # self._log_stats.debug("Checking param {0}".format(param))
             if param.sensor_id is not None and param.static is False:
                 if param.key in message.data:
                     value = message.data[param.key]
                     # self._log_stats.debug( \
                     #        "Key found {0} with value {1}." \
                     #        .format(param.key, value))
                     store = True
                     if param.ignore_values:
                         if value in eval(param.ignore_values):
                             self._log_stats.debug( \
                                     "Value {0} is in the ignore list {0}, so not storing." \
                                     .format(value, param.ignore_values))
                             store = False
                     if store:
                         # check if we need a conversion
                         if self._sen.conversion is not None and self._sen.conversion != '':
                             value = call_package_conversion(\
                                         self._log_stats, \
                                         self._dev['client_id'], \
                                         self._sen.conversion, \
                                         value)
                         self._log_stats.info( \
                                 "Storing stat for device '{0}' ({1}) and sensor'{2}' ({3}): key '{4}' with value '{5}' after conversion." \
                                 .format(self._dev['name'], self._dev['id'], self._sen.name, self._sen.id, param.key, value))
                         # do the store
                         stored_value = value
                         my_db = DbHelper()
                         with my_db.session_scope():
                             my_db.add_sensor_history(\
                                     param.sensor_id, \
                                     value, \
                                     current_date)
                         del(my_db)
                     else:
                         self._log_stats.debug("Don't need to store this value")
                 #else:
                 #    self._log_stats.debug("Key not found in message data")
             #else:
             #    self._log_stats.debug("No sensor attached")
     except:
         self._log_stats.error(traceback.format_exc())
     # publish the result
     self._pub.send_event('device-stats', \
                   {"timestamp" : current_date, \
                   "device_id" : self._dev['id'], \
                   "sensor_id" : self._sen.id, \
                   "stored_value" : stored_value})
开发者ID:Basilic,项目名称:domogik,代码行数:59,代码来源:xplgw.py

示例4: __init__

    def __init__(self, json_path):
        """ Init tool
            @param plugin_name : plugin name
        """

        self._db = DbHelper()
        try:
            self.pkg = PackageJson(path = json_path).json
        except PackageException as exp:
            print("Error in json file:")
            print( exp.value )
            exit()
        except:
            print(str(traceback.format_exc()))
            return
        print("Json file OK")

        # check type == plugin
        if self.pkg["identity"]["type"] not in ["plugin", "external"]:
            print("Error : this package type is not recognized")
            exit()
        # check if json version is at least 2
        if self.pkg['json_version'] < 2:
            print("Error : this package is to old for this version of domogik")
            exit()
开发者ID:capof,项目名称:domogik,代码行数:25,代码来源:packagedata.py

示例5: __init__

    def __init__(self, handler_params, xpl):
        """ 
        @param handler_params : The server params 
        @param xpl : A xPL Manager instance 
        """

        try:
            self.myxpl = xpl

            # logging initialization
            log = logger.Logger('rest-stat')
            self._log_stats = log.get_logger('rest-stat')
            self._log_stats.info("Rest Stat Manager initialisation...")
    
            # create the dbHelper 
            self._db = DbHelper()

            ### Rest data
            self.handler_params = handler_params
            self.handler_params.append(self._log_stats)
            self.handler_params.append(self._db)
    
            self._event_requests = self.handler_params[0]._event_requests
            self.get_exception = self.handler_params[0].get_exception

            self.stats = None
        except :
            self._log_stats.error("%s" % traceback.format_exc())
开发者ID:capof,项目名称:domogik,代码行数:28,代码来源:stat.py

示例6: __init__

 def __init__(self, log, queue, conv, pub):
     threading.Thread.__init__(self)
     self._db = DbHelper()
     self._log = log
     self._queue = queue
     self._conv = conv
     self._pub = pub
开发者ID:ewintec,项目名称:domogik,代码行数:7,代码来源:xplgw.py

示例7: __init__

 def __init__(self, log, queue, storeQueue):
     threading.Thread.__init__(self)
     self._db = DbHelper()
     self._log = log
     self._queue = queue
     self._queue_store = storeQueue
     # on startup, load the device parameters
     self.on_device_changed()
开发者ID:domogik,项目名称:domogik,代码行数:8,代码来源:xplgw.py

示例8: _request_config_cb

    def _request_config_cb(self, message):
        '''
        Callback to receive a request for some config stuff
        @param message : the xPL message
        '''
        #try:
        self._db = DbHelper(engine=self._engine)
        techno = message.data['plugin']
        hostname = message.data['hostname']
        key = message.data['key']
        msg = "Request  h=%s, t=%s, k=%s" % (hostname, techno, key)
        print(msg)
        self.log.debug(msg)
        if "value" in message.data:
            new_value = message.data['value']
        else:
            new_value = None
        if "element" in message.data:
            element = message.data['element']
        else:
            element = None

        msg = "Request  h=%s, t=%s, k=%s (2)" % (hostname, techno, key)
        print(msg)
        self.log.debug(msg)
        # Set configuration
        if new_value:
            msg = "Set config h=%s, t=%s, k=%s, v=%s" % (hostname, techno, key, new_value)
            print msg
            self.log.debug(msg)
            self._set_config(techno, hostname, key, new_value)

        # Send configuration
        else:
            msg = "Request  h=%s, t=%s, k=%s (send)" % (hostname, techno, key)
            print(msg)
            self.log.debug(msg)
            if element:
                msg = "Request  h=%s, t=%s, k=%s (send if element)" % (hostname, techno, key)
                print(msg)
                self.log.debug(msg)
                self._send_config(techno, hostname, key, self._fetch_elmt_config(techno, element, key), element)
            else:
                msg = "Request  h=%s, t=%s, k=%s (send else)" % (hostname, techno, key)
                print(msg)
                self.log.debug(msg)
                if not key:
                    msg = "Request  h=%s, t=%s, k=%s (send if not key)" % (hostname, techno, key)
                    print(msg)
                    self.log.debug(msg)
                    keys = self._fetch_techno_config(techno, hostname, key).keys()
                    values = self._fetch_techno_config(techno, hostname, key).values()
                    self._send_config(techno, hostname, keys, values)
                else:
                    msg = "Request  h=%s, t=%s, k=%s (send else of if not key)" % (hostname, techno, key)
                    print(msg)
                    self.log.debug(msg)
                    self._send_config(techno, hostname, key, self._fetch_techno_config(techno, hostname, key))
开发者ID:capof,项目名称:domogik,代码行数:58,代码来源:dbmgr.py

示例9: _callback

 def _callback(self, message):
     """ Callback for the xpl message
     @param message : the Xpl message received 
     """
     my_db = DbHelper()
     self._log_stats.debug("Stat received for device %s." \
             % (self._dev.name))
     current_date = calendar.timegm(time.gmtime())
     device_data = []
     try:
         # find what parameter to store
         for p in self._stat.params:
             if p.sensor_id is not None:
                 if p.key in message.data:
                     value = message.data[p.key]
                     self._log_stats.debug("Key found %s with value %s." \
                         % (p.key, value))
                     store = True
                     if p.ignore_values:
                         if value in eval(p.ignore_values):
                             self._log_stats.debug("Value %s is in the ignore list %s, so not storing." \
                                  % (value, p.ignore_values))
                             store = False
                     if store:
                         # check if we need a conversion
                         if self._sen.conversion is not None and self._sen.conversion != '':
                             value = call_package_conversion(\
                                         self._log_stats, self._dev.device_type.plugin_id, \
                                         self._sen.conversion, value)
                             self._log_stats.debug("Key found %s with value %s after conversion." \
                                 % (p.key, value))
                         # do the store
                         device_data.append({"value" : value, "sensor": p.sensor_id})
                         my_db.add_sensor_history(p.sensor_id, value, current_date)
     except:
         error = "Error when processing stat : %s" % traceback.format_exc()
         print("==== Error in Stats ====")
         print(error)
         print("========================")
         self._log_stats.error(error)
     # put data in the event queue
     self._event_requests.add_in_queues(self._dev.id, 
             {"timestamp" : current_date, "device_id" : self._dev.id, "data" : device_data})
     del(my_db)
开发者ID:capof,项目名称:domogik,代码行数:44,代码来源:stat.py

示例10: __init__

 def __init__(self, log):
     """ Create ScenarioManager instance
         @param log : Logger instance
     """
     # Keep list of conditions as name : instance
     self._instances = {}
     # an instance of the logger
     self.log = log
     # load all scenarios from the DB
     self._db = DbHelper()
     self.load_scenarios()
开发者ID:Nico0084,项目名称:domogik,代码行数:11,代码来源:manager.py

示例11: __init__

 def __init__(self):
     """ Initiate DbHelper, Logs and config
     """
     XplPlugin.__init__(self, 'xplgw')
     self.log.info(u"XPL manager initialisation...")
     self._db = DbHelper()
     self.pub = MQPub(zmq.Context(), 'xplgw')
     self.stats = None
     self.client_xpl_map = {}
     self._load_client_to_xpl_target()
     self.load()
     self.ready()
开发者ID:Basilic,项目名称:domogik,代码行数:12,代码来源:xplgw.py

示例12: __init__

    def __init__(self):
        """ Initiate DbHelper, Logs and config
        """
        XplPlugin.__init__(self, 'xplgw', log_prefix = "")
        MQAsyncSub.__init__(self, self.zmq, 'xplgw', ['client.conversion', 'client.list'])

        self.log.info(u"XPL manager initialisation...")
        self._db = DbHelper()
        self.pub = MQPub(zmq.Context(), 'xplgw')
        self.stats = None
        self.client_xpl_map = {}
        self.client_conversion_map = {}
        self._load_client_to_xpl_target()
        self._load_conversions()
        self.load()
        self.ready()
开发者ID:anuraagkapoor,项目名称:domogik,代码行数:16,代码来源:xplgw.py

示例13: __init__

    def __init__(self, json_path):
        """ Init tool
            @param plugin_name : plugin name
        """

        self._db = DbHelper()
        try:
            self.pkg = PackageJson(path = json_path).json
        except:
            print(str(traceback.format_exc()))
            return
        print("Json file OK")

        # check type == plugin
        if self.pkg["identity"]["type"] not in ["plugin", "external"]:
            print("Error : this package type is not recognized")
            exit()
开发者ID:zaraki673,项目名称:Docker-Domogik,代码行数:17,代码来源:packagedata.py

示例14: __init__

    def __init__(self):
        '''
        Initialize database and xPL connection
        '''
        XplPlugin.__init__(self, 'dbmgr')
        MQRep.__init__(self, zmq.Context(), 'dbmgr')
        self.log.debug("Init database_manager instance")

        # Check for database connexion
        self._db = DbHelper()
        nb_test = 0
        db_ok = False
        while not db_ok and nb_test < DATABASE_CONNECTION_NUM_TRY:
            nb_test += 1
            try:
                self._db.list_user_accounts()
                db_ok = True
            except:
                msg = "The database is not responding. Check your configuration of if the database is up. Test %s/%s" % (nb_test, DATABASE_CONNECTION_NUM_TRY)
                print(msg)
                self.log.error(msg)
                msg = "Waiting for %s seconds" % DATABASE_CONNECTION_WAIT
                print(msg)
                self.log.info(msg)
                time.sleep(DATABASE_CONNECTION_WAIT)

        if nb_test >= DATABASE_CONNECTION_NUM_TRY:
            msg = "Exiting dbmgr!"
            print(msg)
            self.log.error(msg)
            self.force_leave()
            return

        msg = "Connected to the database"
        print(msg)
        self.log.info(msg)
        try:
            self._engine = self._db.get_engine()
        except:
            self.log.error("Error while starting database engine : %s" % traceback.format_exc())
            self.force_leave()
            return

        Listener(self._request_config_cb, self.myxpl, {'schema': 'domogik.config', 'xpltype': 'xpl-cmnd'})
        self.enable_hbeat()
        IOLoop.instance().start() 
开发者ID:capof,项目名称:domogik,代码行数:46,代码来源:dbmgr.py

示例15: __init__

    def __init__(self):
        '''
        Initialize database and xPL connection
        '''
        Plugin.__init__(self, 'dbmgr', log_prefix='core_')
        # Already done in Plugin
        #MQRep.__init__(self, zmq.Context(), 'dbmgr')
        self.log.debug(u"Init database_manager instance")

        # Check for database connexion
        self._db = DbHelper()
        with self._db.session_scope():
            # TODO : move in a function and use it (also used in dbmgr)
            nb_test = 0
            db_ok = False
            while not db_ok and nb_test < DATABASE_CONNECTION_NUM_TRY:
                nb_test += 1
                try:
                    self._db.list_user_accounts()
                    db_ok = True
                except:
                    msg = "The database is not responding. Check your configuration of if the database is up. Test {0}/{1}. The error while trying to connect to the database is : {2}".format(nb_test, DATABASE_CONNECTION_NUM_TRY, traceback.format_exc())
                    self.log.error(msg)
                    msg = "Waiting for {0} seconds".format(DATABASE_CONNECTION_WAIT)
                    self.log.info(msg)
                    time.sleep(DATABASE_CONNECTION_WAIT)

            if nb_test >= DATABASE_CONNECTION_NUM_TRY:
                msg = "Exiting dbmgr!"
                self.log.error(msg)
                self.force_leave()
                return

            msg = "Connected to the database"
            self.log.info(msg)
            try:
                self._engine = self._db.get_engine()
            except:
                self.log.error(u"Error while starting database engine : {0}".format(traceback.format_exc()))
                self.force_leave()
                return
        self.ready()
开发者ID:domogik,项目名称:domogik,代码行数:42,代码来源:dbmgr.py


注:本文中的domogik.common.database.DbHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。