X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=c5b51096a1fbecfe242b189b8d84625b152cdb65;hp=5b98397af612e174205412d723ed251dfa82ed39;hb=99fb949cf7923eaab08664706287c120b1a93d79;hpb=60a48cbc0a948ba2a1149239f8a53c4e2c73f4fc diff --git a/geekigeeki.py b/geekigeeki.py index 5b98397..c5b5109 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -18,9 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Id$'[4:12] +__version__ = '4.0-' + '$Id$'[4:11] -from time import clock +from time import clock, localtime, gmtime, strftime start_time = clock() title_done = False @@ -105,7 +105,9 @@ def url_args(kvargs): return '' # Formatting stuff -------------------------------------------------- -def emit_header(mime_type="text/html"): +def emit_header(mtime=None, mime_type="text/html"): + if mtime: + print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime))) print("Content-type: " + mime_type + "; charset=utf-8\n") def send_guru(msg_text, msg_type): @@ -119,12 +121,12 @@ def send_guru(msg_text, msg_type): print('' \ % relative_url('sys/GuruMeditation.js')) -def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False): +def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False, mtime=None): global title_done if title_done: return # Head - emit_header() + emit_header(mtime) print('') print('') @@ -332,20 +334,21 @@ def page_list(dirname=None, re=None): re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$") return sorted(filter(re.match, os.listdir(dirname or data_dir))) -def send_footer(mod_string=None): +def send_footer(mtime=None): if globals().get('debug_cgi', False): cgi.print_arguments() cgi.print_form(form) cgi.print_environ() + #FIXME link_inline("sys/footer") print(''' ') class WikiFormatter: @@ -367,6 +370,7 @@ class WikiFormatter: "**": ["b", False], "##": ["tt", False], "__": ["u", False], + "--": ["del", False], "^^": ["sup", False], ",,": ["sub", False], "''": ["em", False], # LEGACY @@ -379,6 +383,9 @@ class WikiFormatter: style[1] = not style[1] return ['' + def _glyph_repl(self, word): + return '—' + def _tit_repl(self, word): if self.h_level: result = '

\n' % self.h_level @@ -534,19 +541,20 @@ class WikiFormatter: print('

') scan_re = re.compile(r"""(?: - # Styles and formatting - (?P \*\*|'''|//|''|\#\#|``|__|\^\^|,,) + # Styles and formatting ("--" must cling to a word to disambiguate it from the dash) + (?P \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` ) | (?P \={2,6}) | (?P
\\\\) | (?P ^-{3,}) | (?P \b( FIXME | TODO | DONE )\b ) + | (?P --) # Links | (?P \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>) | (?P \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\]) # Inline HTML - | (?P <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b ) + | (?P <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b ) | (?P ( /\s*> | ) ) | (?P [<>&] ) @@ -556,7 +564,7 @@ class WikiFormatter: | (?P (http|https|ftp|mailto)\:[^\s'\"]+\S) | (?P [-\w._+]+\@[\w.-]+) - # Lists, divs, spans + # Lists, divs, spans and inline objects | (?P

  • ^\s+[\*\#]\s+) | (?P
       \{\{\{|\s*\}\}\})
                 | (?P   \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
    @@ -621,15 +629,19 @@ class Page:
         def _tmp_filename(self):
             return os.path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + str(os.getpid()) + '#'))
     
    -    def exists(self):
    +    def _mtime(self):
             try:
    -            os.stat(self._filename())
    -            return True
    +            return os.stat(self._filename()).st_mtime
             except OSError, err:
                 if err.errno == errno.ENOENT:
    -                return False
    +                return None
                 raise err
     
    +    def exists(self):
    +        if self._mtime():
    +            return True
    +        return False
    +
         def get_raw_body(self, default=None):
             try:
                 return open(self._filename(), 'rb').read()
    @@ -645,7 +657,7 @@ class Page:
         def format_dir(self):
             out = '== '
             pathname = ''
    -        for dirname in self.page_name.split('/'):
    +        for dirname in self.page_name.strip('/').split('/'):
                 pathname = (pathname + '/' + dirname) if pathname else dirname
                 out += '[[' + pathname + '|' + dirname + ']]/'
             out += ' ==\n'
    @@ -714,19 +726,9 @@ class Page:
                 link_urls += [ [ "stylesheet", value ] ]
     
             send_title(self.page_name, self.split_title(),
    -            msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write())
    +            msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime())
             self.send_naked()
    -        send_footer(self._last_modified())
    -
    -    def _last_modified(self):
    -        try:
    -            from time import localtime, strftime
    -            modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
    -        except OSError, err:
    -            if err.errno != errno.ENOENT:
    -                raise err
    -            return None
    -        return strftime(datetime_fmt, modtime)
    +        send_footer(mtime=self._mtime())
     
         def send_editor(self, preview=None):
             send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
    @@ -771,18 +773,17 @@ class Page:
     
         def send_raw(self, mimetype='text/plain', args=[]):
             if not self.can_read():
    -            send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
    +            send_title(None, msg_text='Read access denied by ACLs', msg_type='notice', mtime=self._mtime())
                 return
     
    +        emit_header(self._mtime(), mimetype)
             if 'maxwidth' in args:
                 import subprocess
    -            emit_header(mimetype)
                 sys.stdout.flush()
                 subprocess.check_call(['gm', 'convert', self._filename(),
                     '-scale', args['maxwidth'].value + ' >', '-'])
             else:
                 body = self.get_raw_body()
    -            emit_header(mimetype)
                 print(body)
     
         def _write_file(self, data):
    @@ -795,6 +796,9 @@ class Page:
                     os.remove(name)
                 except OSError, err:
                     if err.errno != errno.ENOENT: raise err
    +        path = os.path.split(name)[0]
    +        if not os.path.exists(path):
    +            os.makedirs(path)
             os.rename(tmp_filename, name)
     
         def save(self, newdata, changelog):