def test_init_show_planned(self):
     begin = now()-timedelta(minutes=10)
     end = now()+timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel',
                 description='description',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.user)
     rfk.database.session.commit()
     self.test_do_connect_valid_user()
     self.assertEqual(show, show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.PLANNED, Show.FLAGS.PLANNED)
Esempio n. 2
0
 def test_init_show_planned(self):
     begin = now() - timedelta(minutes=10)
     end = now() + timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel',
                 description='description',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.user)
     rfk.database.session.commit()
     self.test_do_connect_valid_user()
     self.assertEqual(show, show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.PLANNED,
                      Show.FLAGS.PLANNED)
Esempio n. 3
0
 def test_transition_unplanned_planned(self):
     self.test_init_show_unplanned()
     show = Show.get_active_show()
     show.begin = show.begin - timedelta(minutes=5)
     rfk.database.session.commit()
     begin = now() - timedelta(minutes=3)
     end = now() + timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel2',
                 description='description2',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.other_user)
     rfk.database.session.commit()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show(), show)
 def test_transition_unplanned_planned(self):
     self.test_init_show_unplanned()
     show = Show.get_active_show()
     show.begin = show.begin - timedelta(minutes=5)
     rfk.database.session.commit()
     begin = now()-timedelta(minutes=3)
     end = now()+timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel2',
                 description='description2',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.other_user)
     rfk.database.session.commit()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show(), show)
Esempio n. 5
0
def init_show(user):
    """Initializes a show

        it either takes a planned show or an unplanned show if it's still running
        if non of them is found a new unplanned show is added and initialized
        if a new show was initialized the old one will be ended and the streamer status will be resetted
    """

    show = Show.get_current_show(user)
    if show is None:
        show = Show()
        if user.get_setting(code='use_icy'):
            show.add_tags(
                Tag.parse_tags(user.get_setting(code='icy_show_genre') or ''))
            show.description = user.get_setting(
                code='icy_show_description') or ''
            show.name = user.get_setting(code='icy_show_name') or ''
        else:
            show.add_tags(
                Tag.parse_tags(user.get_setting(code='show_def_tags') or ''))
            show.description = user.get_setting(code='show_def_desc') or ''
            show.name = user.get_setting(code='show_def_name') or ''
        show.logo = user.get_setting(code='show_def_logo') or None
        show.flags = Show.FLAGS.UNPLANNED
        show.add_user(user)
    elif show.flags == Show.FLAGS.UNPLANNED:
        # just check if there is a planned show to transition to
        s = Show.get_current_show(user, only_planned=True)
        if s is not None:
            show = s
    us = show.get_usershow(user)
    us.status = UserShow.STATUS.STREAMING
    rfk.database.session.commit()
    unfinished_shows = UserShow.query.filter(
        UserShow.status == UserShow.STATUS.STREAMING,
        UserShow.show != show).all()
    for us in unfinished_shows:
        if us.show.flags & Show.FLAGS.UNPLANNED:
            us.show.end_show()
        if us.status == UserShow.STATUS.STREAMING:
            us.status = UserShow.STATUS.STREAMED
        rfk.database.session.commit()
    return show
Esempio n. 6
0
def show_add():
    try:
        if 'begin' in request.form and \
                        'description' in request.form and \
                        'duration' in request.form and \
                        'title' in request.form:
            if int(request.form['duration']) < 30:
                return emit_error(6, 'Duration too short')
            if int(request.form['duration']) > 1440:
                return emit_error(5, 'Duration too long')
            if len(request.form['title']) < 3:
                return emit_error(4, 'Title too short')
            if len(request.form['description']) == 0:
                return emit_error(3, 'Description is empty')

            begin = to_utc(get_timezone().localize(
                datetime.utcfromtimestamp(int(request.form['begin']))))
            begin = begin.replace(second=0)
            end = begin + timedelta(minutes=int(request.form['duration']))
            if begin < now():
                return emit_error(2, 'You cannot enter a past date!')
            if Show.query.filter(Show.end > begin,
                                 Show.begin < end).count() > 0:
                return emit_error(1, 'Your show collides with other shows')
            show = Show(begin=begin,
                        end=end,
                        name=request.form['title'],
                        description=request.form['description'],
                        flags=Show.FLAGS.PLANNED)
            rfk.database.session.add(show)
            show.add_user(current_user)
            _set_show_info(show, request.form)
            rfk.database.session.commit()
            return jsonify({'success': True, 'data': None})
        else:
            return emit_error(
                0, 'Wait a second, are you trying to trick me again?!')
    except Exception as e:
        from rfk.site import app

        app.logger.error(e)
        return emit_error(0, 'something went horribly wrong')
Esempio n. 7
0
def copy_shows():
    local = pytz.timezone('Europe/Berlin')
    shows = oldsession.query(Show).yield_per(50)
    for oldshow in shows:
        if oldshow.streamer != None:
            user = User.get_user(username=oldshow.streamer.username)
            if oldshow.type == 'UNPLANNED':
                flag = NShow.FLAGS.UNPLANNED
            elif oldshow.type == 'PLANNED':
                flag = NShow.FLAGS.PLANNED
            show = NShow(name=oldshow.name[:50],
                        description=oldshow.description,
                        flags=flag,
                        begin=local.normalize(local.localize(oldshow.begin).astimezone(pytz.utc)),
                        end=local.normalize(local.localize(oldshow.end).astimezone(pytz.utc)))
            rfk.database.session.add(show)
            rfk.database.session.flush()
            show.add_user(user)
            rfk.database.session.flush()
            rfk.database.session.commit()
Esempio n. 8
0
def init_show(user):
    """inititalizes a show
        it either takes a planned show or an unplanned show if it's still running
        if non of them is found a new unplanned show is added and initialized
        if a new show was initialized the old one will be ended and the streamer staus will be resettet
    """
    logger.info("init_show: entering")
    logger.info("init_show: user {}".format(str(user)))
    show = Show.get_current_show(user)
    if show is None:
        logger.info("init_show: None")
        show = Show()
        if user.get_setting(code='use_icy'):
            show.add_tags(Tag.parse_tags(user.get_setting(code='icy_show_genre') or ''))
            show.description = user.get_setting(code='icy_show_description') or ''
            show.name = user.get_setting(code='icy_show_name') or ''
        else:
            show.add_tags(Tag.parse_tags(user.get_setting(code='show_def_tags') or ''))
            show.description = user.get_setting(code='show_def_desc') or ''
            show.name = user.get_setting(code='show_def_name') or ''
        show.flags = Show.FLAGS.UNPLANNED
        show.add_user(user)
    elif show.flags == Show.FLAGS.UNPLANNED:
        logger.info("init_show: UNPLANNED")
        #just check if there is a planned show to transition to
        s = Show.get_current_show(user, only_planned=True)
        if s is not None:
            logger.info("init_show: found planned")
            show = s        
    us = show.get_usershow(user)
    us.status = UserShow.STATUS.STREAMING
    rfk.database.session.flush()
    unfinished_shows = UserShow.query.filter(UserShow.status == UserShow.STATUS.STREAMING,
                                             UserShow.show != show).all()
    for us in unfinished_shows:
        if us.show.flags & Show.FLAGS.UNPLANNED:
            us.show.end_show()
        if us.status == UserShow.STATUS.STREAMING:
           us.status = UserShow.STATUS.STREAMED
        rfk.database.session.flush() 
    return show
Esempio n. 9
0
def show_add():
    try:
        if 'begin' in request.form and \
                        'description' in request.form and \
                        'duration' in request.form and \
                        'title' in request.form:
            if int(request.form['duration']) < 30:
                return emit_error(6, 'Duration too short')
            if int(request.form['duration']) > 1440:
                return emit_error(5, 'Duration too long')
            if len(request.form['title']) < 3:
                return emit_error(4, 'Title too short')
            if len(request.form['description']) == 0:
                return emit_error(3, 'Description is empty')

            begin = to_utc(datetime.fromtimestamp(int(request.form['begin'])))
            begin = begin.replace(second=0)
            end = begin + timedelta(minutes=int(request.form['duration']))
            if begin < now():
                return emit_error(2, 'You cannot enter a past date!')
            if Show.query.filter(Show.end > begin, Show.begin < end).count() > 0:
                return emit_error(1, 'Your show collides with other shows')
            show = Show(begin=begin,
                        end=end,
                        name=request.form['title'],
                        description=request.form['description'],
                        flags=Show.FLAGS.PLANNED)
            rfk.database.session.add(show)
            show.add_user(current_user)
            _set_show_info(show, request.form)
            rfk.database.session.commit()
            return jsonify({'success': True, 'data': None})
        else:
            return emit_error(0, 'Wait a second, are you trying to trick me again?!')
    except Exception as e:
        from rfk.site import app

        app.logger.error(e)
        return emit_error(0, 'something went horribly wrong')
Esempio n. 10
0
def copy_shows():
    local = pytz.timezone('Europe/Berlin')
    shows = oldsession.query(Show).yield_per(50)
    for oldshow in shows:
        if oldshow.streamer != None:
            user = User.get_user(username=oldshow.streamer.username)
            if oldshow.type == 'UNPLANNED':
                flag = NShow.FLAGS.UNPLANNED
            elif oldshow.type == 'PLANNED':
                flag = NShow.FLAGS.PLANNED
            show = NShow(name=oldshow.name[:50],
                         description=oldshow.description,
                         flags=flag,
                         begin=local.normalize(
                             local.localize(oldshow.begin).astimezone(
                                 pytz.utc)),
                         end=local.normalize(
                             local.localize(oldshow.end).astimezone(pytz.utc)))
            rfk.database.session.add(show)
            rfk.database.session.flush()
            show.add_user(user)
            rfk.database.session.flush()
            rfk.database.session.commit()