Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from ejoerns/topic/develop
Browse files Browse the repository at this point in the history
Some enhancements and cleanups for example application
  • Loading branch information
Enrico Jorns authored Nov 1, 2017
2 parents 10a8656 + 673d8b4 commit 67b52aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
24 changes: 12 additions & 12 deletions bin/rauc-hawkbit-client
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ from rauc_hawkbit.rauc_dbus_ddi_client import RaucDBUSDDIClient


def result_callback(result):
print("result_callback: {}\n".format(result))
print("Result: {}".format('SUCCESSFUL' if result == 0 else 'FAILED' ))

def main():
def step_callback(percentage, message):
print("Progress: {:>3}% - {}".format(percentage, message))

async def main():
# config parsing
config = ConfigParser()
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -75,17 +78,14 @@ def main():
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')

# create event loop, open aiohttp client session and start polling
gbulb.install()
loop = asyncio.get_event_loop()
with aiohttp.ClientSession(loop=loop) as session:
async with aiohttp.ClientSession() as session:
client = RaucDBUSDDIClient(session, HOST, SSL, TENANT_ID, TARGET_NAME,
AUTH_TOKEN, ATTRIBUTES, BUNDLE_DL_LOCATION,
result_callback)
loop.run_until_complete(loop.create_task(
client.start_polling()))

loop.run_forever()
result_callback, step_callback)
await client.start_polling()

if __name__ == '__main__':
main()
# create event loop, open aiohttp client session and start polling
gbulb.install()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
2 changes: 1 addition & 1 deletion rauc_hawkbit/ddi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def get_resource(self, api_path, query_params={}, **kwargs):
**kwargs))

self.logger.debug('GET {}'.format(url))
with aiohttp.Timeout(self.timeout, loop=self.session.loop):
with aiohttp.Timeout(self.timeout):
async with self.session.get(url, headers=get_headers,
params=query_params) as resp:
await self.check_http_status(resp)
Expand Down
9 changes: 8 additions & 1 deletion rauc_hawkbit/rauc_dbus_ddi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RaucDBUSDDIClient(AsyncDBUSClient):
interface.
"""
def __init__(self, session, host, ssl, tenant_id, target_name, auth_token,
attributes, bundle_dl_location, result_callback, lock_keeper=None):
attributes, bundle_dl_location, result_callback, step_callback=None, lock_keeper=None):
super(RaucDBUSDDIClient, self).__init__()

self.attributes = attributes
Expand All @@ -41,6 +41,7 @@ def __init__(self, session, host, ssl, tenant_id, target_name, auth_token,
self.bundle_dl_location = bundle_dl_location
self.lock_keeper = lock_keeper
self.result_callback = result_callback
self.step_callback = step_callback

# DBUS proxy
self.rauc = self.new_proxy('de.pengutronix.rauc.Installer', '/')
Expand Down Expand Up @@ -96,6 +97,9 @@ async def progress_callback(self, connection, sender_name,
self.logger.info('Update progress: {}% {}'.format(percentage,
description))

if self.step_callback:
self.step_callback(percentage, description)

# send feedback to HawkBit
status_execution = DeploymentStatusExecution.proceeding
status_result = DeploymentStatusResult.none
Expand Down Expand Up @@ -239,6 +243,9 @@ async def download_artifact(self, action_id, url, md5sum,
except AttributeError:
static_api_url = True

if self.step_callback:
self.step_callback(0, "Downloading bundle...")

# try several times
for dl_try in range(tries):
if not static_api_url:
Expand Down

0 comments on commit 67b52aa

Please sign in to comment.