def do_update(config, config_dir):
    """
    CLI action "update new configuration".
    """
    if not os.path.exists(config_dir):
        print "Configuration '{}' does not exist.".format(config)
        exit(1)

    config_file = os.path.join(config_dir, 'config')
    with open(config_file, 'r') as f:
        old_config_data = json.load(f)

    old_url = old_config_data['url']
    old_torrent_dir = old_config_data['torrent_dir']
    old_update_interval = old_config_data['update_interval']

    url = raw_input("RSS URL for processing [{}]: "\
        .format(old_url)) or old_url
    torrent_dir = raw_input("Output directory for found .torrent files [{}]: "\
        .format(old_torrent_dir)) or old_torrent_dir
    update_interval = raw_input("Update interval (mins) [{}]: "\
        .format(old_update_interval)) or old_update_interval

    editor = os.environ["EDITOR"]

    config_filter = os.path.join(config_dir, 'filter')
    if confirm("Do you want to edit filters list?", False):
        call([editor, config_filter])
        print "Filter configuration has been saved."

    config_blacklist = os.path.join(config_dir, 'blacklist')
    if confirm("Do you want to edit blacklist?", False):
        call([editor, config_filter])
        print "Blacklist configuration has been saved."

    config_data = json.dumps({
        "url": url,
        "torrent_dir": torrent_dir,
        "update_interval": update_interval
    }, sort_keys=True, indent=4, separators=(',', ': '))
    with open(config_file, 'w') as f:
        f.write(config_data)

    ct = CronTab(user=True)
    for job in ct:
        if re.match('.*ghetto.*\-e\s{}'.format(config), job.command):
            ct.remove(job)

    cmd = "{} {} -e {}".format(sys.executable,
                               os.path.abspath(__file__),
                               config)
    new_job = ct.new(command=cmd)
    new_job.minute.every(update_interval)
    new_job.enable()
    ct.write()
    print "Crontab updated."

    print "Configuration '{}' has been updated.".format(config)