
import glob
import os
import sys

# sys.path.append("/home/lyq/CARLA_simulator/CARLA_098/PythonAPI/carla")
# sys.path.append("/home/lyq/CARLA_simulator/CARLA_098/PythonAPI/carla/agents")
# carla_path = '/home/lyq/CARLA_simulator/CARLA_098/PythonAPI'

sys.path.append("/home/lyq/CARLA_simulator/CARLA_096/PythonAPI/carla")
sys.path.append("/home/lyq/CARLA_simulator/CARLA_096/PythonAPI/carla/agents")
carla_path = '/home/lyq/CARLA_simulator/CARLA_096/PythonAPI'

try:
    sys.path.append(glob.glob(carla_path + '/carla/dist/carla-*%d.%d-%s.egg' % (
        sys.version_info.major,
        sys.version_info.minor,
        'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass

import carla


def set_weather(world, weather='ClearNoon'):
    """
    Set weather for the world
    Common weather in carla:
        ClearNoon, CloudyNoon, WetNoon, WetCloudyNoon,
        SoftRainNoon, MidRainyNoon, HardRainNoon, ClearSunset,
        CloudySunset, WetSunset, WetCloudySunset, SoftRainSunset,
        MidRainSunset, HardRainSunset.
    """
    weather_dict = {
        'ClearNoon': carla.WeatherParameters.ClearNoon,
        'CloudyNoon': carla.WeatherParameters.CloudyNoon,
        'WetNoon': carla.WeatherParameters.WetNoon,
        'WetCloudyNoon': carla.WeatherParameters.WetCloudyNoon,
        'SoftRainNoon': carla.WeatherParameters.SoftRainNoon,
        'MidRainyNoon': carla.WeatherParameters.MidRainyNoon,
        'HardRainNoon': carla.WeatherParameters.HardRainNoon,
        'ClearSunset': carla.WeatherParameters.ClearSunset,
        'CloudySunset': carla.WeatherParameters.CloudySunset,
        'WetSunset': carla.WeatherParameters.WetSunset,
        'WetCloudySunset': carla.WeatherParameters.WetCloudySunset,
        'SoftRainSunset': carla.WeatherParameters.SoftRainSunset,
        'MidRainSunset': carla.WeatherParameters.MidRainSunset,
        'HardRainSunset': carla.WeatherParameters.HardRainSunset,
    }
    weather_selection = None
    for key in weather_dict:
        if key == weather:
            weather_selection = weather_dict[key]
    if not weather_selection:
        print('Specified weather not found. ClearNoon is set.')
        weather_selection = carla.WeatherParameters.ClearNoon
    world.set_weather(weather_selection)
    world.tick()

def main():

    # town = 'Town03'

    host = 'localhost'
    port = 2000
    client_timeout = 2.0


    client = carla.Client(host, port)
    client.set_timeout(client_timeout)

    # world = client.get_world()
    town = 'Town02'
    world = client.load_world(town)
    set_weather(world)

    # map = world.get_map()

    start = 0.
    duration = 0.
    camera = 0

    path = 'carla_record.log'


    # client.replay_file(path, start, duration, camera)
    # client.replay_file('carla_record.log', start, duration, camera)


    # client.show_recorder_file_info(path)

    # print(client.show_recorder_file_info(client, "carla_record.log"))

    # self.spectator = self.world.get_spectator()

    print('d')


if __name__ == '__main__':
    main()



