[elbe-devel] [PATCH v2 15/66] commands add: Fix Pylint
Torben Hohn
torben.hohn at linutronix.de
Wed Jun 10 13:30:51 CEST 2020
On Fri, Jun 05, 2020 at 01:06:39PM -0400, Olivier Dion wrote:
> 27:11: W0703: (broad-except)
> 34:15: W0703: (broad-except)
> 42:15: W0703: (broad-except)
>
> Fix the exception, make the file a little more readable and more
> verbose error messages.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
> ---
> elbepack/commands/add.py | 29 +++++++++++++++++------------
> 1 file changed, 17 insertions(+), 12 deletions(-)
>
> diff --git a/elbepack/commands/add.py b/elbepack/commands/add.py
> index 8f666a5f..d7b23872 100644
> --- a/elbepack/commands/add.py
> +++ b/elbepack/commands/add.py
> @@ -9,7 +9,7 @@ import sys
>
> from optparse import OptionParser
>
> -from elbepack.elbexml import ElbeXML
> +from elbepack.elbexml import ElbeXML, ValidationError
>
> def run_command(argv):
>
> @@ -22,21 +22,26 @@ def run_command(argv):
> oparser.print_help()
> sys.exit(20)
>
> + xmlfile = args[0]
> + pkg_lst = args[1:]
> +
> try:
> - xml = ElbeXML(args[0])
> - except Exception as e:
> - print("Error reading xml file: %s" % str(e))
> + xml = ElbeXML(xmlfile)
> + except ValidationError as E:
> + print("Error while reading xml file %s: %s" % (xmlfile, E))
> sys.exit(20)
>
> - for a in args[1:]:
> + for pkg in pkg_lst:
> try:
> - xml.add_target_package(a)
> - except Exception as e:
> - print("Error adding package %s: %s" % (a, str(e)))
> + xml.add_target_package(pkg)
> + except ValueError as E:
> + print("Error while adding package %s to %s: %s" % (pkg, xmlfile, E))
> sys.exit(20)
>
> try:
> - xml.xml.write(args[0])
> - except BaseException:
> - print("Unable to write new xml file")
> - sys.exit(20)
> + xml.xml.write(xmlfile)
> + sys.exit(0)
> + except PermissionError as E:
> + print("Unable to truncate file %s: %s" % (xmlfile, E))
> +
> + sys.exit(20)
> --
> 2.27.0
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list