本文整理汇总了Python中configuration.Configuration.set方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.set方法的具体用法?Python Configuration.set怎么用?Python Configuration.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_preferences
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import set [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()
示例2: main
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import set [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()
#.........这里部分代码省略.........