source: clientsplugin/trunk/cron/run-client-event

Last change on this file was 17214, checked in by Ryan J Ollos, 5 years ago

TracClients 0.5dev: Conform to PEP8

  • Property svn:executable set to *
File size: 3.4 KB
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
31import sys
32import locale
33from optparse import OptionParser
34
35from trac.env import open_environment
36
37parser = OptionParser()
38depr = '(not used anymore)'
39parser.add_option('-e', '--env', dest='envpath',
40                  help='Required. Path to the Trac environment.')
41parser.add_option('-c', '--event', dest='event',
42                  help='The client event to run (required)')
43# parser.add_option('-d', action='store_true', dest='debug',
44#                  help='Turn on debug mode - does not update database '
45#                       'and prints verbose messages.')
46# parser.add_option('-m', '--mail', dest='mail',
47#                  help='Email override. Useful in combination with -d.')
48# parser.set_defaults(period='daily', mailtype='summary')
49(options, args) = parser.parse_args(sys.argv[1:])
50
51
52class SendClientFakeReq:
53    def __init__(self):
54        class SendClientFakeHref:
55            def __call__(self, *args, **keywords):
56                return ''
57
58            def wiki(self, *args, **keywords):
59                return ''
60
61            def ticket(self, num):
62                return '#%d' % (num)
63
64        self.href = SendClientFakeHref()
65        self.abs_href = SendClientFakeHref()
66        self.perm = []
67
68    def __call__(self, *args, **keywords):
69        return ''
70
71    def perm(self, *args, **keywords):
72        return []
73
74
75class RunClientEvents:
76    def __init__(self):
77        locale.setlocale(locale.LC_ALL, '')
78        self.env = open_environment(options.envpath)
79        self.req = SendClientFakeReq()
80
81        # Sync the repo so that any commits that happen to have been made
82        # that include client comments are included.
83        repos = self.env.get_repository()
84        repos.sync()
85
86        from clients.events import ClientEvent
87        ClientEvent.triggerall(self.env, self.req, options.event)
88
89
90if __name__ == '__main__':
91    if not options.envpath or not options.event:
92        print "For usage: %s --help" % (sys.argv[0])
93    else:
94        RunClientEvents()
Note: See TracBrowser for help on using the repository browser.