Edgewall Software

root/trunk/sample-plugins/Timestamp.py

Revision 6326, 1.1 KB (checked in by cboos, 19 months ago)

Follow-up to r6295: make the file revision string information global to the module.

Also enhances the plugins admin panel so that it can show that information.

  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedRevision HeadURL
Line 
1"""Inserts the current time (in seconds) into the wiki page."""
2
3revision = "$Rev$"
4url = "$URL$"
5
6#
7# The following shows the code for macro, old-style.
8#
9# The `execute` function serves no purpose other than to illustrate
10# the example, it will not be used anymore.
11#
12# ---- (ignore in your own macro) ----
13# --
14import time # Trac before version 0.11 was using `time` module
15
16def execute(hdf, txt, env):
17    t = time.localtime()
18    return "<b>%s</b>" % time.strftime('%c', t)
19# --
20# ---- (ignore in your own macro) ----
21
22
23#
24# The following is the converted new-style macro
25#
26# ---- (reuse for your own macro) ----
27# --
28from datetime import datetime
29# Note: since Trac 0.11, datetime objects are used internally
30
31from genshi.builder import tag
32
33from trac.util.datefmt import format_datetime, utc
34from trac.wiki.macros import WikiMacroBase
35
36class TimestampMacro(WikiMacroBase):
37    """Inserts the current time (in seconds) into the wiki page."""
38
39    def expand_macro(self, formatter, name, args):
40        t = datetime.now(utc)
41        return tag.b(format_datetime(t, '%c'))
42# --
43# ---- (reuse for your own macro) ----
Note: See TracBrowser for help on using the browser.