From patchwork Tue Oct 26 14:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schrimpf X-Patchwork-Id: 1546474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=LcId0dnJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::337; helo=mail-wm1-x337.google.com; envelope-from=swupdate+bncbaabbp444cfqmgqent5m62a@googlegroups.com; receiver=) Received: from mail-wm1-x337.google.com (mail-wm1-x337.google.com [IPv6:2a00:1450:4864:20::337]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hdv7n0BG3z9sRR for ; Wed, 27 Oct 2021 01:18:43 +1100 (AEDT) Received: by mail-wm1-x337.google.com with SMTP id b81-20020a1c8054000000b0032c9d428b7fsf5065859wmd.3 for ; Tue, 26 Oct 2021 07:18:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1635257919; cv=pass; d=google.com; s=arc-20160816; b=EuZEGFl21dhp+OEa5kJbzZgtkHaA+VyGHzu1NHvqiFdnJHRDFAb8ugI5Tc6dB5TS7J JF5VEzdpwCxU519IFmmmh+G+j8psk4XmAFIb2gJo7FtgFCKW9cJOg+eawRazj24wmEWu e1vnNdzPXvMHmCYB7qUg+TwP/+2+2jcK/ePXqKh55ZEcBNQS52aOSVx0cRErSAJ1uRtJ Ir8v1WbIbfNmdVL4clgoIrWv0vcHkCHTupR/ZRugJkFPrezoraTsR/gnaUxluGsHfwjY N3y5n85Vs/eKFEEQhNmyQeUKiAos/gupxfoBdlwMI0pIjIocFWIwZlOlimHLUngu/um9 G2mQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=803w5wgvp6w/G5jBKpoEDmsk1fBIdpxAOqTkVqHYoiA=; b=ZV2rwNwFP9jkVrkqq/LmThzpT5whOGaSKQt64Z+mYLl95CKbiR8zErZ+5/vg3iJ+Nh UzWRQu8mKWUJTvWHmuxFJESeYwnUfPyFu4AQhd6/XtDib7YJW/pIqQdOw0QCYmQyQ0cw sr3UstVnap5UETvhBm9B8NcpLU/iPZHsSCT+wuPdAomZ+xRlhH4TQPSI/tP1estzG2MH DxcrEyBr6QNukMBGZg+z5wP82KopckKk8xPi/CSa0GkpoomrbgF4DG/C/atpHWk4gGcr 1jqRDvXTwbtRYqSvPUUQPyKcRAtl5Ox7DSZ4QLfakrGyhgRqRobESs5vatg7BPgr7kWG EYnQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=803w5wgvp6w/G5jBKpoEDmsk1fBIdpxAOqTkVqHYoiA=; b=LcId0dnJCvEnBQBx9n5mo2naX+Ue66JAkAjGNYbjK4VynOfih0EziZ0NsKUWySEDYZ 4aetqGoQcJtRq9/RjeZ8+gP9uXkhjcdkqiHdmpGLVZ2acSaD/3panNKFHYIQ3/Oesk/g pnwis+jp6aKvz4C+Aum3zSYkYdQsBB0e4goirFojZszPAUUAiCXypZjx1YaInnqLMbZX dFl7A0MHtntqFkPMKo59BP+R10dUe5gGq/c2cIqoO3WRbzGjnuP7ZLfIeoRguQLW+aGK xnKnaXyN9tlDXY2Wy/tAv3yQLQlhIxiTxWUTYGeCkjgzHXPriM0cyJWN5F0p7ZwCNFPS /Rwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=803w5wgvp6w/G5jBKpoEDmsk1fBIdpxAOqTkVqHYoiA=; b=U7w64mbqaVjCyyXCS9b4cNP0j3DX/I6jI8GfoIk4InQXvhfosNmQ/3pUBiJod9/pqe l602IdBTVyatqcmGXdsbcHVeCl25siZUC2IzhlLYw9BeWJYWyWa/Pc+eS8rD+km1KEm2 /6YHe1JCmutLu5Xccz8QKq68h5xdb2sQjTbEW3jsyRxOFaUj3NDPW6N03p3a8n1M8+48 ErzEmkPlBMyoSfwrEVl5UKeCeZtiGUTJmyXG6W7Vd444pJZoDlCrkVqSNdPQ45L1hQVA GMZkCkEaeoGn2PrQ3J9v+iTDfUCYPeIBH8ejUZuSPncI2mBP54WNn4huSdgIa9DTpygA EbPw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM5314lOQUFYNd64MTLYlS0XX4rI34+qsQGuYLd1mw2rDBzAVbJqPd ub0IfrDKa84EETsn9tBVvNw= X-Google-Smtp-Source: ABdhPJyiemO0EhB34X282duuuKPAK1I2mxoB+h21hI9/kHrlZnDnWgdk4Vnh5gHNBPQCq1/sHyVd7Q== X-Received: by 2002:a5d:4a82:: with SMTP id o2mr32705232wrq.434.1635257919282; Tue, 26 Oct 2021 07:18:39 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:6b08:: with SMTP id v8ls6030631wrw.3.gmail; Tue, 26 Oct 2021 07:18:38 -0700 (PDT) X-Received: by 2002:a5d:5191:: with SMTP id k17mr22021437wrv.166.1635257918525; Tue, 26 Oct 2021 07:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635257918; cv=none; d=google.com; s=arc-20160816; b=gb34sMQL1NFht2uabOSVrk1mtzlmVCFFgSn0C9AoEljjgB29UPGOPCg03vT4uD2qfO wBZWG7bFKQhDqclxjXI4btVoOSDUNISDUHgcxpLadkEBCrkvMutVohkMtFnpbu2e81vD Pk257hsG9c6jZxHhLLz8ibOyngLPm/52kT6zD9MOLA+NdSn1CPM+KqZ4a3pFOaioQ9n8 t8123R17tumY706vDm94XnKUU1zTnibQFpu0xEk2gjTA0dcfZ97vSFJMOlagB8EHR7RQ oUCeraCnRxj92a6k21Gg4CKZv2s5Kp8/68hTfOykLXiExKIpoDjqxGkBz0l+LogFsC/9 TiJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=6608zIBy3c/TCOdTDG4iINJqROgGc8+S+aFJ74k0M8w=; b=RkWbWclQHPvChKCuyy1pv0XbIzhQPIV9aGs55plfRLjz0bztBOe01w+t+m3F+9qne6 ZACSgMyqcJbQwZOEUvlsMhIdss/+I93iFw71O4KF56OVpQkgrS50AURegttnDEeCVHrm WNyc5fWLa/zLKpKGFyza60eZi+FFgD1W4QKFtIHjt4+DWCLbMTDL+zFlf8ypkH5qIP9i mmHLiGaJpHzn+shQdusFOYuS9eQk8oAafR7rC0eLqlmyVDErtMVIQrSS/5M9q0NtJmJT fVwcgvChxf92/qteHSLTuZ9yeqh3qdp26SkLuNKoKAu/YNKLUDLxTkULck440i4N7gY9 6l8Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Received: from Johanness-MacBook-Pro-BE.local ([195.1.58.114]) by gmr-mx.google.com with ESMTP id i1si877562wrc.2.2021.10.26.07.18.38 for ; Tue, 26 Oct 2021 07:18:38 -0700 (PDT) Received-SPF: neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) client-ip=195.1.58.114; Received: by Johanness-MacBook-Pro-BE.local (Postfix, from userid 501) id C0DC3304F65344; Tue, 26 Oct 2021 16:18:37 +0200 (CEST) From: Johannes Schrimpf To: swupdate@googlegroups.com Cc: Johannes Schrimpf Subject: [swupdate] [PATCH 1/3] Rename swupdate-client.py to swupdate_client.py Date: Tue, 26 Oct 2021 16:14:43 +0200 Message-Id: <20211026141445.85452-1-johannes.schrimpf@blueye.no> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 X-Original-Sender: johannes.schrimpf@blueye.no X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Change file name to swupdate_client.py, so it can be included from other python modules Signed-off-by: Johannes Schrimpf --- examples/client/{swupdate-client.py => swupdate_client.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/client/{swupdate-client.py => swupdate_client.py} (100%) diff --git a/examples/client/swupdate-client.py b/examples/client/swupdate_client.py similarity index 100% rename from examples/client/swupdate-client.py rename to examples/client/swupdate_client.py From patchwork Tue Oct 26 14:14:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schrimpf X-Patchwork-Id: 1546475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=aqMoqTFL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23b; helo=mail-lj1-x23b.google.com; envelope-from=swupdate+bncbaabbre44cfqmgqejummuda@googlegroups.com; receiver=) Received: from mail-lj1-x23b.google.com (mail-lj1-x23b.google.com [IPv6:2a00:1450:4864:20::23b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hdv7r3F24z9sRR for ; Wed, 27 Oct 2021 01:18:48 +1100 (AEDT) Received: by mail-lj1-x23b.google.com with SMTP id p19-20020a2e8053000000b002119ff434a2sf194606ljg.11 for ; Tue, 26 Oct 2021 07:18:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1635257925; cv=pass; d=google.com; s=arc-20160816; b=0v69KcBVwn9K6ksarSBhEcKaqIwlNnejJ+VQIbKeHZOUz8MtKOlBiVs8tHjajreycQ fxmi9PDsFxkHnyxvh2/MpAiigz04s9PuA99xO7eWOmeD5wdmrsDlG1S7+Wws+NMnf4iY vOz276GhOSKtkdU8V+N5EXQXwC3DglNueQy3/PpHtKtokxo7a15ak2/wjHgrT0Ctbm9s LVYQs3C3ILy2xtwqO3lb9TE5JDB3wZxw8Rgx3fMnE2VOenOQSXpTomvni+huMUZ3Y2oO JHGnnXB68j5pqqFAgiM53CBj6tPA+4XUQ6EqugRvnEIYoROtYry/pKpwrQ0I1CmiJZbq MYAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=WwY7pHzVz4xbME1Q0eZYPXt5q7vZgmwMCr/BbaDrSgI=; b=CaaznMEeK7LBiocagjE9ZVsBB5yM9i/yyDbz77sR2c8MvlqPGt5Wn50p/0EP1lj7UU qK+WYR+78dIllNooCYBI1b3jRkFqWYKG91tQmD5z6nYEXfwUCd8AxH0BOElvNpFDk3uf qVvQulByUleJv+jE+YlKyBKOB8q4DRajkqsGbNH0WNCwqWDUqigQzul1Cz1hurrsNF6w PZ+rd2B7IlkUjr6pzh1N40MuarOq+qtYF1TLPoREK7ExNqdQRuGUimECEgzBwg6kxMaj NbyZSJUysQwN6VR1S1m8qNxmqou1L2NnQQcVpaEbbPlINq660Nourazm8L4Gzpx99gqN 9k1A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=WwY7pHzVz4xbME1Q0eZYPXt5q7vZgmwMCr/BbaDrSgI=; b=aqMoqTFLGK4MBshjwKvL6vupBa1QYUmFSZj0Egjvm7W/UbpmNWNC0S6K6bQ/9ud1B7 Niuz167pvxeFMyvhYmGmgJAbxX8Oz1X1XK4Equ4Afr1dvo0M6dVesfzvX518pqEYwlC1 Ce6knVOJ4sUGM+lzzTBYawBO2u2BkTWqQbJVNJhL8EhVx8Udocy2v0nNbio3KZ4B8Mdm Qro8s3rIpOAt0gZYn+b98HBQieyYQZmrnnMkW7cO1Intvi120OlAjr+LRV2rTWwhiQGr HPhMTaFLXLZGfvtFnDKGxXXwrDag4DhuXI6TztEfBRBWh97h9R7RWCNI3xSI5+g6yokh N0rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=WwY7pHzVz4xbME1Q0eZYPXt5q7vZgmwMCr/BbaDrSgI=; b=2rTGfSFb4hojdS3Q41Vql8duarZ3JK4pAQbLtoVR0m3hU7MVKDWsTJL5TFsSX8dcfi GeXE9Nx9n2E8WLX/uc1zvh0Y3AhVxCTiYuRLCTcIu6DNJ5TTJFNMAWtZ51R540NQfwNy OXvcqa50UCfKJBnmZJ6oaXuSlKpxGILygYIPvdvACk369kYyvSRimK+D7+HTmnsdlbsk AoQLjYV9ySXeVBPJOJvaM3ypBiGwkRLmSVWP3n2UjM2WJJj0nTF4Duv3W/F1/RVp422n tPYT/zgMUD90C7YhsVA1ehLkxyQgCwQ6Dw0YPSraH8uq+/Ah8TwmVu6b4UiTfm2h/QQi cTbQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533jLACiSNxf7AziV+x1zS7IAQWHyoJNCG/DgDzJYE+glYEjXhNx +LIGYJmVp3x2Y9rxj61SCx8= X-Google-Smtp-Source: ABdhPJxdj9Ms+6Xnvsf0/ut0oHR9SYUA2uW5C35l2O+r/fRqVQC1ZvQbz4imMCdBDZLQf7pM3hZ3zQ== X-Received: by 2002:a2e:a0d7:: with SMTP id f23mr26980210ljm.422.1635257924897; Tue, 26 Oct 2021 07:18:44 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:3499:: with SMTP id v25ls436394lfr.0.gmail; Tue, 26 Oct 2021 07:18:44 -0700 (PDT) X-Received: by 2002:ac2:4e10:: with SMTP id e16mr24622490lfr.225.1635257924147; Tue, 26 Oct 2021 07:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635257924; cv=none; d=google.com; s=arc-20160816; b=wxDiAODRIdIPr5/oLT2Ft56dEDKJfMiV/Zj1lAvJ2Zlp1wJ8ROfeKxRE0envcOtJ0I kjoXDKdKf9Wfmk89VDTllaQbfwKWNbVEdmAnh22z9kox8Zdrh9F8N+3/9/OnQPzD8GLL eJblcPADhunP2CUZUAWNdm+nv1Xl4CKCZItlMvjtJnb/LrnXfvSAnu9SCP+faT8Q3aYn 1jmErwPPfXWl1NKTRDhp0Av5JL0cmhEK2TDcTM2UwRyRzEfAXLeP9FLm2lSjb+QQ7MxC 5FoRE6y1ulAG4L0k9szXN5m1fGhf6S/D5r0KINQA11UKSV9S2WYST3Zu7LYuVlRzYVqJ YDdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=gGAHLIyaW7689I0+A6Z8E2th3rLqCqLrX93hFNhhMj8=; b=sFpnWLxyP4J6UMVe5wWwUwjgOhjQ3Fngl8kPDh9B5ftbqA2ollF72rW4FXVG2jB2IG nP9bOE9RYo+gkgWl9NHo2IbV3f2xHv5QdMVBanPnmZo8yHTXqGfnHAdu04g6yNkBeWgt Z6MMAOKD2eY73Cz38M+ENmgLxwYq+fmikPTz0sB0/ym2dFfACnI1xR/bDe0ElD/1DIgJ RDb+tPQQujX3ncOZMH822blsZJP1WN5EBwm/bmxvhmvNgh6/3zhHfCaHsONmROY/08kC zIn4z5k0g1CVaRSgmdVneJ8sQyzO7yE2h6/fsQ78WezGUc8yOCEW3LdAShy7P9tW84nz vvuQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Received: from Johanness-MacBook-Pro-BE.local ([195.1.58.114]) by gmr-mx.google.com with ESMTP id z12si1471582lfd.12.2021.10.26.07.18.44 for ; Tue, 26 Oct 2021 07:18:44 -0700 (PDT) Received-SPF: neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) client-ip=195.1.58.114; Received: by Johanness-MacBook-Pro-BE.local (Postfix, from userid 501) id C6B21304F65357; Tue, 26 Oct 2021 16:18:43 +0200 (CEST) From: Johannes Schrimpf To: swupdate@googlegroups.com Cc: Johannes Schrimpf Subject: [swupdate] [PATCH 2/3] Improve example client Date: Tue, 26 Oct 2021 16:14:44 +0200 Message-Id: <20211026141445.85452-2-johannes.schrimpf@blueye.no> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211026141445.85452-1-johannes.schrimpf@blueye.no> References: <20211026141445.85452-1-johannes.schrimpf@blueye.no> MIME-Version: 1.0 X-Original-Sender: johannes.schrimpf@blueye.no X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , - Start websocket client at the beginning of the update, so all messages are shown - Call requests.post in executor to not block the asyncio event loop - Use argparse to handle command line arguments - Handle timeout in both the upload task and the websocket task - Use flake8/black to lint and format code - Add support for logging, so external programs can register their own logger - Handle json parse error in version info message Signed-off-by: Johannes Schrimpf --- examples/client/swupdate_client.py | 158 +++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 45 deletions(-) diff --git a/examples/client/swupdate_client.py b/examples/client/swupdate_client.py index ae31ec9..fc0c1d4 100755 --- a/examples/client/swupdate_client.py +++ b/examples/client/swupdate_client.py @@ -6,68 +6,136 @@ import asyncio import json -import os import requests import websockets +import logging +import string +import argparse import sys class SWUpdater: - "" " Python helper class for SWUpdate " "" - - url_upload = 'http://{}:{}/upload' - url_status = 'ws://{}:{}/ws' - - def __init__ (self, path_image, host_name, port): - self.__image = path_image - self.__host_name = host_name - self.__port = port - - - async def wait_update_finished(self, timeout = 300): - print ("Wait update finished") - async def get_finish_messages (): - async with websockets.connect(self.url_status.format(self.__host_name, self.__port)) as websocket: + """Python helper class for SWUpdate""" + + url_upload = "http://{}:{}/upload" + url_status = "ws://{}:{}/ws" + + def __init__(self, path_image, host_name, port=8080, logger=None): + self._image = path_image + self._host_name = host_name + self._port = port + if logger is not None: + self._logger = logger + else: + logging.basicConfig(stream=sys.stdout, level=logging.INFO) + self._logger = logging.getLogger("swupdate") + + async def wait_update_finished(self): + self._logger.info("Waiting for messages on websocket connection") + try: + async with websockets.connect( + self.url_status.format(self._host_name, self._port) + ) as websocket: while True: - message = await websocket.recv() - data = json.loads(message) - - if data ["type"] != "message": + try: + message = await websocket.recv() + message = "".join( + filter(lambda x: x in set(string.printable), message) + ) + + except Exception as err: + self._logger.warning(err) continue - print (data["text"]) - if data ["text"] == "SWUPDATE successful !": - return + try: + data = json.loads(message) + except json.decoder.JSONDecodeError: + # As of 2021.04, the version info message contains invalid json + self._logger.warning(f"json parse error: {message}") + continue - await asyncio.wait_for(get_finish_messages(), timeout = timeout) + if data["type"] != "message": + continue - def update (self, timeout = 300): - print ("Start uploading image...") - print (self.url_upload.format(self.__host_name, self.__port)) + self._logger.info(data["text"]) + if "SWUPDATE successful" in data["text"]: + return True + if "Installation failed" in data["text"]: + return False + + except Exception as err: + self._logger.error(err) + return False + + def sync_upload(self, swu_file, timeout): + return requests.post( + self.url_upload.format(self._host_name, self._port), + files={"file": swu_file}, + timeout=timeout, + ) + + async def upload(self, timeout): + self._logger.info("Start uploading image...") try: - response = requests.post(self.url_upload.format(self.__host_name, self.__port), files = { 'file':open (self.__image, 'rb') }) + with open(self._image, "rb") as swu_file: + loop = asyncio.get_event_loop() + response = await loop.run_in_executor( + None, self.sync_upload, swu_file, timeout + ) if response.status_code != 200: - raise Exception ("Cannot upload software image: {}". format (response.status_code)) - - print ("Software image uploaded successfully. Wait for installation to be finished...\n") - asyncio.sleep(10) - asyncio.get_event_loop().run_until_complete(self.wait_update_finished(timeout = timeout)) - + self._logger.error( + "Cannot upload software image: {}".format(response.status_code) + ) + return False + + self._logger.info( + "Software image uploaded successfully." + "Wait for installation to be finished..." + ) + return True except ValueError: - print("No connection to host, exit") + self._logger.info("No connection to host, exit") + except FileNotFoundError: + self._logger.info("swu file not found") + except requests.exceptions.ConnectionError as e: + self._logger.info("Connection Error:\n%s" % str(e)) + return False + + async def start_tasks(self, timeout): + ws_task = asyncio.create_task(self.wait_update_finished()) + upload_task = asyncio.create_task(self.upload(timeout)) + + if not await upload_task: + self._logger.info("Cancelling websocket task") + ws_task.cancel() + return False + try: + result = await asyncio.wait_for(ws_task, timeout=timeout) + except asyncio.TimeoutError: + self._logger.info("timeout!") + return False -if __name__ == "__main__": - sys.path.append (os.getcwd ()) + return result - if len (sys.argv) == 3: - port = "8080" - elif len (sys.argv) == 4: - port = sys.argv[3] - else: - print ("Usage: swupdate.py [port]") - exit (1) + def update(self, timeout=300): + return asyncio.run(self.start_tasks(timeout)) - SWUpdater (sys.argv[1], sys.argv[2], port).update () +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("swu_file", help="Path to swu image") + parser.add_argument("host_name", help="Host name") + parser.add_argument("port", help="Port", type=int, default=8080, nargs="?") + parser.add_argument( + "--timeout", + help="Timeout for the whole swupdate process", + type=int, + default=300, + nargs="?", + ) + + args = parser.parse_args() + updater = SWUpdater(args.swu_file, args.host_name, args.port) + updater.update(timeout=args.timeout) From patchwork Tue Oct 26 14:14:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schrimpf X-Patchwork-Id: 1546476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=eTB/ipOq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::33e; helo=mail-wm1-x33e.google.com; envelope-from=swupdate+bncbaabbr444cfqmgqeoqkkjei@googlegroups.com; receiver=) Received: from mail-wm1-x33e.google.com (mail-wm1-x33e.google.com [IPv6:2a00:1450:4864:20::33e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hdv7v1mmZz9sRR for ; Wed, 27 Oct 2021 01:18:51 +1100 (AEDT) Received: by mail-wm1-x33e.google.com with SMTP id k6-20020a7bc306000000b0030d92a6bdc7sf994292wmj.3 for ; Tue, 26 Oct 2021 07:18:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1635257928; cv=pass; d=google.com; s=arc-20160816; b=OC8USl7maB4qtD7u9NaD0yXAG2+W9kQtofKA5Ma4aMVnj+3HYH/DTuYyOHXndrBrj2 vrbM5VwxUwAEkcb08WxuhF7xZ1Ayx9SvOQ6Sr2YQVkaiNFNqfGOhdc6xAlpMVIDQaNj4 tVIVGxhKzF3e8l0qNPlZcfeNmNnDEdnVkF1nLVTp43PO7lGYfJ6FSnAAtJO/piMMmUKk 8ihHqWCRJMnwyxAIK3d7jjfX5UI8B6PQg5N+eg2rhyYvcvrUlQI3vFI9wmHw91Dqhi2w YsQyjlTTwWljewwacDKsXyN3U68s1dYKKtIrdZq/Wo5YvpM22rbt72lPimW1q7h17ozi /RrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=TzHzn40ooAyTEQRPuFm4uznd9n8GFcxIitfaMVEJsP4=; b=gVLgCdLXg6oMC7JKkKygmqf6v0csbIZEVjpW/PoqbaOvzBd5xqVRz3fsL+nhhcrjmo 2qmiLxQjwS/D/Mi+c+AQWarduoKrf2NLHZ/UMkPDcIF2R9Lzw6gl8tz/JYp8cMiQebgk Rf5VfCIwemiKG+n6ZdOIkKMNSDOY3WV1o9S2ah/3HZ2Vdp01lWObxa7A7UPJp9QY84ox hlG7AxiXgUU+bJjr+dkzoiowLaRPMIlL3FY5gFf8maBD1YDrufiLCw7/FmWkf8nHVDnn lI4ltYjZphzvQ4pAJinUusxES98FYBJ/u5GkyuQl8JurzJX+50JAXM12Vv9zCx7E7iP7 zbzw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=TzHzn40ooAyTEQRPuFm4uznd9n8GFcxIitfaMVEJsP4=; b=eTB/ipOq1VR4NvNoz9I3/Zfgm9fOcuBLV831yaKwO72m1hR0ueXkUaB8Z+uc6lHD5I /RMTyeqQ5wLr2kD8l4Gz7ALxvEKuZZW/kW4kZXai8BrK1Ghh06s0aNkltkyV8ugXj1Ca WZ7Ki6QYjCsgYrWSq8C9a/b819ACisDSnv7TkKOxkRHVHLYL9xp7MIpUaDcGy++Hbf/z kSzNYccfUZIA1Hhq3zAJ36UyGQYNgRdXdHI3JPJ5BMs21opZqQQv1f0wZMzBXezVH3Jq cZ8mNR4m9igxny2Z9TiOLRVDzYDAcn1CAs1rMK7HNm+icMf+HmwNnI7vf3dcXQ3yuvjL aMdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=TzHzn40ooAyTEQRPuFm4uznd9n8GFcxIitfaMVEJsP4=; b=1B2eFFZlREdBhBC2NBB0ScS+o0wdVBlV2iIegrY280Oqj79K7jLytIsfefdcaejyXi eJ64Pgu8jmGQvPyeWuDAoQ0CNmEDNT4yUYbd/Pwgz0QTswekWOdMm9ahNmICVFLCwEWA k8nXB62wKsleTu3X3b4YclrcAUcCEKfsdvnR9IEuCJ/zqEyUqx9oNQOOKJ3jKG9TffwL 43PSwadu1LfUwr8VB15BgQJ3XC24R5QLm+gkChSgyO2rUEi1730JcE5FHxaXWDnA7Vze PhEZf+OUP2WlxHiggHwsr31QXy7xdvophJXAxo5UGYqE8UfGcJktWfvtGiLChi4U5osY atCw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531jj791Y+z56fSjasMkowqT+D12CLHHxZKfCFn6r1pr5ajW2HtK epJ/s6E9aha6kv9L7SID40I= X-Google-Smtp-Source: ABdhPJzQ2gMTIoUsULr3t3gCOClusczJ7XH+5JTbBqJ18r8AHTEqOBtpZcyihiE8Z30FWYQOryiRHA== X-Received: by 2002:adf:a402:: with SMTP id d2mr33895442wra.266.1635257927860; Tue, 26 Oct 2021 07:18:47 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:adf:8b92:: with SMTP id o18ls6027895wra.0.gmail; Tue, 26 Oct 2021 07:18:47 -0700 (PDT) X-Received: by 2002:adf:e10a:: with SMTP id t10mr32301972wrz.384.1635257927014; Tue, 26 Oct 2021 07:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635257927; cv=none; d=google.com; s=arc-20160816; b=RhbOsNfE+pMBlcuVv45i1kd4UrQXfIg0DT+dTlDFQOQMPZRA37KFNOL46NGFctlH/K LJMI8+fywjxRuYviV+dgbEz1GOH3qS0UwNnJX+QUO0jVqElfquM1wvOzBUk2CTf0CvtX GQdmYwzef40zsIh0g+DJZ37hB8zxqVLyZkRTnVroELthVhiRND0EJe5BkZweH1UI/uDV 9AtOXFGsnyrNyAUU72bKUziRJRvwEloRsN98NVn3laBCDpJvcUa02qWYjdhCyPTpl6hF D5SUfEu8WgwGu7o3t3IXrs70YBkzr5G1fNor9e9I4lDJkjaQg8Xi1gOvMjWpUbVI+HH+ 5j5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=EfjSFHfr68AJqKl0bZPTJJWOkXbQRrgZ0ajD6fvcRF0=; b=PffrSP44ZnPBvwwrAxoZBYMv2N6fZ3tciXt9Q5tKyDCxHGVfftm5cRVyuFMbkIRAFH tlLLbYHk8tkF305lOLSL7/4yev+BVlNLbhgrtOlzXH2WnodY/hMHiRN5Un6mtZDrX42X N6ogaeE/c7+WydoFRzsRnfrggcx22v+ZHf0bJ4kS21uxor6oV1VOhXrNqfI+DJDvX4LU pGVCgNCRJ90LMPjZxELd8Jn/TTASlJZn1/Z3QUtYZ65k5QEzJNvDqYAgam9CeupYRBoJ OEk9N08pUFdIaneLCbVu3rz0jTtJj9I3CWem/HVmtlRef6Gmp/FThX2m6tGPtalrnGJz +9Hg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Received: from Johanness-MacBook-Pro-BE.local ([195.1.58.114]) by gmr-mx.google.com with ESMTP id h3si170317wml.1.2021.10.26.07.18.46 for ; Tue, 26 Oct 2021 07:18:46 -0700 (PDT) Received-SPF: neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) client-ip=195.1.58.114; Received: by Johanness-MacBook-Pro-BE.local (Postfix, from userid 501) id 7D91A304F65359; Tue, 26 Oct 2021 16:18:46 +0200 (CEST) From: Johannes Schrimpf To: swupdate@googlegroups.com Cc: Johannes Schrimpf Subject: [swupdate] [PATCH 3/3] Add Pipfile and README.md Date: Tue, 26 Oct 2021 16:14:45 +0200 Message-Id: <20211026141445.85452-3-johannes.schrimpf@blueye.no> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211026141445.85452-1-johannes.schrimpf@blueye.no> References: <20211026141445.85452-1-johannes.schrimpf@blueye.no> MIME-Version: 1.0 X-Original-Sender: johannes.schrimpf@blueye.no X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 195.1.58.114 is neither permitted nor denied by best guess record for domain of johannes@johanness-macbook-pro-be.local) smtp.mailfrom=johannes@johanness-macbook-pro-be.local Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Johannes Schrimpf Signed-off-by: Johannes Schrimpf > --- examples/client/Pipfile | 13 +++++++++++ examples/client/README.md | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 examples/client/Pipfile create mode 100644 examples/client/README.md diff --git a/examples/client/Pipfile b/examples/client/Pipfile new file mode 100644 index 0000000..a237601 --- /dev/null +++ b/examples/client/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +websockets = "*" +requests = "*" + +[dev-packages] + +[requires] +python_version = "3.9" diff --git a/examples/client/README.md b/examples/client/README.md new file mode 100644 index 0000000..b6e5d32 --- /dev/null +++ b/examples/client/README.md @@ -0,0 +1,47 @@ +## Install dependencies + +### apt +``` +sudo apt update +sudo apt install python3-websockets python3-requests +``` + +### pip +``` +pip install websockets requests +``` + +### pipenv +``` +pipenv install +``` + +## Usage + +### apt/pip +``` +./swupdate_client.py [port] +``` + +### pipenv +``` +pipenv run ./swupdate_client.py [port] +``` + + +## Development +### Import from another python program +``` +from swupdate_client import SWUpdater + +updater = SWUpdater("path-to-swu", "host-name") +if updater.update(): + print("Update successful!") +else: + print("Update failed!") +``` + +### Formatting +``` +black swupdate_client.py +``` \ No newline at end of file