#NEWLINE# def get_current_scripts( ) : #NEWLINE# #INDENT# from .. models import ScriptVersion #NEWLINE# try : #NEWLINE# #INDENT# scripts = ScriptVersion . objects . count ( ) #NEWLINE# #UNINDENT# except OperationalError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# scripts = ScriptVersion . objects . select_related ( 'script' ) . filter ( default_version = True ) #NEWLINE# non_default_scripts = ScriptVersion . objects . filter ( default_version = False ) . exclude ( script__in = [ i . script for i in scripts ] ) #NEWLINE# script_versions = defaultdict ( list ) #NEWLINE# for sv in non_default_scripts : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# version_string = parse_version ( str ( sv . script_version ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# sys . stderr . write ( 'Error converting script version:\n{}' . format ( traceback . format_exc ( ) ) ) #NEWLINE# version_string = sv . script_version #NEWLINE# #UNINDENT# script_versions [ sv . script . script_name ] . append ( ( version_string , sv . script_iteration , sv ) ) #NEWLINE# [ script_versions [ i ] . sort ( key = itemgetter ( 0 , 1 , 2 ) , reverse = True ) for i in script_versions ] #NEWLINE# #UNINDENT# scripts = [ i . script for i in scripts ] #NEWLINE# if script_versions : #NEWLINE# #INDENT# for script_version_info in script_versions . values ( ) : #NEWLINE# #INDENT# new_scripts = ScriptVersion . objects . select_related ( 'script' ) . filter ( pk__in = [ i [ 2 ] . pk for i in script_version_info ] ) #NEWLINE# scripts . extend ( [ i . script for i in new_scripts ] ) #NEWLINE# #UNINDENT# #UNINDENT# return scripts