root/clientsplugin/0.11/cron/run-client-event

Revision 4480, 3.5 kB (checked in by coling, 3 months ago)

Add a runner script to trigger via cron

  • Property svn:mergeinfo set to
  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 # run-client-event
4 # ----------------------------------------------------------------------------
5 # Copyright (c) 2008 Colin Guthrie
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to
9 # deal in the Software without restriction, including without limitation the
10 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 # sell copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 #   The above copyright notice and this permission notice shall be included in
15 #   all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24 # ----------------------------------------------------------------------------
25
26 # This email integration script is meant to interface to the Trac
27 # (http://www.edgewall.com/products/trac/) issue tracking/wiki/etc
28 # system
29
30
31 import os
32 import sys
33 import locale
34 import time
35 from optparse import OptionParser
36 from StringIO import StringIO
37
38 from trac import __version__
39 from trac.core import *
40 from trac.env import open_environment
41 from trac.util.datefmt import format_date, to_datetime
42 from trac.wiki import wiki_to_html
43 from genshi import escape
44
45
46 parser = OptionParser()
47 depr = '(not used anymore)'
48 parser.add_option('-e', '--env', dest='envpath',
49                   help='Required. Path to the Trac environment.')
50 parser.add_option('-c', '--event', dest='event',
51                   help='The client event to run (required)')
52 #parser.add_option('-d', action='store_true', dest='debug',
53 #                  help='Turn on debug mode - does not update database and prints verbose messages.')
54 #parser.add_option('-m', '--mail', dest='mail',
55 #                  help='Email override. Useful in combination with -d.')
56 #parser.set_defaults(period='daily', mailtype='summary')
57 (options, args) = parser.parse_args(sys.argv[1:])
58
59
60 class SendClientFakeReq:
61   def __init__(self):
62     class SendClientFakeHref:
63       def __call__(self, *args, **keywords):
64         return ''
65       def wiki(self, *args, **keywords):
66         return ''
67       def ticket(self, num):
68         return '#%d' % (num)
69     self.href = SendClientFakeHref()
70     self.abs_href = SendClientFakeHref()
71     self.perm = []
72  
73   def __call__(self, *args, **keywords):
74     return ''
75   def perm(self, *args, **keywords):
76     return []
77
78 class RunClientEvents:
79
80     def __init__(self):
81         locale.setlocale(locale.LC_ALL, '')
82         self.env = open_environment(options.envpath)
83         self.req = SendClientFakeReq()
84
85         # Sync the repo so that any commits that happen to have been made
86         # that include client comments are included.
87         repos = self.env.get_repository()
88         repos.sync()
89
90         from clients.events import ClientEvent
91         ClientEvent.triggerall(self.env, self.req, options.event)
92  
93 if __name__ == "__main__":
94     if not options.envpath or not options.event:
95         print "For usage: %s --help" % (sys.argv[0])
96     else:
97         RunClientEvents()
Note: See TracBrowser for help on using the browser.