diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-02-13 13:51:50 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-02-13 13:51:59 +0300 |
commit | 7a513da9d8c2b409bc0655c232b1b58c24e66164 (patch) | |
tree | 28359b8734f76cfc4228cfa9332594e19600b7c4 /blender_id | |
parent | fa7f7ca3ba34ae832666d45f7ce37af5a4dc3946 (diff) |
Show which Blender ID instance is communicated with in the addon prefs
This is only shown if it was overridden by setting the
BLENDER_ID_ENDPOINT environment variable. It makes Cloud development a
bit easier when it's explicit to which Blender ID (local dev or real
one) we're talking.
Diffstat (limited to 'blender_id')
-rw-r--r-- | blender_id/CHANGELOG.md | 2 | ||||
-rw-r--r-- | blender_id/__init__.py | 24 | ||||
-rw-r--r-- | blender_id/communication.py | 5 |
3 files changed, 20 insertions, 11 deletions
diff --git a/blender_id/CHANGELOG.md b/blender_id/CHANGELOG.md index efda8c80..ee36a7fe 100644 --- a/blender_id/CHANGELOG.md +++ b/blender_id/CHANGELOG.md @@ -6,6 +6,8 @@ - API change: `blender_id.get_subclient_user_id()` now returns `''` instead of `None` when the user is not logged in. - Log which Blender ID instance is communicated with. +- Show which Blender ID instance is communicated with in the addon preferences, + if it was overridden by setting the BLENDER_ID_ENDPOINT environment variable. # Version 1.5 (released 2018-07-03) diff --git a/blender_id/__init__.py b/blender_id/__init__.py index 51e91989..1110dadc 100644 --- a/blender_id/__init__.py +++ b/blender_id/__init__.py @@ -239,16 +239,20 @@ class BlenderIdPreferences(AddonPreferences): else: exp_str = 'within seconds' + endpoint = communication.blender_id_endpoint() + if endpoint == communication.BLENDER_ID_ENDPOINT: + msg = 'You are logged in as %s.' % active_profile.username + else: + msg = 'You are logged in as %s at %s.' % (active_profile.username, endpoint) + + col = layout.column(align=True) + col.label(text=msg, icon='WORLD_DATA') if time_left.days < 14: - layout.label(text='You are logged in as %s.' % active_profile.username, - icon='WORLD_DATA') - layout.label(text='Your token will expire %s. Please log out and log in again ' - 'to refresh it.' % exp_str, icon='PREVIEW_RANGE') + col.label(text='Your token will expire %s. Please log out and log in again ' + 'to refresh it.' % exp_str, icon='PREVIEW_RANGE') else: - layout.label( - text='You are logged in as %s. Your authentication token expires %s.' - % (active_profile.username, exp_str), - icon='WORLD_DATA') + col.label(text='Your authentication token expires %s.' % exp_str, + icon='BLANK1') row = layout.row().split(factor=0.8) row.operator('blender_id.logout') @@ -263,7 +267,7 @@ class BlenderIdPreferences(AddonPreferences): class BlenderIdMixin: @staticmethod def addon_prefs(context): - preferences = context.preferences.addons[__name__].preferences + preferences = context.user_preferences.addons[__name__].preferences preferences.reset_messages() return preferences @@ -352,7 +356,7 @@ def register(): bpy.utils.register_class(BlenderIdPreferences) bpy.utils.register_class(BlenderIdValidate) - preferences = bpy.context.preferences.addons[__name__].preferences + preferences = bpy.context.user_preferences.addons[__name__].preferences preferences.reset_messages() diff --git a/blender_id/communication.py b/blender_id/communication.py index 9960c338..65fdf4cf 100644 --- a/blender_id/communication.py +++ b/blender_id/communication.py @@ -24,6 +24,9 @@ import typing log = logging.getLogger(__name__) +# Can be overridden by setting the environment variable BLENDER_ID_ENDPOINT. +BLENDER_ID_ENDPOINT = 'https://www.blender.org/id/' + class BlenderIdCommError(RuntimeError): """Raised when there was an error communicating with Blender ID""" @@ -59,7 +62,7 @@ def blender_id_endpoint(endpoint_path=None): if base_url: log.warning('Using overridden Blender ID url %s', base_url) else: - base_url = 'https://www.blender.org/id/' + base_url = BLENDER_ID_ENDPOINT log.info('Using standard Blender ID url %s', base_url) # urljoin() is None-safe for the 2nd parameter. |