# # # add_file "enscriptlangs.py" # content [95c443cac402a883b7f523a46faba66d2c79caaf] # # add_file "file.psp" # content [94b9b9755a369fa78cc881c1be574e017a3819b9] # # add_file "langlist.sh" # content [365a8bc8a68ddc0bbc21c5ff2b00df54aee50352] # # patch "config.py.example" # from [e3a572080fc1c44961b2c5137633a17fb78f69a7] # to [7627e154e30ee6e88e547312876aa5cca8bf7c7e] # # set "langlist.sh" # attr "mtn:execute" # value "true" # ============================================================ --- enscriptlangs.py 95c443cac402a883b7f523a46faba66d2c79caaf +++ enscriptlangs.py 95c443cac402a883b7f523a46faba66d2c79caaf @@ -0,0 +1,1 @@ +enscript_langs = ['ada', 'asm', 'awk', 'bash', 'changelog', 'cpp', 'csh', 'c', 'delphi', 'diffs', 'diff', 'diffu', 'dylan', 'eiffel', 'elisp', 'erlang', 'forth', 'fortran_pp', 'fortran', 'haskell', 'html', 'icon', 'idl', 'inf', 'javascript', 'java', 'ksh', 'lua', 'm4', 'mail', 'makefile', 'matlab', 'nroff', 'oberon2', 'objc', 'outline', 'oz', 'pascal', 'perl', 'postscript', 'pyrex', 'python', 'rfc', 'scheme', 'sh', 'skill', 'Smalltalk', 'sml', 'sql', 'states', 'synopsys', 'tcl', 'tcsh', 'tex', 'vba', 'verilog', 'vhdl', 'vrml', 'wmlscript', 'zsh', ] ============================================================ --- file.psp 94b9b9755a369fa78cc881c1be574e017a3819b9 +++ file.psp 94b9b9755a369fa78cc881c1be574e017a3819b9 @@ -0,0 +1,122 @@ +<% + +import mimetypes +import datetime +import monotone +import common +import config +import urllib +import pipes +import time +import os +from enscriptlangs import enscript_langs +from html import get_icon, TableWriter + +# file.psp ; provide information about a file +# if possible, display it (with syntax highlighting, etc.) +# provide a download link + +psp.set_error_page("error.psp") + +if not form.has_key('id'): + raise Exception("No revision ID specified.") + +id = form['id'] +if not monotone.is_valid_id(id): + raise Exception("Specified revision ID is not valid.") + +if not form.has_key('path'): + raise Exception("No path specified.") +path = form['path'] + +revision = mt.revision(id) +if not revision.has_key('new_manifest'): + raise Exception("There is no manifest in this revision ID.") +manifest_id = revision['new_manifest'][0][0][1] +manifest = mt.manifest(manifest_id) + +matching_file_id = None +for file_id, filename in manifest: + if filename == path: + matching_file_id = file_id + break +if matching_file_id == None: + raise Exception("File not found in this revision.") + +info = { + 'title' : "File '/%s' in revision %s" % (hq(path), hq(id)), + } +req.write(template.header(info)) + +contents = mt.file(matching_file_id) + +%> + +<% + +# is it binary? +def is_binary(): + nontext_chars = "\x01\x02\x03\x04\x05\x06\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1c\x1d\x1e\x1f" + check = {} + for char in nontext_chars: + check[char] = True + for i in contents: + if check.has_key(i): return True + return False + +mime_type = mimetypes.guess_type(path)[0] +if mime_type == None: mime_type = 'text/plain' +if mime_type == 'image/png' or mime_type == 'image/jpeg' or mime_type == 'image/gif': + display_as_image = True +else: display_as_image = False +# okay; can we guess a valid enscript filter to run this through? +tsp = mime_type.split('/', 1) +filter = None +if tsp[0] == 'text': + candidate = tsp[1] + if candidate.startswith('x-'): candidate = candidate[2:] + if candidate.endswith('src'): candidate = candidate[:-3] + req.write("candidate: %s
" % candidate) + if candidate == 'c++': candidate = 'cpp' # ugly + if candidate in enscript_langs: filter = candidate +if filter == None: + # heh, will at least work for lua files + candidate = path.rsplit('.', 1) + if candidate in enscript_langs: filter = candidate + +# if no filter then let's check if it's binary or not; if not binary +# we'll just treat it as text; otherwise display a warning and a download +# link +if filter == None and not is_binary(): + filter = 'text' + +req.write('

For more information about the revision containing this file, see its %s page. For other files contained in this revision, see the %s.

' % (link("revision", id, "revision"), link("manifest", id, "manifest"))) + +req.write('

You can also %s the file verbatim.

' % link("download", [matching_file_id, path], "download")) + +req.write('''
''') +if display_as_image: + req.write(''''): + in_contents = True + req.write('
')
+		elif in_contents:
+			req.write(line)
+		if line.startswith('
'): in_contents = False +else: + req.write('''

This file seems to binary and not suitable for display in the browser. You must %s the file and use a suitable viewer.

''' % (link("download", [matching_file_id, path], "download"))) +req.write('''
''') + +req.write(template.footer(info)) + +%> ============================================================ --- langlist.sh 365a8bc8a68ddc0bbc21c5ff2b00df54aee50352 +++ langlist.sh 365a8bc8a68ddc0bbc21c5ff2b00df54aee50352 @@ -0,0 +1,3 @@ + +echo -n 'enscript_langs = ['; for i in `enscript --help-highlight | grep Name | awk {'print $2'}`; do echo -n "'$i', "; done; echo ']' + ============================================================ --- config.py.example e3a572080fc1c44961b2c5137633a17fb78f69a7 +++ config.py.example 7627e154e30ee6e88e547312876aa5cca8bf7c7e @@ -35,6 +35,9 @@ # and where they are on the web gnome_mimetype_uri = 'mimetypes/' +# where to find GNU enscript +enscript_path = '/usr/bin/enscript' + graphopts = { # a directory (must be writable by the web user) # in which viewmtn can output graph files