<s> from daapserver . models import Server , Database , Item , Container , ContainerItem <EOL> from daapserver import DaapServer , provider <EOL> import sys <EOL> import copy <EOL> import gevent <EOL> import random <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> class RevisionProvider ( provider . Provider ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( RevisionProvider , self , ) . __init__ ( ) <EOL> self . server = server = Server ( name = "<STR_LIT>" ) <EOL> database = Database ( id = <NUM_LIT:1> , name = "<STR_LIT>" ) <EOL> server . databases . add ( database ) <EOL> container_one = Container ( id = <NUM_LIT:1> , name = "<STR_LIT>" , is_base = True ) <EOL> database . containers . add ( container_one ) <EOL> gevent . spawn ( self . do_random_things ) <EOL> self . update ( ) <EOL> def do_random_things ( self ) : <EOL> database = self . server . databases [ <NUM_LIT:1> ] <EOL> counter = <NUM_LIT:1> <EOL> while True : <EOL> if not database . items : <EOL> choice = "<STR_LIT>" <EOL> else : <EOL> choice = random . choice ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> if choice == "<STR_LIT>" : <EOL> item = Item ( <EOL> id = counter , artist = "<STR_LIT>" , album = "<STR_LIT>" , <EOL> name = "<STR_LIT>" % counter , duration = counter ) <EOL> container_item = ContainerItem ( id = counter , item_id = item . id ) <EOL> counter += <NUM_LIT:1> <EOL> database . items . add ( item ) <EOL> database . containers [ <NUM_LIT:1> ] . container_items . add ( container_item ) <EOL> logger . info ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , item . id , len ( database . items ) , self . revision ) <EOL> elif choice == "<STR_LIT>" : <EOL> item = random . choice ( database . items . values ( ) ) <EOL> container_item = database . containers [ <NUM_LIT:1> ] . container_items [ item . id ] <EOL> item = copy . copy ( item ) <EOL> container_item = copy . copy ( container_item ) <EOL> item . duration += <NUM_LIT:1000> * <NUM_LIT> <EOL> database . containers [ <NUM_LIT:1> ] . container_items . add ( container_item ) <EOL> database . items . add ( item ) <EOL> logger . info ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , item . id , len ( database . items ) , self . revision ) <EOL> elif choice == "<STR_LIT>" : <EOL> item = random . choice ( database . items . values ( ) ) <EOL> container_item = database . containers [ <NUM_LIT:1> ] . container_items [ item . id ] <EOL> database . containers [ <NUM_LIT:1> ] . container_items . remove ( container_item ) <EOL> database . items . remove ( item ) <EOL> logger . info ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , item . id , len ( database . items ) , self . revision ) <EOL> database . containers . add ( database . containers [ <NUM_LIT:1> ] ) <EOL> self . server . databases . add ( database ) <EOL> self . update ( ) <EOL> if choice in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> assert list ( database . items ( self . revision ) . updated ( <EOL> database . items ( self . revision - <NUM_LIT:1> ) ) ) == [ item . id ] <EOL> elif choice == "<STR_LIT>" : <EOL> assert list ( database . items ( self . revision ) . removed ( <EOL> database . items ( self . revision - <NUM_LIT:1> ) ) ) == [ item . id ] <EOL> gevent . sleep ( <NUM_LIT> ) <EOL> def get_item_data ( self , * args , ** kwargs ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def main ( ) : <EOL> logging . basicConfig ( <EOL> level = logging . DEBUG , <EOL> format = "<STR_LIT>" ) <EOL> server = DaapServer ( <EOL> provider = RevisionProvider ( ) , <EOL> port = <NUM_LIT> , <EOL> debug = True ) <EOL> server . serve_forever ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( ) ) </s>
