From 5cc0a8c902ae39fa62313e3248a5119cb7ab925f Mon Sep 17 00:00:00 2001 From: cjsieh Date: Mon, 31 Aug 2020 16:19:16 -0500 Subject: [PATCH 1/6] Add files via upload Change from adafruit_sdcard to sdcardio . --- adafruit_pyportal.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 42c2171..5de3d6d 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -63,7 +63,7 @@ import rtc import supervisor from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -import adafruit_sdcard +import sdcardio if hasattr(board, "TOUCH_XL"): @@ -328,10 +328,10 @@ def __init__( if self._debug: print("Init SD Card") - sd_cs = DigitalInOut(board.SD_CS) + sd_cs = board.SD_CS self._sdcard = None try: - self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs) + self._sdcard = sdcardio.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: From 4b4e2073c21aabd5c1b4bf3c01543d9cb0332200 Mon Sep 17 00:00:00 2001 From: cjsieh Date: Wed, 2 Sep 2020 15:36:16 -0500 Subject: [PATCH 2/6] sdcardio added to pylint 2.6.0 version pylinit 2.6.0 changes added --- adafruit_pyportal.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 5de3d6d..bc43c9a 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -660,10 +660,10 @@ def get_local_time(self, location=None): try: aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] - except KeyError: + except KeyError as error: raise KeyError( "\n\nOur time service requires a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long - ) + ) from error location = secrets.get("timezone", location) if location: @@ -686,10 +686,10 @@ def get_local_time(self, location=None): year_day = int(times[2]) week_day = int(times[3]) is_dst = None # no way to know yet - except KeyError: + except KeyError as error: raise KeyError( "Was unable to lookup the time, try setting secrets['timezone'] according to http://worldtimeapi.org/timezones" # pylint: disable=line-too-long - ) + ) from error year, month, mday = [int(x) for x in the_date.split("-")] the_time = the_time.split(".")[0] hours, minutes, seconds = [int(x) for x in the_time.split(":")] @@ -778,10 +778,10 @@ def image_converter_url(image_url, width, height, color_depth=16): try: aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] - except KeyError: + except KeyError as error: raise KeyError( "\n\nOur image converter service require a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long - ) + ) from error return IMAGE_CONVERTER_SERVICE % ( aio_username, @@ -813,10 +813,10 @@ def push_to_io(self, feed_key, data): try: aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] - except KeyError: + except KeyError as error: raise KeyError( "Adafruit IO secrets are kept in secrets.py, please add them there!\n\n" - ) + ) from error wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( self._esp, secrets, None @@ -970,13 +970,11 @@ def fetch(self, refresh_url=None, timeout=10): try: self.wget(image_url, filename, chunk_size=chunk_size) except OSError as error: - print(error) raise OSError( """\n\nNo writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py""" # pylint: disable=line-too-long - ) + ) from error except RuntimeError as error: - print(error) - raise RuntimeError("wget didn't write a complete file") + raise RuntimeError("wget didn't write a complete file") from error if iwidth < iheight: pwidth = int( self._image_resize[1] From 0e4ebe2db8b349130701e59b4b6991b5474db878 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Thu, 3 Sep 2020 20:46:07 -0500 Subject: [PATCH 3/6] add sdcard to autodoc mock --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 36fbb1a..c355d20 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,6 +37,7 @@ "secrets", "adafruit_sdcard", "storage", + "sdcardio", "adafruit_io", "adafruit_cursorcontrol", "adafruit_requests", From f0ccc24684b4771c9ff0d54d5ac74b2d863d8c28 Mon Sep 17 00:00:00 2001 From: cjsieh Date: Tue, 8 Sep 2020 18:45:05 -0500 Subject: [PATCH 4/6] added code to handle python 5.x.x vs 6.x.x since sdcardio is not in 5.x.x sdcardio is not in 5.x.x so code added to test for this Co-authored-by: Scott Shawcroft --- adafruit_pyportal.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index bc43c9a..c175f35 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -63,7 +63,12 @@ import rtc import supervisor from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -import sdcardio +try: + import sdcardio + native_sd = True +except ImportError: + import adafruit_sdcard as sdcardio + native_sd = False if hasattr(board, "TOUCH_XL"): @@ -329,6 +334,8 @@ def __init__( if self._debug: print("Init SD Card") sd_cs = board.SD_CS + if not native_sd: + sd_cs = DigitalInOut(sd_cs) self._sdcard = None try: self._sdcard = sdcardio.SDCard(spi, sd_cs) From 38283b3b860114c1b08bf3ae5fa50c10394acab8 Mon Sep 17 00:00:00 2001 From: cjsieh Date: Wed, 9 Sep 2020 11:09:37 -0500 Subject: [PATCH 5/6] fix pylint and black errors fix pylint and black errors --- adafruit_pyportal.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index c175f35..4f0e7db 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -63,13 +63,13 @@ import rtc import supervisor from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError + try: - import sdcardio - native_sd = True + import sdcardio + NATIVE_SD = True except ImportError: - import adafruit_sdcard as sdcardio - native_sd = False - + import adafruit_sdcard as sdcardio + NATIVE_SD = False if hasattr(board, "TOUCH_XL"): import adafruit_touchscreen @@ -334,8 +334,8 @@ def __init__( if self._debug: print("Init SD Card") sd_cs = board.SD_CS - if not native_sd: - sd_cs = DigitalInOut(sd_cs) + if not NATIVE_SD: + sd_cs = DigitalInOut(sd_cs) self._sdcard = None try: self._sdcard = sdcardio.SDCard(spi, sd_cs) From b8b983166fd665f930ce00140e9407124ba98790 Mon Sep 17 00:00:00 2001 From: cjsieh Date: Wed, 9 Sep 2020 16:01:16 -0500 Subject: [PATCH 6/6] fix for black again black fix again --- adafruit_pyportal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 4f0e7db..5c62b0a 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -66,9 +66,11 @@ try: import sdcardio + NATIVE_SD = True except ImportError: import adafruit_sdcard as sdcardio + NATIVE_SD = False if hasattr(board, "TOUCH_XL"):