text
stringlengths 0
828
|
---|
LOGGER.info('Rendering: {} to {}'.format(template_in, file_out))
|
handle.write(result)
|
shutil.copymode(template_in, file_out)"
|
302,"def copy_file(src, target):
|
""""""
|
copy_file
|
copy source to target
|
""""""
|
LOGGER.info(""Copying {} to {}"".format(src, target))
|
shutil.copyfile(src, target)
|
shutil.copymode(src, target)"
|
303,"def process_templates(input_dir, target_dir, context):
|
""""""
|
_process_templates_
|
Given the input dir containing a set of template,
|
clone the structure under that directory into the target dir
|
using the context to process any mustache templates that
|
are encountered
|
""""""
|
if not target_dir.endswith('/'):
|
target_dir = ""{}/"".format(target_dir)
|
if not os.path.exists(target_dir):
|
LOGGER.info('Creating: {}'.format(target_dir))
|
os.makedirs(target_dir)
|
replicate_directory_tree(input_dir, target_dir)
|
templates = find_templates(input_dir)
|
for templ in templates:
|
output_file = templ.replace(input_dir, target_dir)
|
output_file = output_file[:-len('.mustache')]
|
render_template(templ, output_file, context)"
|
304,"def process_copies(input_dir, target_dir, excludes):
|
""""""
|
_process_copies_
|
Handles files to be copied across, assumes
|
that dir structure has already been replicated
|
""""""
|
copies = find_copies(input_dir, excludes)
|
for c in copies:
|
output_file = c.replace(input_dir, target_dir)
|
copy_file(c, output_file)"
|
305,"def newDevice(deviceJson, lupusec):
|
""""""Create new device object for the given type.""""""
|
type_tag = deviceJson.get('type')
|
if not type_tag:
|
_LOGGER.info('Device has no type')
|
if type_tag in CONST.TYPE_OPENING:
|
return LupusecBinarySensor(deviceJson, lupusec)
|
elif type_tag in CONST.TYPE_SENSOR:
|
return LupusecBinarySensor(deviceJson, lupusec)
|
elif type_tag in CONST.TYPE_SWITCH:
|
return LupusecSwitch(deviceJson, lupusec)
|
else:
|
_LOGGER.info('Device is not known')
|
return None"
|
306,"def get_devices(self, refresh=False, generic_type=None):
|
""""""Get all devices from Lupusec.""""""
|
_LOGGER.info(""Updating all devices..."")
|
if refresh or self._devices is None:
|
if self._devices is None:
|
self._devices = {}
|
responseObject = self.get_sensors()
|
if (responseObject and
|
not isinstance(responseObject, (tuple, list))):
|
responseObject = responseObject
|
for deviceJson in responseObject:
|
# Attempt to reuse an existing device
|
device = self._devices.get(deviceJson['name'])
|
# No existing device, create a new one
|
if device:
|
device.update(deviceJson)
|
else:
|
device = newDevice(deviceJson, self)
|
if not device:
|
_LOGGER.info('Device is unknown')
|
continue
|
self._devices[device.device_id] = device
|
# We will be treating the Lupusec panel itself as an armable device.
|
panelJson = self.get_panel()
|
_LOGGER.debug(""Get the panel in get_devices: %s"", panelJson)
|
self._panel.update(panelJson)
|
alarmDevice = self._devices.get('0')
|
if alarmDevice:
|
alarmDevice.update(panelJson)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.