text
stringlengths 0
828
|
---|
4809,"def version(self): |
""""""Get the QS Mobile version."""""" |
return self.get_json(URL_VERSION.format(self._url), astext=True)" |
4810,"def listen(self, callback=None): |
""""""Start the &listen long poll and return immediately."""""" |
self._running = True |
self.loop.create_task(self._async_listen(callback))" |
4811,"async def _async_listen(self, callback=None): |
""""""Listen loop."""""" |
while True: |
if not self._running: |
return |
try: |
packet = await self.get_json( |
URL_LISTEN.format(self._url), timeout=30, exceptions=True) |
except asyncio.TimeoutError: |
continue |
except aiohttp.client_exceptions.ClientError as exc: |
_LOGGER.warning(""ClientError: %s"", exc) |
self._sleep_task = self.loop.create_task(asyncio.sleep(30)) |
try: |
await self._sleep_task |
except asyncio.CancelledError: |
pass |
self._sleep_task = None |
continue |
if isinstance(packet, dict) and QS_CMD in packet: |
_LOGGER.debug(""callback( %s )"", packet) |
try: |
callback(packet) |
except Exception as err: # pylint: disable=broad-except |
_LOGGER.error(""Exception in callback\nType: %s: %s"", |
type(err), err) |
else: |
_LOGGER.debug(""unknown packet? %s"", packet)" |
4812,"def set_qs_value(self, qsid, val, success_cb): |
""""""Push state to QSUSB, retry with backoff."""""" |
self.loop.create_task(self.async_set_qs_value(qsid, val, success_cb))" |
4813,"async def async_set_qs_value(self, qsid, val, success_cb=None): |
""""""Push state to QSUSB, retry with backoff."""""" |
set_url = URL_SET.format(self._url, qsid, val) |
for _repeat in range(1, 6): |
set_result = await self.get_json(set_url, 2) |
if set_result and set_result.get('data', 'NO REPLY') != 'NO REPLY': |
if success_cb: |
success_cb() |
return True |
await asyncio.sleep(0.01 * _repeat) |
_LOGGER.error(""Unable to set %s"", set_url) |
return False" |
4814,"async def update_from_devices(self): |
""""""Retrieve a list of &devices and values."""""" |
res = await self.get_json(URL_DEVICES.format(self._url)) |
if res: |
self.devices.update_devices(res) |
return True |
return False" |
4815,"def multi_ops(data_stream, *funcs): |
"""""" fork a generator with multiple operations/functions |
data_stream - an iterable data structure (ie: list/generator/tuple) |
funcs - every function that will be applied to the data_stream """""" |
assert all(callable(func) for func in funcs), 'multi_ops can only apply functions to the first argument' |
assert len(funcs), 'multi_ops needs at least one function to apply to data_stream' |
for i in data_stream: |
if len(funcs) > 1: |
yield tuple(func(i) for func in funcs) |
elif len(funcs) == 1: |
yield funcs[0](i)" |
4816,"def attowiki_distro_path(): |
""""""return the absolute complete path where attowiki is located |
.. todo:: use pkg_resources ? |
"""""" |
attowiki_path = os.path.abspath(__file__) |
if attowiki_path[-1] != '/': |
attowiki_path = attowiki_path[:attowiki_path.rfind('/')] |
else: |
attowiki_path = attowiki_path[:attowiki_path[:-1].rfind('/')] |
return attowiki_path" |
4817,"def build_command(self): |
""""""Build out the crontab command"""""" |
return cron_utils.cronify(""crontab -l | {{ cat; echo \""{} {} {} {} {} CJOBID='{}' MAILTO='' {}\""; }} | crontab - > /dev/null"".format(self._minute, self._hour, self._day_of_month, self._month_of_year, self._day_of_week, self._jobid, self._command))" |
4818,"def read_environment_file(envfile=None): |
"""""" |
Read a .env file into os.environ. |
If not given a path to a envfile path, does filthy magic stack backtracking |
to find manage.py and then find the envfile. |
"""""" |
if envfile is None: |
frame = sys._getframe() |
envfile = os.path.join(os.path.dirname(frame.f_back.f_code.co_filename), '.env') |
if not os.path.exists(envfile): |
warnings.warn(""not reading %s - it doesn't exist."" % envfile) |
return |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.