<s> import yaml <EOL> from astropy . coordinates import SkyCoord <EOL> from . . utils . config import load_config <EOL> from . . utils import error <EOL> from . core import Scheduler <EOL> from . target import Target <EOL> class Scheduler ( Scheduler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , targets_file = None , location = None ) : <EOL> self . config = load_config ( ) <EOL> super ( ) . __init__ ( targets_file = targets_file , location = location ) <EOL> self . _is_initialized = False <EOL> def initialize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . read_target_list ( ) <EOL> self . _is_initialized = True <EOL> def get_target ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _is_initialized : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . read_target_list ( ) <EOL> try : <EOL> target = self . list_of_targets . pop ( ) <EOL> except Exception as e : <EOL> raise error . NoTarget ( e ) <EOL> return target <EOL> def read_target_list ( self ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( '<STR_LIT>' . format ( self . targets_file ) ) <EOL> with open ( self . targets_file , '<STR_LIT:r>' ) as yaml_string : <EOL> yaml_list = yaml . load ( yaml_string ) <EOL> self . logger . debug ( "<STR_LIT>" . format ( yaml_list ) ) <EOL> targets = [ ] <EOL> for target_dict in yaml_list : <EOL> target_name = target_dict . get ( '<STR_LIT:name>' ) <EOL> self . logger . debug ( "<STR_LIT>" . format ( target_name ) ) <EOL> try : <EOL> if '<STR_LIT>' not in target_dict : <EOL> t = SkyCoord . from_name ( target_name ) <EOL> target_dict [ '<STR_LIT>' ] = t . to_string ( style = '<STR_LIT>' ) <EOL> target_dict [ '<STR_LIT>' ] = t . frame . name <EOL> target = Target ( target_dict ) <EOL> except Exception as e : <EOL> self . logger . warning ( "<STR_LIT>" . format ( e ) ) <EOL> else : <EOL> targets . append ( target ) <EOL> self . list_of_targets = targets <EOL> return targets </s>
