@@ -595,3 +595,51 @@ def _make_links(project, rev, author, path, page, query):
595595 'graph_data' : graph_data ,
596596 })
597597 return tdt
598+
599+
600+ def browsefiles (request , username , projectname ):
601+ from vilya .models .project import CodeDoubanProject
602+
603+ def _add_file_type_and_warns (node ):
604+ code_file_exts = 'py rb c h html mako ptl js css less handlebars coffee sql' .split () # noqa
605+ bad_exts = 'pyc exe' .split ()
606+ node_ext = node ['path' ].rsplit ('.' )[1 ] if '.' in node ['path' ] else ''
607+ if node ['type' ] == 'tree' :
608+ icon_type = 'directory'
609+ elif node ['type' ] == 'commit' :
610+ icon_type = 'submodule'
611+ elif node_ext in code_file_exts :
612+ icon_type = 'code-file'
613+ else :
614+ icon_type = 'text-file'
615+ node ['icon-type' ] = icon_type
616+ if node_ext in bad_exts :
617+ node ['warn' ] = 'bad'
618+ else :
619+ node ['warn' ] = 'no'
620+ return node
621+
622+ name = '/' .join ([username , projectname ])
623+
624+ if 'json' in request .environ ['HTTP_ACCEPT' ]:
625+ output = 'json'
626+ else :
627+ output = 'html'
628+ project = CodeDoubanProject .get_by_name (name )
629+ user = request .user
630+ path = request .GET .get ('path' , '' )
631+ rev = request .GET .get ('rev' , project .default_branch )
632+ allfiles = project .repo .get_tree (rev , path = path )
633+ allfiles = [_add_file_type_and_warns (f ) for f in allfiles ]
634+ errors = ''
635+ ref = rev
636+ if ref is None :
637+ ref = project .default_branch
638+ branches = project .repo .branches
639+ tags = project .repo .tags
640+ ref_type = 'branch' if ref in branches else 'tag' \
641+ if ref in tags else 'tree'
642+ if output == 'json' :
643+ return HttpResponse (json .dumps (allfiles ))
644+ else :
645+ return HttpResponse (st ('browsefiles.html' , ** locals ()))
0 commit comments