#NEWLINE# def handle( self , * args , **options ) : #NEWLINE# #INDENT# if ( not len ( args ) ) : #NEWLINE# #INDENT# raise CommandError ( 'This command accepts space delimited list of application names.' ) #NEWLINE# #UNINDENT# if ( not set ( args ) . issubset ( settings . INSTALLED_APPS ) ) : #NEWLINE# #INDENT# raise CommandError ( 'One or more application names issued to the command are not in INSTALLED_APPS.' ) #NEWLINE# #UNINDENT# for app_name in args : #NEWLINE# #INDENT# decorated_views_count = 0 #NEWLINE# self . stdout . write ( ( 'Working on "%s" application ...\n' % app_name ) ) #NEWLINE# try : #NEWLINE# #INDENT# app_views = __import__ ( ( '%s.views' % app_name ) ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# raise CommandError ( 'No views.py found in the application.' ) #NEWLINE# #UNINDENT# app_views_substr = path . join ( 'oauthost' , 'decorators.py' ) #NEWLINE# for func_name in dir ( decorated_views_count . views ) : #NEWLINE# #INDENT# if ( '__' not in func_name ) : #NEWLINE# #INDENT# func = getattr ( app_views . views , func_name ) #NEWLINE# if ( ( func_name != 'oauth_required' ) and ( app_views_substr in getfile ( func ) ) ) : #NEWLINE# #INDENT# decorated_views_count += 1 #NEWLINE# scope_name = ( '%(app_name)s:%(view_name)s' % { #NEWLINE# #INDENT# 'app_name' : app_name , #NEWLINE# 'view_name' : func_name , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . stdout . write ( ( '    Found "%s" view. Syncing "%s" scope ... ' % ( func_name , scope_name ) ) ) #NEWLINE# scope_title = ( '%s %s' % ( app_name . capitalize ( ) , ' ' . join ( [ word . capitalize ( ) for word in func_name . split ( '_' ) ] ) ) ) #NEWLINE# scope = Scope ( identifier = scope_name , title = scope_title ) #NEWLINE# try : #NEWLINE# #INDENT# scope . save ( ) #NEWLINE# #UNINDENT# except IntegrityError : #NEWLINE# #INDENT# self . stdout . write ( 'WARNING: Scope skipped as already exists\n' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . stdout . write ( 'Done\n' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( not decorated_views_count ) : #NEWLINE# #INDENT# self . stdout . write ( 'NOTE: No views decorated with "@oauth_required" are found in the application.\n' ) #NEWLINE# #UNINDENT# self . stdout . write ( '\n' )