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


Python Configuration.save方法代码示例

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


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

示例1: save_preferences

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import save [as 别名]
 def save_preferences(self):
     tbuffer = self.entry3.get_buffer()
     inicio = tbuffer.get_start_iter()
     fin = tbuffer.get_end_iter()
     image_link = tbuffer.get_text(inicio, fin, True)
     reduce_size = self.checkbutton21.get_active()
     max_size = self.toInt(self.entry4.get_text())
     reduce_colors = self.checkbutton22.get_active()
     tbi = self.entry_slideshow.get_value()
     configuration = Configuration()
     configuration.set('max_size', max_size)
     configuration.set('reduce_size', reduce_size)
     configuration.set('reduce_colors', reduce_colors)
     configuration.set('image_link', image_link)
     configuration.set('first_time', False)
     configuration.set('time_between_images', tbi)
     configuration.save()
开发者ID:atareao,项目名称:Picapy,代码行数:19,代码来源:preferences.py

示例2: Pay4BytesCore

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import save [as 别名]
class Pay4BytesCore(Service):
    IReactorTimeProvider = reactor
    updateInterval = 1
    menuItems = (
                    ('Quit', lambda widget: reactor.stop()),
                )
    def __init__(self):
        self.statusIcon = StatusIcon(self.menuItems)
        self.configuration = Configuration()
        self.connectionRegistry = None
        self.timer = LoopingCall(self.updateStatistics)
        self.timer.clock = self.IReactorTimeProvider

    def startService(self):
        Service.startService(self)
        self.configuration.load()
        self.connectionRegistry = \
            ConnectionRegistry( self.createConfiguredDeviceMap())
        self.timer.start(self.updateInterval).addErrback(log.err)
        self.statusIcon.show()

    def stopService(self):
        self.statusIcon.hide()
        # HACK: the timer should always be running and there's no need for this
        #        check; however, during development the service might be
        #        uncleanly with the timer not running, and then we'd rather
        #        avoid 'trying to stop a timer which isn't running' exception
        if self.timer.running:
            self.timer.stop()
        self.connectionRegistry.updateConfiguration()
        self.configuration.save()
        Service.stopService(self)

    def updateStatistics(self):
        statisticsMap = readNetworkDevicesStatisticsMap()
        self.connectionRegistry.updateConnections(statisticsMap)
        self.statusIcon.updateTooltip(self.connectionRegistry)

    def createConfiguredDeviceMap(self):
        result = {}
        for configuredDevice in self.configuration:
            pattern = re.compile(configuredDevice.get(DEVICE_NAME_PATTERN))
            result[pattern] = configuredDevice
        return result
开发者ID:yaniv-aknin,项目名称:pay4bytes,代码行数:46,代码来源:core.py

示例3: main

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import save [as 别名]
def main():

    """
    Let's setup logging.
    Note: The 'logging.json->loggers' configuration corresponds to each item returned by 'logging.getLogger'
    we'll just setup root to handle everything but we could target specific modules if we wanted to by simply
    defining a logger targeting a specific module name.
    """
    try:
        # attempt to load from the config file
        logger_config = Configuration('logging.json')
        logging.config.dictConfig(logger_config.get())

        logging.info("\n\n+ ================================ +\n+ Logging initialised. \n+ ================================ +\n")
    except Exception as e:
        print("Error with logging:", type(e), e)
        quit()

    config = Configuration('motion.json')

    force_capture = config.get('force_capture')
    force_capture_time = config.get('force_capture_time')

    url = config.get('home_url')
    username = config.get('username')
    token = config.get('token')

    device_id = None
    api = ApiClient(username, token, url)
    try:
        id_config = Configuration('id.json', catch_errors=False)
        device_id = id_config.get('id')
        if not device_id or not api.confirm_device_id(device_id):
            logging.error("Device ID not registered.")
            raise Exception("Device ID not registered.")
    except Exception as e:
        logging.debug(type(e), e)
        device_name = config.get('device_name')
        logging.info("Provisioning new device: %s." % device_name)
        device_id = api.register_device(device_name)
        id_config.set('id', device_id)
        id_config.save()
        logging.info("Registered new device: %s" % device_id)

    pool_lock = threading.Lock()
    pool = []

    m = None

    logging.info("Queuing upload processors.")

    # TODO: Upload processors consume memory, actively monitor memory and set an upper limit of how many processors can be running...
    # TODO: What if the server goes down? Network storage?
    for i in range(config.get('upload_processor_count', 15)):
        logging.debug("Adding upload processor %i." % i)
        pool.append(UploadProcessor(pool_lock, pool))

    logging.info("Starting motion detection loop.")

    fallback_dir = os.path.join(config.get('fallback_dir', '/home/pi/default_fallback_dir'), device_id)
    fallback_space_to_reserve = config.get('fallback_space_to_reserve', 16)

    try:
        m = Motion()
        running = True

        time_now = time.time()

        while running:
            # If motion was detected, or we've manually scheduled an image to be uploaded.
            if m.detect_motion() or m.get_capture_queue_length() > 0:
                with pool_lock:
                    if pool:
                        processor = pool.pop()
                    else:
                        processor = None
                if processor:
                    logging.debug("Acquired an upload processor.")

                    # load the processor with an image and required backend auth details.
                    processor.stream = m.pop_capture_stream_queue()
                    processor.username = username
                    processor.token = token
                    processor.url = url
                    processor.device_id = device_id
                    processor.fallback_dir = fallback_dir

                    # tell the processor to start working.
                    processor.event.set()
                else:
                    logging.info("Upload processor pool exhausted. Waiting for more uploaders...")

            # Do we want to capture images every N seconds?
            if (force_capture):
                # If timeout, let's capture an image to be processed.
                if ((time.time() - time_now) > force_capture_time):
                    # Reset the clock
                    time_now = time.time()
                    logging.info("Timeout reached. Capturing an image.")
                    m.capture_to_stream_queue()
#.........这里部分代码省略.........
开发者ID:razodactyl,项目名称:seclient,代码行数:103,代码来源:motion.py


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