Exemplo n.º 1
0
# station search criteria
parser.add_option('-v', action='store_true', dest='verbose', default=False)
parser.add_option('-y', action='store_true', dest='test_file', default=False)
parser.add_option('-z', action='store_true', dest='debug', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

debug = options.debug
verbose = options.verbose
test_file = options.test_file

# grape variety and chill model
if not args[0].isdigit():
    varieties = (getGrapeVariety(args[0]), )
    date_indx = 1
else:
    varieties = []
    for name in fromConfig('crops.grape.varieties.build'):
        varieties.append(getGrapeVariety(name))
    date_indx = 0

# get the date
date_args = args[date_indx:]
num_date_args = len(date_args)

if num_date_args == 1:  # target year is only argument
    start_date, end_date = targetDateSpan(int(date_args[0]))
elif num_date_args >= 3:  # start date specified
    year = int(date_args[0])
parser.add_option('-a', action='store_true', dest='animate', default=False)
parser.add_option('-d', action='store', type='int', dest='delay', default=30)
parser.add_option('-v', action='store_true', dest='verbose', default=False)
parser.add_option('-z', action='store_true', dest='test_file', default=False)

options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

animate = options.animate
delay = options.delay
test_file = options.test_file
verbose = options.verbose

# apple variety config
variety = getGrapeVariety(args[0])

factory = GrapeGridFactory()

# get the date
date_args = len(args[1:])
if date_args == 1:
    target_year = int(args[1])
    start_date = datetime(target_year, 1, 1)
    end_date = datetime(target_year, 5, 15)
elif date_args >= 3:
    year = int(args[1])
    month = int(args[2])
    day = int(args[3])
    start_date = datetime(year, month, day)
    if date_args == 3: end_date = None
options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

delay = options.delay
debug = options.debug
test_path = options.test_path

animate_cmd_path = fromConfig('animate_cmd_path')
_cmd_tmpl_ = '%s -delay %d %%s -loop 0 %%s' % (animate_cmd_path, delay)

# target year
target_year = int(args[0])

# grape variety
variety = getGrapeVariety(args[1])

# type of map to animate
map_key = args[2]

map_filepath = mapFilename('date', variety, map_key)

anim_map_key = nameToFilepath(map_key)
png_path = '*%s' % map_filepath[map_filepath.find(anim_map_key):]

anim_filepath = animationFilepath(target_year, variety, map_key)

working_dir = \
mapWorkingDir(target_year, variety, *map_key.split(','))
os.chdir(working_dir)