#NEWLINE# def parse_workflow_config( rawactions ) : #NEWLINE# #INDENT# 'Given a list of options from [ticket-workflow]' #NEWLINE# required_attrs = { #NEWLINE# #INDENT# 'oldstates' : [ ] , #NEWLINE# 'newstate' : '' , #NEWLINE# 'name' : '' , #NEWLINE# 'label' : '' , #NEWLINE# 'default' : 0 , #NEWLINE# 'operations' : [ ] , #NEWLINE# 'permissions' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# optional_attrs = { #NEWLINE# #INDENT# 'set_owner' : [ ] , #NEWLINE# 'set_resolution' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# known_attrs = required_attrs . copy ( ) #NEWLINE# known_attrs . update ( optional_attrs ) #NEWLINE# actions = defaultdict ( dict ) #NEWLINE# for ( option , value ) in rawactions : #NEWLINE# #INDENT# parts = option . split ( '.' ) #NEWLINE# name = parts [ 0 ] #NEWLINE# if ( len ( parts ) == 1 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( oldstates , newstate ) = [ x . strip ( ) for x in value . split ( '->' ) ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# actions [ name ] [ 'oldstates' ] = to_list ( oldstates ) #NEWLINE# actions [ name ] [ 'newstate' ] = newstate #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attribute = parts [ 1 ] #NEWLINE# if ( ( attribute not in known_attrs . keys ( ) ) or isinstance ( known_attrs [ attribute ] , str ) ) : #NEWLINE# #INDENT# actions [ name ] [ attribute ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( known_attrs [ attribute ] , int ) : #NEWLINE# #INDENT# actions [ name ] [ attribute ] = int ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( known_attrs [ attribute ] , list ) : #NEWLINE# #INDENT# actions [ name ] [ attribute ] = to_list ( value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for ( action , attributes ) in actions . items ( ) : #NEWLINE# #INDENT# if ( 'label' not in attributes ) : #NEWLINE# #INDENT# if ( 'name' in attributes ) : #NEWLINE# #INDENT# attributes [ 'label' ] = attributes [ 'name' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attributes [ 'label' ] = action . replace ( '_' , ' ' ) . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# for ( key , val ) in required_attrs . items ( ) : #NEWLINE# #INDENT# attributes . setdefault ( key , val ) #NEWLINE# #UNINDENT# #UNINDENT# return actions