<s> import logging <EOL> import StringIO <EOL> import traceback <EOL> from celery . decorators import task <EOL> from django . utils . translation import ugettext as _ <EOL> from projector . models import Project , State <EOL> from projector . utils import str2obj <EOL> from projector . settings import get_config_value <EOL> @ task <EOL> def project_create_repository ( instance , vcs_alias = None ) : <EOL> if get_config_value ( '<STR_LIT>' ) : <EOL> instance . create_repository ( vcs_alias ) <EOL> @ task <EOL> def setup_project ( instance , vcs_alias = None , workflow = None ) : <EOL> """<STR_LIT>""" <EOL> logging . debug ( "<STR_LIT>" % instance ) <EOL> if isinstance ( workflow , str ) : <EOL> workflow = str2obj ( workflow ) <EOL> if vcs_alias : <EOL> instance . set_vcs_alias ( vcs_alias ) <EOL> if workflow : <EOL> instance . set_workflow ( workflow ) <EOL> current_state = instance . state <EOL> try : <EOL> instance . set_memberships ( ) <EOL> current_state = State . MEMBERSHIPS_CREATED <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> instance . set_author_permissions ( ) <EOL> current_state = State . AUTHOR_PERMISSIONS_CREATED <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> instance . create_workflow ( ) <EOL> current_state = State . WORKFLOW_CREATED <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> instance . create_config ( ) <EOL> current_state = State . CONFIG_CREATED <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> if get_config_value ( '<STR_LIT>' ) : <EOL> instance . create_repository ( vcs_alias = vcs_alias ) <EOL> current_state = State . REPOSITORY_CREATED <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> current_state = State . READY <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = current_state ) <EOL> except ( MemoryError , KeyboardInterrupt ) : <EOL> raise <EOL> except Exception : <EOL> try : <EOL> from djangodblog . models import Error <EOL> Error . objects . create_from_exception ( ) <EOL> except ImportError : <EOL> pass <EOL> Project . objects . filter ( pk = instance . pk ) . update ( state = State . ERROR ) <EOL> user_error_text = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> stack = StringIO . StringIO ( ) <EOL> traceback . print_exc ( file = stack ) <EOL> stacktrace = stack . getvalue ( ) <EOL> logging . error ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( current_state , stacktrace ) ) <EOL> Project . objects . filter ( pk = instance . pk ) . update ( <EOL> error_text = user_error_text ) </s>
