fix args processing
This commit is contained in:
parent
9515fbff4a
commit
144a80c180
@ -4,6 +4,8 @@
|
||||
import logging
|
||||
import stat
|
||||
import os
|
||||
from os.path import exists
|
||||
|
||||
import ee
|
||||
import sys
|
||||
import argparse
|
||||
@ -14,6 +16,16 @@ from country_iso2ify import get_resolver
|
||||
|
||||
resolver = get_resolver()
|
||||
|
||||
def list_subunits_and_exit(country_name):
|
||||
iso_code = resolver.resolve(country_name)
|
||||
countries = country_subunits_by_iso_code(iso_code)
|
||||
logging.debug("Country is [{}] iso code is [{}]".format(country_name,iso_code))
|
||||
item = None
|
||||
if countries:
|
||||
for item in countries:
|
||||
print("Subunit of [{}]: [{}]".format(country_name,item.subunit))
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def get_mainland_bbox(country_name, region_name):
|
||||
# Returns the main continental/primary bounding box
|
||||
@ -65,7 +77,7 @@ program_name = 'get_ee_from_region.py'
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog=program_name,
|
||||
description='get a url from google ee api based on supplied region',
|
||||
description='get a url from google ee api based on supplied region, optionally list subregions of a country',
|
||||
epilog='Good luck')
|
||||
|
||||
parser.add_argument(
|
||||
@ -81,8 +93,8 @@ parser.add_argument(
|
||||
"-L",
|
||||
"--list-subunits",
|
||||
dest='list_subunits',
|
||||
action='store_true',
|
||||
default=False,
|
||||
action='count',
|
||||
default=0,
|
||||
required=False,
|
||||
help="list country subunits and exit")
|
||||
|
||||
@ -90,6 +102,7 @@ parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
dest='verbose',
|
||||
default=True,
|
||||
required=False,
|
||||
action='store_true',
|
||||
help="verbose mode, log output goes to stderr")
|
||||
@ -99,7 +112,7 @@ parser.add_argument(
|
||||
"--country",
|
||||
dest='country',
|
||||
metavar='country',
|
||||
default='US',
|
||||
default='United States',
|
||||
action='store',
|
||||
help="country to get topo image for")
|
||||
|
||||
@ -134,6 +147,12 @@ if args.logging or args.verbose:
|
||||
if args.verbose:
|
||||
logging.debug('logging to stderr requested')
|
||||
|
||||
logging.debug('list_subunits is [{}]'.format(args.list_subunits))
|
||||
|
||||
if args.list_subunits > 0:
|
||||
list_subunits_and_exit(args.country)
|
||||
|
||||
|
||||
t = Timerlog("atomic test").start()
|
||||
logging.debug(t.end().report())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user