def getElement(request, element, team=None, release=None, fetch=None, linkTarget=None): """ Grab an element out of AccuRev by fileName. Convenience function for importProtocol, refreshProtocol """ if team == None or release == None: team, release = getTeamAndReleaseIDFromSession(request.session) # Different settings based on deployment if settings.LOCAL_SERVER: deploy = Repository.DEPLOY_LOCAL_WINDOWS elif settings.DEVELOPMENT_SERVER: deploy = Repository.DEPLOY_DEVELOPMENT elif settings.PRODUCTION_SERVER: deploy = Repository.DEPLOY_PRODUCTION if not fetch: try: fetch = AccuRevFetcher() except Exception as e: msg = "An unknown error occurred while fetching the protocol from the VCS. Error: %s" % e.message objContext = RequestContext(request, {'msg': msg, 'admin':settings.ADMINS}) return render_to_response('protocol_import_list_error.html', objContext) # Get the repository object for this team/release protocols in accurev try: repository = Repository.objects.get(team=team, release=release, repo_type='P', path_type='A') localrepo = Repository.objects.get(team=team, release=release, repo_type='P', path_type='L', deployment=deploy) except Exception as e: if type(e) == Repository.DoesNotExist: msg = "An AccuRev Repository for the given scope (%s/%s) does not exist. Please contact a site administrator." %(release.get_release_name_display(), team.get_team_name_display()) else: msg = "An unexpected error occurred while fetching the protocol from the VCS. Error: %s" % e.message objContext = RequestContext(request, {'file': element, 'msg': [msg, ], 'admin':settings.ADMINS}) raise GetElementError(render_to_response('protocol_import_error.html', objContext)) # Copy to the local repository # Use a different mechanism if it is an elink, should cat instead of pop try: if linkTarget: fetched_protocol = fetch.cat(repository.accurev_stream, str(os.path.join(settings.PROTOCOL_PARSE_BASE_PATH,localrepo.path).replace('\\',os.sep)), linkTarget.replace(r'/',os.sep)) else: fetched_protocol = fetch.pop(repository.accurev_stream, str(os.path.join(settings.PROTOCOL_PARSE_BASE_PATH,localrepo.path).replace('\\',os.sep)), [str(repository.path.replace('\\',os.sep)+os.sep+element), ], override=True) return (fetched_protocol, fetch, repository) except Exception as e: msg = "An unexpected error occurred while fetching the protocol from the VCS. Error: %s" % e.message objContext = RequestContext(request, {'file': element, 'msg': [msg, ], 'admin':settings.ADMINS}) raise GetElementError(render_to_response('protocol_import_error.html', objContext))