From edadee5a78ff5d74ec43a139ba6c1d83698ed3e7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 27 Oct 2016 11:28:03 +0100 Subject: [PATCH] ECC-275: errors.pl not creating ecCodes header files --- src/errors.pl | 39 ++++++++++++++++++++------------------- src/extrules.am | 1 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/errors.pl b/src/errors.pl index b0376dd2f..2de046954 100755 --- a/src/errors.pl +++ b/src/errors.pl @@ -13,7 +13,7 @@ use strict; use warnings; my $internal = get_internal_errors(); my $public = get_public_errors(); -# print "DUMP,\t", Data::Dumper->Dump([\$public], [" "]); +#print "DUMP,\t", Data::Dumper->Dump([\$public], [" "]); write_public($public); #write_internal($internal); @@ -24,8 +24,8 @@ write_python_exceptions($public); sub write_python_exceptions { my $errdict = shift; - my %errmap = (); # code -> mangled name - open(H,">py_exceptions.py") or die "py_exceptions.py: $!"; + my %errmap = (); # code -> class name + open(H,">errors.py.new") or die "errors.py.new: $!"; my $header = <<'END_HEADER'; """ @@ -62,15 +62,15 @@ END_HEADER my $code = $_; my $name = $errdict->{$_}{name}; my $text = $errdict->{$_}{text}; - # Convert name to Exception class - $name =~ s/GRIB_//; + # Convert name e.g. GRIB_WRONG_ARRAY_SIZE -> WrongArraySizeError + $name =~ s/GRIB_//; # Remove GRIB_ my $name_lc = $name; - $name_lc =~ s/_/ /g; - $name_lc = lc $name_lc; - $name_lc =~ s/(\w+)/\u$1/g; - $name_lc =~ s/ //g; + $name_lc =~ s/_/ /g; # Remove underscores + $name_lc = lc $name_lc; # lowercase + $name_lc =~ s/(\w+)/\u$1/g; # First letter uppercase + $name_lc =~ s/ //g; # Remove spaces $name = $name_lc; - if ($name !~ /Error$/) { + if ($name !~ /Error$/) { # Append Error (unless already there) $name = $name . "Error"; } $name = 'FunctionNotImplementedError' if ($name eq 'NotImplementedError'); @@ -82,22 +82,23 @@ END_HEADER $name = 'InvalidBitsPerValueError' if ($name eq 'InvalidBpvError'); $name = 'KeyValueNotFoundError' if ($name eq 'NotFoundError'); - print H "class ${name}(GribInternalError):\n"; ## $name,$_; - print H " \"\"\"${text}.\"\"\"\n"; + if ($code != 0) { # Ignore SUCCESS + print H "class ${name}(GribInternalError):\n"; ## $name,$_; + print H " \"\"\"${text}.\"\"\"\n"; - $errmap{$code} = $name; # store for next loop + $errmap{$code} = $name; # store for next loop + } } + print H "\nERROR_MAP = {\n"; my $i = 0; - my $size = keys %{$errdict}; - foreach (sort {$a<=>$b} keys %{$errdict}){ - my $name = $errdict->{$_}{name}; - my $code = $_; + my $size = keys %errmap; + for my $code (sort { $a <=> $b } keys %errmap) { next if ($code == 0); $i++; my $ktext = sprintf("%-3d", $code); - print H " $ktext : $name"; - print H ",\n" if ($i < $size-1); + print H " $ktext : $errmap{$code}"; + print H ",\n" if ($i < $size); } print H "\n}\n\n"; diff --git a/src/extrules.am b/src/extrules.am index f64e5ca4a..f0db5e1d0 100644 --- a/src/extrules.am +++ b/src/extrules.am @@ -8,6 +8,7 @@ grib_errors.c : grib_errors.txt errors.pl cmp ../fortran/grib_api_constants.h grib_api_constants.h.new || (mv grib_api_constants.h.new ../fortran/grib_api_constants.h) cmp ../fortran/eccodes_constants.h eccodes_constants.h.new || (mv eccodes_constants.h.new ../fortran/eccodes_constants.h) cmp ../python/grib_errors.h grib_errors.h.new || (mv grib_errors.h.new ../python/grib_errors.h) + cmp ../python/gribapi/errors.py errors.py.new || (mv errors.py.new ../python/gribapi/errors.py) proto:;-chmod +w grib_api_prototypes.h; mkptypes -A $(libeccodes_la_prototypes) $(libeccodes_extra_prototypes) > temp && mv temp grib_api_prototypes.h;rm -f temp