diff --git a/txclib/config.py b/txclib/config.py index bda8b9d5..2c0e8c14 100644 --- a/txclib/config.py +++ b/txclib/config.py @@ -5,6 +5,8 @@ import six +from txclib.exceptions import MalformedConfigFile + class OrderedRawConfigParser(configparser.RawConfigParser): """ @@ -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: diff --git a/txclib/project.py b/txclib/project.py index 00dc234a..02e39160 100644 --- a/txclib/project.py +++ b/txclib/project.py @@ -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() @@ -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) @@ -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() @@ -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) @@ -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) @@ -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)