#NEWLINE# @ transaction . atomic #NEWLINE# def handle_noargs( self , users = None , review_requests = None , diffs = None , reviews = None , diff_comments = None , password = None , verbosity = NORMAL , **options ) : #NEWLINE# #INDENT# num_of_requests = None #NEWLINE# num_of_diffs = None #NEWLINE# num_of_reviews = None #NEWLINE# num_of_diff_comments = None #NEWLINE# random . seed ( ) #NEWLINE# if form : #NEWLINE# #INDENT# num_of_requests = self . parse_command ( 'review_requests' , review_requests ) #NEWLINE# repo_dir = os . path . abspath ( os . path . join ( sys . argv [ 0 ] , '..' , 'scmtools' , 'testdata' , 'git_repo' ) ) #NEWLINE# if ( not os . path . exists ( repo_dir ) ) : #NEWLINE# #INDENT# raise CommandError ( 'No path to the repository' ) #NEWLINE# #UNINDENT# self . repository = Repository . objects . create ( name = 'Test Repository' , path = repo_dir , tool = Tool . objects . get ( name = 'Git' ) ) #NEWLINE# #UNINDENT# if diffs : #NEWLINE# #INDENT# num_of_diffs = self . parse_command ( 'diffs' , diffs ) #NEWLINE# diff_dir_tmp = os . path . abspath ( os . path . join ( sys . argv [ 0 ] , '..' , 'reviews' , 'management' , 'commands' , 'diffs' ) ) #NEWLINE# if ( not os . path . exists ( diff_dir_tmp ) ) : #NEWLINE# #INDENT# raise CommandError ( 'Diff dir does not exist' ) #NEWLINE# #UNINDENT# diff_dir = ( diff_dir_tmp + '/' ) #NEWLINE# files = [ f for f in os . listdir ( diff_dir ) if f . endswith ( '.diff' ) ] #NEWLINE# if ( len ( files ) == 0 ) : #NEWLINE# #INDENT# raise CommandError ( 'No diff files in this directory' ) #NEWLINE# #UNINDENT# #UNINDENT# if reviews : #NEWLINE# #INDENT# num_of_reviews = self . parse_command ( 'reviews' , reviews ) #NEWLINE# #UNINDENT# if diff_comments : #NEWLINE# #INDENT# num_of_diff_comments = self . parse_command ( 'diff-comments' , diff_comments ) #NEWLINE# #UNINDENT# if ( not users ) : #NEWLINE# #INDENT# raise CommandError ( 'At least one user must be added' ) #NEWLINE# #UNINDENT# for i in range ( 1 , ( users + 1 ) ) : #NEWLINE# #INDENT# new_user = User . objects . create ( username = self . rand_username ( ) , first_name = random . choice ( NAMES ) , last_name = random . choice ( NAMES ) , email = 'test@example.com' , is_staff = False , is_active = True , is_superuser = False ) #NEWLINE# if password : #NEWLINE# #INDENT# new_user . set_password ( password ) #NEWLINE# new_user . save ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# new_user . set_password ( 'test1' ) #NEWLINE# new_user . save ( ) #NEWLINE# #UNINDENT# Profile . objects . create ( user = new_user , first_time_setup_done = True , collapsed_diffs = True , wordwrapped_diffs = True , syntax_highlighting = True , show_closed = True ) #NEWLINE# req_val = self . pick_random_value ( num_of_requests ) #NEWLINE# if ( int ( verbosity ) > NORMAL ) : #NEWLINE# #INDENT# self . stdout . write ( ( 'For user %s:%s' % ( i , new_user . username ) ) ) #NEWLINE# self . stdout . write ( '=============================' ) #NEWLINE# #UNINDENT# for j in range ( 0 , req_val ) : #NEWLINE# #INDENT# if ( int ( verbosity ) > NORMAL ) : #NEWLINE# #INDENT# self . stdout . write ( ( 'Request #%s:' % j ) ) #NEWLINE# #UNINDENT# review_request = ReviewRequest . objects . create ( new_user , None ) #NEWLINE# review_request . public = True #NEWLINE# review_request . summary = self . lorem_ipsum ( 'summary' ) #NEWLINE# review_request . description = self . lorem_ipsum ( 'description' ) #NEWLINE# review_request . shipit_count = 0 #NEWLINE# review_request . repository = self . repository #NEWLINE# if ( j == 0 ) : #NEWLINE# #INDENT# review_request . target_people . add ( User . objects . get ( pk = 1 ) ) #NEWLINE# #UNINDENT# review_request . save ( ) #NEWLINE# diff_val = self . pick_random_value ( num_of_diffs ) #NEWLINE# if ( diff_val > 0 ) : #NEWLINE# #INDENT# diffset_history = DiffSetHistory . objects . create ( name = ( 'testDiffFile' + six . text_type ( i ) ) ) #NEWLINE# diffset_history . save ( ) #NEWLINE# #UNINDENT# for k in range ( 0 , diff_val ) : #NEWLINE# #INDENT# if ( int ( verbosity ) > NORMAL ) : #NEWLINE# #INDENT# self . stdout . write ( ( '%s:\tDiff #%s' % ( i , k ) ) ) #NEWLINE# #UNINDENT# random_number = random . randint ( 0 , ( len ( files ) - 1 ) ) #NEWLINE# file_to_open = ( diff_dir + files [ random_number ] ) #NEWLINE# f = open ( file_to_open , 'r' ) #NEWLINE# form = UploadDiffForm ( review_request = review_request , files = { #NEWLINE# #INDENT# 'path' : File ( f ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# cur_diff = form . create ( f , None , diffset_history ) #NEWLINE# #UNINDENT# review_request . diffset_history = diffset_history #NEWLINE# review_request . save ( ) #NEWLINE# review_request . publish ( new_user ) #NEWLINE# f . close ( ) #NEWLINE# review_val = self . pick_random_value ( num_of_reviews ) #NEWLINE# for l in range ( 0 , review_val ) : #NEWLINE# #INDENT# if ( int ( verbosity ) > NORMAL ) : #NEWLINE# #INDENT# self . stdout . write ( ( '%s:%s:\t\tReview #%s:' % ( i , j , l ) ) ) #NEWLINE# #UNINDENT# reviews = Review . objects . create ( review_request = review_request , user = new_user ) #NEWLINE# reviews . publish ( new_user ) #NEWLINE# comment_val = self . pick_random_value ( num_of_diff_comments ) #NEWLINE# for m in range ( 0 , comment_val ) : #NEWLINE# #INDENT# if ( int ( verbosity ) > NORMAL ) : #NEWLINE# #INDENT# self . stdout . write ( ( '%s:%s:\t\t\tComments #%s' % ( i , j , m ) ) ) #NEWLINE# #UNINDENT# if ( m == 0 ) : #NEWLINE# #INDENT# file_diff = cur_diff . files . order_by ( 'id' ) [ 0 ] #NEWLINE# #UNINDENT# max_lines = 220 #NEWLINE# first_line = random . randrange ( 1 , ( max_lines - 1 ) ) #NEWLINE# remain_lines = ( max_lines - first_line ) #NEWLINE# num_lines = random . randrange ( 1 , remain_lines ) #NEWLINE# diff_comment = Comment . objects . create ( filediff = file_diff , text = ( 'comment number %s' % ( m + 1 ) ) , first_line = first_line , num_lines = num_lines ) #NEWLINE# review_request . publish ( new_user ) #NEWLINE# reviews . comments . add ( diff_comment ) #NEWLINE# reviews . save ( ) #NEWLINE# reviews . publish ( new_user ) #NEWLINE# db . reset_queries ( ) #NEWLINE# #UNINDENT# if ( comment_val == 0 ) : #NEWLINE# #INDENT# db . reset_queries ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( review_val == 0 ) : #NEWLINE# #INDENT# db . reset_queries ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( diff_val == 0 ) : #NEWLINE# #INDENT# db . reset_queries ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( req_val == 0 ) : #NEWLINE# #INDENT# db . reset_queries ( ) #NEWLINE# #UNINDENT# if ( req_val != 0 ) : #NEWLINE# #INDENT# self . stdout . write ( ( 'user %s created with %s requests' % ( new_user . username , req_val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . stdout . write ( ( 'user %s created successfully' % new_user . username ) )