(timeline_name, index_name, username, sketch_id=None)
Use existing sketch or create a new sketch.

    Args:
        timeline_name: (str) Name of the Timeline
        index_name: (str) Name of the index
        username: (str) Who should own the timeline
        sketch_id: (str) Optional sketch_id to add timeline to

    Returns:
        (tuple) sketch ID and timeline ID as integers
Use existing sketch or create a new sketch.
Use existing sketch or create a new sketch .
def setup_sketch(timeline_name, index_name, username, sketch_id=None):
    """Use existing sketch or create a new sketch.

    Args:
        timeline_name: (str) Name of the Timeline
        index_name: (str) Name of the index
        username: (str) Who should own the timeline
        sketch_id: (str) Optional sketch_id to add timeline to

    Returns:
        (tuple) sketch ID and timeline ID as integers
    """
    with app.app_context():
        user = User.get_or_create(username=username)
        sketch = None

        if sketch_id:
            try:
                sketch = Sketch.query.get_with_acl(sketch_id, user=user)
                logger.info('Using existing sketch: {} ({})'.format(
                    sketch.name, sketch.id))
            except Forbidden:
                pass

        if not (sketch or sketch_id):
            # Create a new sketch.
            sketch_name = 'Turbinia: {}'.format(timeline_name)
            sketch = Sketch(
                name=sketch_name, description=sketch_name, user=user)
            # Need to commit here to be able to set permissions later.
            db_session.add(sketch)
            db_session.commit()
            sketch.grant_permission(permission='read', user=user)
            sketch.grant_permission(permission='write', user=user)
            sketch.grant_permission(permission='delete', user=user)
            sketch.status.append(sketch.Status(user=None, status='new'))
            db_session.add(sketch)
            db_session.commit()
            logger.info('Created new sketch: {} ({})'.format(
                sketch.name, sketch.id))

        searchindex = SearchIndex.get_or_create(
            name=timeline_name, description='Created by Turbinia.', user=user,
            index_name=index_name)
        searchindex.grant_permission(permission='read', user=user)
        searchindex.grant_permission(permission='write', user=user)
        searchindex.grant_permission(permission='delete', user=user)
        searchindex.set_status('processing')
        db_session.add(searchindex)
        db_session.commit()

        timeline = Timeline(
            name=searchindex.name, description=searchindex.description,
            sketch=sketch, user=user, searchindex=searchindex)

        # If the user doesn't have write access to the sketch then create the
        # timeline but don't attach it to the sketch.
        if not sketch.has_permission(user, 'write'):
            timeline.sketch = None
        else:
            sketch.timelines.append(timeline)

        db_session.add(timeline)
        db_session.commit()
        timeline.set_status('processing')

        return sketch.id, timeline.id
def setup_sketch ( timeline_name , index_name , username , sketch_id = None ) : with app . app_context ( ) : user = User . get_or_create ( username = username ) sketch = None if sketch_id : try : sketch = Sketch . query . get_with_acl ( sketch_id , user = user ) logger . info ( 'Using existing sketch: {} ({})' . format ( sketch . name , sketch . id ) ) except Forbidden : pass if not ( sketch or sketch_id ) : # Create a new sketch. sketch_name = 'Turbinia: {}' . format ( timeline_name ) sketch = Sketch ( name = sketch_name , description = sketch_name , user = user ) # Need to commit here to be able to set permissions later. db_session . add ( sketch ) db_session . commit ( ) sketch . grant_permission ( permission = 'read' , user = user ) sketch . grant_permission ( permission = 'write' , user = user ) sketch . grant_permission ( permission = 'delete' , user = user ) sketch . status . append ( sketch . Status ( user = None , status = 'new' ) ) db_session . add ( sketch ) db_session . commit ( ) logger . info ( 'Created new sketch: {} ({})' . format ( sketch . name , sketch . id ) ) searchindex = SearchIndex . get_or_create ( name = timeline_name , description = 'Created by Turbinia.' , user = user , index_name = index_name ) searchindex . grant_permission ( permission = 'read' , user = user ) searchindex . grant_permission ( permission = 'write' , user = user ) searchindex . grant_permission ( permission = 'delete' , user = user ) searchindex . set_status ( 'processing' ) db_session . add ( searchindex ) db_session . commit ( ) timeline = Timeline ( name = searchindex . name , description = searchindex . description , sketch = sketch , user = user , searchindex = searchindex ) # If the user doesn't have write access to the sketch then create the # timeline but don't attach it to the sketch. if not sketch . has_permission ( user , 'write' ) : timeline . sketch = None else : sketch . timelines . append ( timeline ) db_session . add ( timeline ) db_session . commit ( ) timeline . set_status ( 'processing' ) return sketch . id , timeline . id