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


Python DBCache.gethostname方法代码示例

本文整理汇总了Python中MythTV.database.DBCache.gethostname方法的典型用法代码示例。如果您正苦于以下问题:Python DBCache.gethostname方法的具体用法?Python DBCache.gethostname怎么用?Python DBCache.gethostname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MythTV.database.DBCache的用法示例。


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

示例1: getLogs

# 需要导入模块: from MythTV.database import DBCache [as 别名]
# 或者: from MythTV.database.DBCache import gethostname [as 别名]
    def getLogs(cls, appname, count, hostname=None, db=None):
        db = DBCache(db)
        if hostname is None:
            hostname = db.gethostname()

        with db as cursor:
            cursor.execute("""SELECT DISTINCT pid
                                FROM logging
                               WHERE application=?
                                 AND host=?
                               ORDER BY id DESC;""", (appname, hostname))
            try:
                instances = zip(*cursor.fetchall())[0]
            except IndexError:
                print "No logs found on system profile."
                sys.exit(1)

        if count == -1:
            count = len(instances)
        else:
            count = min(count, len(instances))
        for pid in instances[0:count]:
            yield list(cls._fromQuery("""WHERE application=?
                                           AND host=?
                                           AND pid=?
                                         ORDER BY id;""",
                                    (appname, hostname, pid)))
开发者ID:andrewjw,项目名称:mythtv-scripts,代码行数:29,代码来源:pastelog.py

示例2: getAppNames

# 需要导入模块: from MythTV.database import DBCache [as 别名]
# 或者: from MythTV.database.DBCache import gethostname [as 别名]
    def getAppNames(cls, hostname=None, db=None):
        app = namedtuple('Application', ['name', 'count'])

        db = DBCache(db)
        if hostname is None:
            hostname = db.gethostname()

        with db as cursor:
            cursor.execute("""SELECT application, count(1)
                                FROM (SELECT DISTINCT application, pid
                                        FROM logging
                                       WHERE host=?) AS `pids`
                               GROUP BY application;""", (hostname,))
            for row in cursor:
                yield app(*row)
开发者ID:andrewjw,项目名称:mythtv-scripts,代码行数:17,代码来源:pastelog.py

示例3: BECache

# 需要导入模块: from MythTV.database import DBCache [as 别名]
# 或者: from MythTV.database.DBCache import gethostname [as 别名]

#.........这里部分代码省略.........
        if backend is None:
            # no backend given, use master
            self.host = self.db.settings.NULL.MasterServerIP
            self.hostname = self.db._gethostfromaddr(self.host)

        else:
            backend = backend.strip('[]')
            query = "SELECT hostname FROM settings WHERE value=? AND data=?"
            if self._reip.match(backend):
                # given backend is IP address
                self.host = backend
                self.hostname = self.db._gethostfromaddr(
                                            backend, 'BackendServerIP')
            elif check_ipv6(backend):
                # given backend is IPv6 address
                self.host = backend
                self.hostname = self.db._gethostfromaddr(
                                            backend, 'BackendServerIP6')
            else:
                # given backend is hostname, pull address from database
                self.hostname = backend
                self.host = self.db._getpreferredaddr(backend)

        # lookup port from database
        self.port = int(self.db.settings[self.hostname].BackendServerPort)
        if not self.port:
            raise MythDBError(MythError.DB_SETTING, 'BackendServerPort',
                                            self.port)

        self._ident = '%s:%d' % (self.host, self.port)
        if self._ident in self._shared:
            # existing connection found
            self._conn = self._shared[self._ident]
            if self.sendcommands:
                if self._conn.command is None:
                    self._conn.command = self._newcmdconn()
                elif self.blockshutdown:
                    # upref block of shutdown
                    # issue command to backend if needed
                    self._conn.blockshutdown += 1
                    if self._conn.blockshutdown == 1:
                        self._conn.command.blockShutdown()
            if self.receiveevents:
                if self._conn.event is None:
                    self._conn.event = self._neweventconn()
        else:
            # no existing connection, create new
            self._conn = self._ConnHolder()

            if self.sendcommands:
                self._conn.command = self._newcmdconn()
                if self.blockshutdown:
                    self._conn.blockshutdown = 1
            if self.receiveevents:
                self._conn.event = self._neweventconn()

            self._shared[self._ident] = self._conn

        self._events = self._listhandlers()
        for func in self._events:
            self.registerevent(func)

    def __del__(self):
        # downref block of shutdown
        # issue command to backend if needed
        #print 'destructing BECache'
        if self.blockshutdown:
            self._conn.blockshutdown -= 1
            if not self._conn.blockshutdown:
                self._conn.command.unblockShutdown()

    def _newcmdconn(self):
        return BEConnection(self.host, self.port, self.db.gethostname(),
                            self.blockshutdown)

    def _neweventconn(self):
        return BEEventConnection(self.host, self.port, self.db.gethostname())

    def backendCommand(self, data):
        """
        obj.backendCommand(data) -> response string

        Sends a formatted command via a socket to the mythbackend.
        """
        if self._conn.command is None:
            return ""
        return self._conn.command.backendCommand(data)

    def _listhandlers(self):
        return []

    def registerevent(self, func, regex=None):
        if self._conn.event is None:
            return
        if regex is None:
            regex = func()
        self._conn.event.registerevent(regex, func)

    def clearevents(self):
        self._events = []
开发者ID:Beirdo,项目名称:mythtv-stabilize,代码行数:104,代码来源:mythproto.py


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