From 7ee456ced98ce231b1012cce7690938fb9489fcc Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Thu, 18 Apr 2019 12:35:39 +0200 Subject: [PATCH 1/6] Bumps and pins setuptools Refs upstream: https://github.com/kivy/python-for-android/pull/1795 --- buildozer.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildozer.spec b/buildozer.spec index 7412771..2718b3b 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -74,7 +74,7 @@ requirements = requests==2.20.0, requests-cache==0.4.13, rlp==1.0.3, - setuptools, + setuptools==40.9.0, toolz==0.9.0, urllib3==1.24.1, web3==4.8.1 From f81164875c04893fda9ef4caa8a7c51a1e8bf756 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 22 Apr 2019 20:15:21 +0200 Subject: [PATCH 2/6] Supports F-Droid auto updates, refs #132 Uses the HTTP update method, refs: https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode --- docs/Release.md | 43 +++++-------------------------------------- src/CHANGELOG.md | 6 ++++++ src/version.py | 6 ++++++ 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/docs/Release.md b/docs/Release.md index bf0bbc9..6ce6ea5 100644 --- a/docs/Release.md +++ b/docs/Release.md @@ -7,57 +7,24 @@ This is documenting the release process. Make sure the CHANGELOG.md is up to date and follows the http://keepachangelog.com guidelines. Start the release with git flow: -``` +```sh git flow release start vYYYYMMDD ``` Now update the [CHANGELOG.md](/src/CHANGELOG.md) `[Unreleased]` section to match the new release version. -Also update the `__version__` string of the [version.py](/src/version.py) file. Then commit and finish release. +Also update the `__version__` and `__version_code__` values from the [version.py](/src/version.py) file. Optionally already update the direct download link from the [README.md](/README.md). -``` +Then commit and finish release. +```sh git commit -a -m "vYYYYMMDD" git flow release finish ``` Push everything, make sure tags are also pushed: -``` +```sh git push git push origin master:master git push --tags ``` -## Android - -Useful links: - - * https://developer.android.com/studio/publish/app-signing.html - * https://github.com/kivy/kivy/wiki/Creating-a-Release-APK - -### Fields - - * my-project - The directory for your project - * my-new-key - The name of the key you generate - * my-alias - A short alias name for the key - -### Commands -Prepare the environment variables: -``` -export P4A_RELEASE_KEYSTORE=~/.android/.keystore -export P4A_RELEASE_KEYSTORE_PASSWD=android -export P4A_RELEASE_KEYALIAS_PASSWD=android -export P4A_RELEASE_KEYALIAS= -``` -Generate a keystore if not yet generated: -``` -keytool -genkey -v -keystore ~/.android/.keystore -alias -keyalg RSA -keysize 2048 -validity 10000 -``` -Run buildozer: -``` -buildozer android release -``` - -### Play Store - - - ## GitHub Got to GitHub [Release/Tags](https://github.com/AndreMiras/EtherollApp/tags), click "Add release notes" for the tag just created. diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 1032771..e18d70a 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,10 +1,16 @@ # Change Log +## [Unreleased] + + - Support F-Droid auto updates, refs #132 + + ## [v20190418] - Pull minimum bet from contract, refs #129 - Fix permission issue on settings, refs #131 + - Available on the F-Droid market, refs #36 ## [v20190217] diff --git a/src/version.py b/src/version.py index b57a620..b948757 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1,7 @@ __version__ = '2019.0418' +# The `__version_code__` is used for the F-Droid auto update and should match +# the `versionCode` from the `build.gradle` file located in: +# `.buildozer/android/platform/build/dists/etheroll/` +# The auto update method used is the `HTTP`, see: +# https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode +__version_code__ = 202318 From d594613b6a4a57fbb4b85d486c34dede69d7616e Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Thu, 25 Apr 2019 12:10:33 +0200 Subject: [PATCH 3/6] Updates release process and download links, refs #132 - tag changed to match with F-Droid and `__version__` - adds F-Droid download button - changes APK download image to match size refs #132 --- README.md | 7 ++++++- docs/Release.md | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 56a933f..cf66881 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ [![Build Status](https://secure.travis-ci.org/AndreMiras/EtherollApp.png?branch=develop)](http://travis-ci.org/AndreMiras/EtherollApp) - + + + + + + Provably fair dice game running on the [Ethereum blockchain](https://etheroll.com/#/smart-contract). Built with Python, [Kivy](https://github.com/kivy/kivy) and love. diff --git a/docs/Release.md b/docs/Release.md index 6ce6ea5..f4bd696 100644 --- a/docs/Release.md +++ b/docs/Release.md @@ -8,14 +8,14 @@ This is documenting the release process. Make sure the CHANGELOG.md is up to date and follows the http://keepachangelog.com guidelines. Start the release with git flow: ```sh -git flow release start vYYYYMMDD +git flow release start vYYYY.MMDD ``` Now update the [CHANGELOG.md](/src/CHANGELOG.md) `[Unreleased]` section to match the new release version. Also update the `__version__` and `__version_code__` values from the [version.py](/src/version.py) file. Optionally already update the direct download link from the [README.md](/README.md). Then commit and finish release. ```sh -git commit -a -m "vYYYYMMDD" +git commit -a -m "vYYYY.MMDD" git flow release finish ``` Push everything, make sure tags are also pushed: From 9cf3716f534b151dd80acd4ae8b9915b6755c629 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Thu, 25 Apr 2019 18:08:22 +0200 Subject: [PATCH 4/6] Fail silently on store permission error Don't prompt an error dialog the first time the user open the application without runtime read/write disk permission. --- src/etheroll/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/etheroll/settings.py b/src/etheroll/settings.py index 7c7836b..3b1aeaa 100644 --- a/src/etheroll/settings.py +++ b/src/etheroll/settings.py @@ -25,8 +25,8 @@ def get_store(): controller.check_request_write_permission() try: store = Store.get_store() - except PermissionError as exception: - controller.on_permission_error(exception) + except PermissionError: + # fails silently, setting will simply not be stored on disk store = {} return store From bea29a173a3e9682cf435e5e21635137a8e18a4d Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Fri, 26 Apr 2019 20:59:09 +0200 Subject: [PATCH 5/6] Create keystore directory if needed, refs #133 Also makes sure we have permissions beforehand. --- src/CHANGELOG.md | 1 + src/ethereum_utils.py | 1 + src/etheroll/controller.py | 11 ++++++++--- src/etheroll/settings.py | 4 +++- src/service/main.py | 13 +++++++++++-- src/tests/test_ethereum_utils.py | 19 ++++++++++++++++++- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index e18d70a..0dafcab 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -4,6 +4,7 @@ ## [Unreleased] - Support F-Droid auto updates, refs #132 + - Keystore directory and permissions, refs #133, #134 ## [v20190418] diff --git a/src/ethereum_utils.py b/src/ethereum_utils.py index 368c030..6fffa6f 100644 --- a/src/ethereum_utils.py +++ b/src/ethereum_utils.py @@ -8,6 +8,7 @@ class AccountUtils: def __init__(self, keystore_dir): self.keystore_dir = keystore_dir self._accounts = None + os.makedirs(keystore_dir, exist_ok=True) def get_account_list(self): """ diff --git a/src/etheroll/controller.py b/src/etheroll/controller.py index e35b325..e51534d 100755 --- a/src/etheroll/controller.py +++ b/src/etheroll/controller.py @@ -89,7 +89,10 @@ def account_utils(self): from etheroll.store import Store if self._account_utils is None: keystore_dir = Store.get_keystore_path() - self._account_utils = AccountUtils(keystore_dir=keystore_dir) + # would try to create the keystore directory if doesn't exist, + # hence we need to make sure we have permissions + if self.check_request_write_permission(): + self._account_utils = AccountUtils(keystore_dir=keystore_dir) return self._account_utils def preload_account_utils(self, dt): @@ -419,12 +422,14 @@ def check_request_write_permission(): Android runtime storage permission check. """ if platform != "android": - return + return True from android.permissions import ( Permission, request_permission, check_permission) permission = Permission.WRITE_EXTERNAL_STORAGE - if not check_permission(permission): + had_permission = check_permission(permission) + if not had_permission: request_permission(permission) + return had_permission @staticmethod def on_permission_error(exception): diff --git a/src/etheroll/settings.py b/src/etheroll/settings.py index 3b1aeaa..79939a9 100644 --- a/src/etheroll/settings.py +++ b/src/etheroll/settings.py @@ -25,7 +25,9 @@ def get_store(): controller.check_request_write_permission() try: store = Store.get_store() - except PermissionError: + except (PermissionError, OSError): + # PermissionError -> e.g. Android runtime permission + # OSError -> e.g. directory doesn't exist # fails silently, setting will simply not be stored on disk store = {} return store diff --git a/src/service/main.py b/src/service/main.py index 2b1ddad..ac994ec 100755 --- a/src/service/main.py +++ b/src/service/main.py @@ -41,9 +41,8 @@ def __init__(self, osc_server_port=None): """ Set `osc_server_port` to enable UI synchronization with service. """ - keystore_dir = self.get_keystore_path() - self.account_utils = AccountUtils(keystore_dir=keystore_dir) self._pyetheroll = None + self._account_utils = None # per address cached merged logs, used to compare with next pulls self.merged_logs = {} self.last_roll_activity = None @@ -65,6 +64,16 @@ def run(self): # service decided to die naturally after no roll activity self.set_auto_restart_service(False) + @property + def account_utils(self): + """ + Gets or creates the AccountUtils object so it loads lazily. + """ + if self._account_utils is None: + keystore_dir = self.get_keystore_path() + self._account_utils = AccountUtils(keystore_dir=keystore_dir) + return self._account_utils + @staticmethod def set_auto_restart_service(restart=True): """ diff --git a/src/tests/test_ethereum_utils.py b/src/tests/test_ethereum_utils.py index 59a006f..146d33c 100644 --- a/src/tests/test_ethereum_utils.py +++ b/src/tests/test_ethereum_utils.py @@ -1,7 +1,7 @@ import os import shutil import unittest -from tempfile import mkdtemp +from tempfile import TemporaryDirectory, mkdtemp from unittest import mock from ethereum_utils import AccountUtils @@ -79,6 +79,23 @@ def test_get_account_list_error(self): self.assertEqual( self.account_utils.get_account_list()[0].address, account.address) + def test_get_account_list_no_dir(self): + """ + The keystore directory should be created if it doesn't exist, refs: + https://github.com/AndreMiras/PyWallet/issues/133 + """ + # nominal case when the directory already exists + with TemporaryDirectory() as keystore_dir: + self.assertTrue(os.path.isdir(keystore_dir)) + account_utils = AccountUtils(keystore_dir) + self.assertEqual(account_utils.get_account_list(), []) + # when the directory doesn't exist it should also be created + self.assertFalse(os.path.isdir(keystore_dir)) + account_utils = AccountUtils(keystore_dir) + self.assertTrue(os.path.isdir(keystore_dir)) + self.assertEqual(account_utils.get_account_list(), []) + shutil.rmtree(keystore_dir, ignore_errors=True) + def test_deleted_account_dir(self): """ The deleted_account_dir() helper method should be working From 7917e96c29617ce00a8903f3b410d8efb5d65ea8 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Fri, 26 Apr 2019 23:15:24 +0200 Subject: [PATCH 6/6] v2019.0426 --- README.md | 2 +- src/CHANGELOG.md | 2 +- src/version.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf66881..65eb0f9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - + diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 0dafcab..d4b4559 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -## [Unreleased] +## [v2019.0426] - Support F-Droid auto updates, refs #132 - Keystore directory and permissions, refs #133, #134 diff --git a/src/version.py b/src/version.py index b948757..91a371d 100644 --- a/src/version.py +++ b/src/version.py @@ -1,7 +1,7 @@ -__version__ = '2019.0418' +__version__ = '2019.0426' # The `__version_code__` is used for the F-Droid auto update and should match # the `versionCode` from the `build.gradle` file located in: # `.buildozer/android/platform/build/dists/etheroll/` # The auto update method used is the `HTTP`, see: # https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode -__version_code__ = 202318 +__version_code__ = 202326