Skip to content

Commit

Permalink
Merge pull request #190 from transifex/update_wording
Browse files Browse the repository at this point in the history
Update some logger messages to be more descriptive
  • Loading branch information
SofiaMargariti authored Nov 2, 2017
2 parents cde8a82 + ba3642e commit 291a668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion txclib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import six

from txclib.exceptions import MalformedConfigFile


class OrderedRawConfigParser(configparser.RawConfigParser):
"""
Expand Down Expand Up @@ -67,7 +69,9 @@ def fromkeys(cls, keys, value=None):
def __setitem__(self, key, val):
k = self._flip.get(val, _NOTFOUND)
if not (k is _NOTFOUND or k == key):
raise KeyError('(key,val) would erase mapping for value %r' % val)
raise MalformedConfigFile("Your lang map configuration is not correct. "
"Duplicate entry detected with value '%s'. "
"Keys and values should be unique." % val)

v = self.get(key, _NOTFOUND)
if v is not _NOTFOUND:
Expand Down
28 changes: 20 additions & 8 deletions txclib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ def get_resource_lang_mapping(self, resource):
lang_map.update({k: v})
except configparser.NoOptionError:
pass
except (ValueError, KeyError):
raise Exception("Your lang map configuration is not correct.")
except ValueError:
raise MalformedConfigFile(
"Your lang map configuration is not correct.")

if self.config.has_section(resource):
res_lang_map = Flipdict()
Expand All @@ -311,8 +312,9 @@ def get_resource_lang_mapping(self, resource):
res_lang_map.update({k: v})
except configparser.NoOptionError:
pass
except (ValueError, KeyError):
raise Exception("Your lang map configuration is not correct.")
except ValueError:
raise MalformedConfigFile(
"Your lang map configuration is not correct.")

# merge the lang maps and return result
lang_map.update(res_lang_map)
Expand Down Expand Up @@ -688,7 +690,7 @@ def push(self, source=False, translations=False, force=False,
logger.debug("Using host %s" % host)
self._set_url_info(host=host, project=project_slug,
resource=resource_slug)
logger.info("Pushing translations for resource %s:" % resource)
logger.info("Pushing resource %s:" % resource)

stats = self._get_stats_for_resource()

Expand All @@ -711,7 +713,7 @@ def push(self, source=False, translations=False, force=False,
continue
# Push source file
try:
logger.warning("Pushing source file (%s)" % sfile)
logger.info("Pushing source file (%s)" % sfile)
if not self._resource_exists(stats):
logger.info("Resource does not exist. Creating...")
fileinfo = "%s;%s" % (resource_slug, slang)
Expand All @@ -727,7 +729,12 @@ def push(self, source=False, translations=False, force=False,
params=params,
)
except Exception as e:
if isinstance(e, SSLError) or not skip:
if isinstance(e, SSLError):
raise
elif not skip:
logger.error("Could not upload source file. "
"You can use --skip to ignore this "
"error and continue the execution.")
raise
else:
logger.error(e)
Expand Down Expand Up @@ -805,7 +812,12 @@ def push(self, source=False, translations=False, force=False,
logger.error("Resource hasn't been created. "
"Try pushing source file.")
except Exception as e:
if isinstance(e, SSLError) or not skip:
if isinstance(e, SSLError):
raise
elif not skip:
logger.error("Could not push translations. "
"You can use --skip to ignore this "
"error and continue the execution.")
raise
else:
logger.error(e)
Expand Down

0 comments on commit 291a668

Please sign in to comment.