From fc37cb7bb9120f7c1dc949948875061579ffd043 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 14 Apr 2020 12:25:00 -0700 Subject: [PATCH] remove need for old Locale::SubCountry --- FS/FS/state.pm | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---------- debian/control | 2 +- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/FS/FS/state.pm b/FS/FS/state.pm index 671a93b44..fa8cef5e3 100644 --- a/FS/FS/state.pm +++ b/FS/FS/state.pm @@ -76,29 +76,87 @@ sub check { =cut +our %state2fips = ( + 'AL' => '01', + 'AK' => '02', + 'AZ' => '04', + 'AR' => '05', + 'CA' => '06', + 'CO' => '08', + 'CT' => '09', + 'DE' => '10', + 'DC' => '11', + 'FL' => '12', + 'GA' => '13', + 'HI' => '15', + 'ID' => '16', + 'IL' => '17', + 'IN' => '18', + 'IA' => '19', + 'KS' => '20', + 'KY' => '21', + 'LA' => '22', + 'ME' => '23', + 'MD' => '24', + 'MA' => '25', + 'MI' => '26', + 'MN' => '27', + 'MS' => '28', + 'MO' => '29', + 'MT' => '30', + 'NE' => '31', + 'NV' => '32', + 'NH' => '33', + 'NJ' => '34', + 'NM' => '35', + 'NY' => '36', + 'NC' => '37', + 'ND' => '38', + 'OH' => '39', + 'OK' => '40', + 'OR' => '41', + 'PA' => '42', + 'RI' => '44', + 'SC' => '45', + 'SD' => '46', + 'TN' => '47', + 'TX' => '48', + 'UT' => '49', + 'VT' => '50', + 'VA' => '51', + 'WA' => '53', + 'WV' => '54', + 'WI' => '55', + 'WY' => '56', + + 'AS' => '60', #American Samoa + 'GU' => '66', #Guam + 'MP' => '69', #Northern Mariana Islands + 'PR' => '72', #Puerto Rico + 'VI' => '78', #Virgin Islands +); + sub _upgrade_data { - warn "Updating state and country codes...\n"; + # we only need U.S. state codes at this point (for FCC 477 reporting) + warn "Updating state FIPS codes...\n"; my %existing; - foreach my $state (qsearch('state')) { + foreach my $state ( qsearch('state', {'country'=>'US'}) ) { $existing{$state->country} ||= {}; $existing{$state->country}{$state->state} = $state; } - my $world = Locale::SubCountry::World->new; - foreach my $country_code ($world->all_codes) { + foreach my $country_code ('US') { my $country = Locale::SubCountry->new($country_code); next unless $country->has_sub_countries; $existing{$country} ||= {}; foreach my $state_code ($country->all_codes) { - my $fips = $country->FIPS10_4_code($state_code); - # we really only need U.S. state codes at this point, so if there's - # no FIPS code, ignore it. - next if !$fips or $fips eq 'unknown' or $fips =~ /\W/; + my $fips = $state2fips{$state_code} || next; my $this_state = $existing{$country_code}{$state_code}; if ($this_state) { if ($this_state->fips ne $fips) { # this should never happen... - $this_state->set(fips => $fips); - my $error = $this_state->replace; - die "error updating $country_code/$state_code:\n$error\n" if $error; + die "guru meditation #414: State FIPS codes shouldn't change"; + #$this_state->set(fips => $fips); + #my $error = $this_state->replace; + #die "error updating $country_code/$state_code:\n$error\n" if $error; } delete $existing{$country_code}{$state_code}; } else { @@ -113,9 +171,10 @@ sub _upgrade_data { } # clean up states that no longer exist (does this ever happen?) foreach my $state (values %{ $existing{$country_code} }) { - my $error = $state->delete; - die "error removing expired state ".$state->country.'/'.$state->state. - "\n$error\n" if $error; + die "guru meditation #415: State that no longer exists?"; + #my $error = $state->delete; + #die "error removing expired state ".$state->country.'/'.$state->state. + # "\n$error\n" if $error; } } # foreach $country_code ''; diff --git a/debian/control b/debian/control index d751c77e9..c80b3d7fc 100644 --- a/debian/control +++ b/debian/control @@ -44,7 +44,7 @@ Depends: aspell-en,gnupg,ghostscript,gsfonts,gzip, libipc-run-perl,libipc-run3-perl,libipc-sharelite-perl,libjavascript-rpc-perl, libjson-perl,liblingua-en-inflect-perl,liblingua-en-nameparse-perl, liblocale-gettext-perl,liblocale-maketext-fuzzy-perl, - liblocale-maketext-lexicon-perl,liblocale-subcountry-perl (<< 2), + liblocale-maketext-lexicon-perl,liblocale-subcountry-perl, liblog-dispatch-perl, libmailtools-perl (>=2.12), libmime-tools-perl (>= 5.504), libmodule-versions-report-perl, -- 2.11.0