Skip to content

Commit

Permalink
Resolves donnemartin#149: Add option to disable avatar (donnemartin#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
kBite authored and donnemartin committed May 18, 2019
1 parent 75e4abe commit d7c57ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitsomeconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[github]
user_login = None
enable_avatar = True
verify_ssl = True
clr_primary = None
clr_secondary = green
Expand Down
13 changes: 13 additions & 0 deletions gitsome/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Config(object):
:type verify_ssl: bool
:param verify_ssl: Determines whether to verify SSL certs.
:type enable_avatar: bool
:param enable_avatar: Determines whether to request avatar image.
"""

CONFIG = '.gitsomeconfig'
Expand Down Expand Up @@ -133,6 +136,7 @@ class Config(object):
CONFIG_URL_SECTION = 'url'
CONFIG_URL_LIST = 'url_list'
CONFIG_AVATAR = '.gitsomeconfigavatar.png'
CONFIG_ENABLE_AVATAR = 'enable_avatar'

def __init__(self):
self.api = None
Expand All @@ -143,6 +147,7 @@ def __init__(self):
self.enterprise_url = None
self.verify_ssl = True
self.urls = []
self.enable_avatar = True
self._init_colors()
self.load_configs([
self.load_config_colors,
Expand Down Expand Up @@ -205,6 +210,10 @@ def authenticate_cached_credentials(self, config, parser,
parser=parser,
cfg_label=self.CONFIG_VERIFY_SSL,
boolean_config=True)
self.enable_avatar = self.load_config(
parser=parser,
cfg_label=self.CONFIG_ENABLE_AVATAR,
boolean_config=True)
self.user_feed = self.load_config(
parser=parser,
cfg_label=self.CONFIG_USER_FEED)
Expand Down Expand Up @@ -629,6 +638,10 @@ def save_config(self):
parser.set(self.CONFIG_SECTION,
self.CONFIG_USER_FEED,
self.user_feed)
if self.enable_avatar is not None:
parser.set(self.CONFIG_SECTION,
self.CONFIG_ENABLE_AVATAR,
self.enable_avatar)
if self.enterprise_url is not None:
parser.set(self.CONFIG_SECTION,
self.CONFIG_ENTERPRISE_URL,
Expand Down
22 changes: 12 additions & 10 deletions gitsome/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ def avatar(self, url, text_avatar):
"""
if platform.system() == 'Windows':
text_avatar = True
avatar = self.config.get_github_config_path(
self.config.CONFIG_AVATAR)
try:
urllib.request.urlretrieve(url, avatar)
except urllib.error.URLError:
pass
avatar_enabled = self.config.enable_avatar
avatar_text = ''
if os.path.exists(avatar):
avatar_text = self.img2txt(avatar, ansi=(not text_avatar))
avatar_text += '\n'
os.remove(avatar)
if avatar_enabled:
avatar = self.config.get_github_config_path(
self.config.CONFIG_AVATAR)
try:
urllib.request.urlretrieve(url, avatar)
except urllib.error.URLError:
pass
if os.path.exists(avatar):
avatar_text = self.img2txt(avatar, ansi=(not text_avatar))
avatar_text += '\n'
os.remove(avatar)
return avatar_text

def avatar_setup(self, url, text_avatar):
Expand Down

0 comments on commit d7c57ab

Please sign in to comment.