1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Implement Dync populate dynamic, flesh out testing for all but dyn

This commit is contained in:
Ross McFarland
2018-12-10 15:30:15 -08:00
parent a169d50fcf
commit 60911917b4
5 changed files with 275 additions and 61 deletions

View File

@@ -2,11 +2,13 @@
#
#
from logging import getLogger
from .geo_data import geo_data
class GeoCodes(object):
__COUNTRIES = None
log = getLogger('GeoCodes')
@classmethod
def validate(cls, code, prefix):
@@ -50,3 +52,20 @@ class GeoCodes(object):
'country_code': country_code,
'province_code': province_code,
}
@classmethod
def country_to_code(cls, country):
for continent, countries in geo_data.items():
if country in countries:
return '{}-{}'.format(continent, country)
cls.log.warn('country_to_code: unrecognized country "%s"', country)
return
@classmethod
def province_to_code(cls, province):
# We get to cheat on this one since we only support provinces in NA-US
if province not in geo_data['NA']['US']['provinces']:
cls.log.warn('country_to_code: unrecognized province "%s"',
province)
return
return 'NA-US-{}'.format(province)