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