<s> import frappe , random <EOL> settings = frappe . _dict ( <EOL> prob = { <EOL> "<STR_LIT:default>" : { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:5> ) } , <EOL> } <EOL> ) <EOL> def add_random_children ( doc , fieldname , rows , randomize , unique = None ) : <EOL> nrows = rows <EOL> if rows > <NUM_LIT:1> : <EOL> nrows = random . randrange ( <NUM_LIT:1> , rows ) <EOL> for i in xrange ( nrows ) : <EOL> d = { } <EOL> for key , val in randomize . items ( ) : <EOL> if isinstance ( val [ <NUM_LIT:0> ] , basestring ) : <EOL> d [ key ] = get_random ( * val ) <EOL> else : <EOL> d [ key ] = random . randrange ( * val ) <EOL> if unique : <EOL> if not doc . get ( fieldname , { unique : d [ unique ] } ) : <EOL> doc . append ( fieldname , d ) <EOL> else : <EOL> doc . append ( fieldname , d ) <EOL> def get_random ( doctype , filters = None ) : <EOL> condition = [ ] <EOL> if filters : <EOL> for key , val in filters . items ( ) : <EOL> condition . append ( "<STR_LIT>" % ( key , str ( val ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) ) ) <EOL> if condition : <EOL> condition = "<STR_LIT>" + "<STR_LIT>" . join ( condition ) <EOL> else : <EOL> condition = "<STR_LIT>" <EOL> out = frappe . db . sql ( """<STR_LIT>""" % ( doctype , condition ) ) <EOL> return out and out [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] or None <EOL> def can_make ( doctype ) : <EOL> return random . random ( ) < settings . prob . get ( doctype , settings . prob [ "<STR_LIT:default>" ] ) [ "<STR_LIT>" ] <EOL> def how_many ( doctype ) : <EOL> return random . randrange ( * settings . prob . get ( doctype , settings . prob [ "<STR_LIT:default>" ] ) [ "<STR_LIT>" ] ) </s>
