def fetch_sessions(job_config, data_bucket, data_dir, course, fetch_holdout_session_only = False, fetch_all_sessions = False):
    """
    Fetch course sessions in data_bucket/data_dir. By default, fetches only training sessions (not holdout session).
    :param job_config: MorfJobConfig object.
    :param data_bucket: name of bucket containing data; s3 should have read/copy access to this bucket.
    :param data_dir: path to directory in data_bucket that contains course-level directories of raw data.
    :param course: string; name of course (should match course-level directory name in s3 directory tree).
    :param fetch_holdout_session_only: logical; return only holdout (final) session.
    :param fetch_all_sessions: logical; return all sessions (training and holdout).
    :return: list of session numbers as strings.
    """
    assert (not (fetch_holdout_session_only & fetch_all_sessions)), "choose one - fetch holdout sessions or fetch all sessions"
    s3 = job_config.initialize_s3()
    if not data_dir.endswith("/"):
        data_dir = data_dir + "/"
    course_bucket_objects = s3.list_objects(Bucket=data_bucket, Prefix="".join([data_dir, course, "/"]), Delimiter="/")
    sessions = [item.get("Prefix").split("/")[2] for item in course_bucket_objects.get("CommonPrefixes")]
    sessions = sorted(sessions, key = lambda x: x[-3:]) # handles session numbers like "2012-001" by keeping leading digits before "-" but only sorts on last 3 digits
    if fetch_all_sessions: # return complete list of sessions
        result = sessions
    else:
        holdout_session = sessions.pop(-1)
        if fetch_holdout_session_only == True:
            result = [holdout_session] # return only holdout session, but as a list, so type is consistent
        else:
            result = sessions # return list of sessions without holdout session
    return tuple(result)