def enumerate_suites(request): """ Return a list of suite names. Arguments: ctx (optional) - filter suites containing supplied ctx name json (optional) - return result in JSON format """ ctx_name = request.REQUEST.get('context', None) as_json = request.REQUEST.get('json', False) target = request.REQUEST.get('target', False) suites = [] root = contrib.get_document_root(target) contextini = settings.TEST_CONTEXT_FILE_NAME for dirpath, dirnames, filenames in os.walk(root, followlinks=True): if not ( contextini in filenames ): continue if ctx_name: contextfile = os.path.join(dirpath, contextini) ctx = context.get(contextfile) ctx_sections = ctx.sections() if not ctx_name in ctx_sections: continue suites += [ dirpath.replace(root, '').replace('\\','/').lstrip('/') ] if as_json: return HttpResponse(json.dumps(suites)) return HttpResponse(str(suites).replace('[','').replace(']','').rstrip(',').replace('\'',''))
def patch(request): path = get_path(request) if path: document_root = contrib.get_document_root(path) full_path = contrib.get_full_path(document_root, path) log.debug('add full path for %s path: %s , fullpath: %s' % (fn, path, full_path)) return fn(request, contrib.get_full_path(document_root, path)) return fn(request)
def saveTestSatelliteScripts(url, path, ctx): """ uploads all scripts those test or suite depends on to remote server from the context """ document_root = contrib.get_document_root(path) virtual_root = contrib.get_virtual_root(path) log.info('save satellite scripts for: %s' % path) saveAllLibraries(document_root, virtual_root, url, path, ctx) saveToolsAllScripts(url, document_root, virtual_root, ctx)
def show_context(request, path): document_root = contrib.get_document_root(path) fullpath = contrib.get_full_path(document_root, path) log.debug('show context of %s (%s %s)' % (fullpath, document_root, path)) result = "" sections = config.sections(context.get(fullpath).inifile) for section_name in sections: ctx = context.get(fullpath, section=section_name) context_ini = context.render_ini(path, ctx, request.get_host(), section_name) result += context_ini return HttpResponse(result)
def search_view_ext(request, path=None, search_pattern=None, as_json=False, global_search=True): path = request.GET.get('path', path) search_pattern = request.GET.get('search_pattern',search_pattern) as_json = request.GET.get('as_json', as_json) document_root = contrib.get_document_root(path) if global_search: path = contrib.get_virtual_root(path) full_path = contrib.get_full_path(document_root, path) print path, full_path, document_root folders = [ full_path ] log.debug(locals()) if os.path.isfile(full_path): folders = [ os.path.dirname(full_path) ] path = os.path.dirname( path ) return search_view(request, folders, path, search_pattern, as_json)
def serve(request, path, show_indexes=False): document_root = contrib.get_document_root(path) fullpath = contrib.get_full_path(document_root, path) log.debug('show index of %s(%s %s)' % (fullpath, document_root, path)) if os.path.isdir(fullpath): if 'history' in request.REQUEST: import reporting context = request.REQUEST.get('context') date = request.REQUEST.get('history', None) asxml = request.REQUEST.get('xml', None) asjson = request.REQUEST.get('json', None) if not date: results = reporting.getSuiteHistoryResults(path, context) return _render_to_response('history_list.html', locals()) if asxml: tests_list = reporting.getResultsAsXml(path, context, date, request) return HttpResponse(tests_list) tests_list = reporting.getResults(path, context, date) if asjson: url = reporting.getTestResultsUrl(path, context, date, request) result = { 'url': url, 'data': tests_list } return HttpResponse(json.dumps(result)) return _render_to_response('history.html', locals()) if request.path and request.path[-1:] != '/': return HttpResponseRedirect(request.path + '/') if show_indexes: template = load_index_template() descriptor = get_dir_index(document_root, path, fullpath) return HttpResponse(template.render(descriptor)) if not os.path.exists(fullpath): if 'editor' in request.REQUEST: #open(fullpath, 'w').close() # creating file if not exists by editor opening it first time tools.make(fullpath) else: raise Http404('"%s" does not exist' % fullpath) if 'editor' in request.REQUEST: descriptor = get_file_content_to_edit(path, fullpath, is_stubbed(path, request)) stub(path, request) return _render_to_response('editor.html', descriptor, context_instance=RequestContext(request)) return get_file_content(fullpath)
def breadcrumbs(path): """ >>> breadcrumbs('') '' >>> breadcrumbs('/') '' >>> breadcrumbs('/path1/') '<a href="/">•</a> <a>path1</a> <a href="//"><img height="11" src="/static/img/up.png" /></a>' """ path = path.replace('\\','/') document_root = contrib.get_document_root(path) fullpath = contrib.get_full_path(document_root, path) type = dir_index_tools.get_type(fullpath) if document_root and document_root != '/': html = '<a href="/">•</a> ' root = '/' lastpath = root i = 0 crumbs = path.rstrip('/').split('/') for p in crumbs: i += 1 if p: lastpath += p lastpath += '/' if i < len(crumbs): html += '<a href="%s">%s</a> ‣ ' % ( lastpath, p ) else: html += '<a>%s</a> ' % ( p ) if type != 'test': html += '<a href="%s%s"><img height="11" src="/static/img/up.png" /></a>' % (root, above(path)) else: html = '' return mark_safe(html)
def serve(request, path, show_indexes=False): document_root = contrib.get_document_root(path) fullpath = contrib.get_full_path(document_root, path) log.debug('show index of %s(%s %s)' % (fullpath, document_root, path)) if os.path.isdir(fullpath): if request.path and request.path[-1:] != '/': return HttpResponseRedirect(request.path + '/') if show_indexes: template = load_index_template() descriptor = get_dir_index(document_root, path, fullpath) return HttpResponse(template.render(descriptor)) if not os.path.exists(fullpath): if 'editor' in request.REQUEST: open(fullpath, 'w').close() # creating file if not exists by editor opening it first time else: raise Http404('"%s" does not exist' % fullpath) if 'editor' in request.REQUEST: descriptor = get_file_content_to_edit(path, fullpath, is_stubbed(path, request)) stub(path, request) return _render_to_response('editor.html', descriptor, context_instance=RequestContext(request)) return get_file_content(fullpath)
def saveSuiteAllTests(url, path, ctx): document_root = contrib.get_document_root(path) tests = contrib.enum_suite_tests( contrib.get_full_path(document_root, path) ) log.info('save suite tests for: %s' % path) uploadFolderToRemote(tests, path, document_root, ctx, url, 'test')