Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (86 sloc) 3.775 kB
d95f25e @markrcote Bug 783585 Fix line endings. r=wlach
markrcote authored
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import datetime
6 import logging
7 import pytz
8 import re
9 import socket
10
11 import builds
12
13 def from_iso_date_or_datetime(s):
14 datefmt = '%Y-%m-%d'
15 datetimefmt = datefmt + 'T%H:%M:%S'
16 try:
17 d = datetime.datetime.strptime(s, datetimefmt)
18 except ValueError:
19 d = datetime.datetime.strptime(s, datefmt)
20 return d
21
22
23 def main(args, options):
24 logging.info('Looking for builds...')
25 if args[0] == 'latest':
26 commands = ['triggerjobs %s' %
27 builds.BuildCache().find_latest_build(options.branch)]
28 else:
29 if re.match('\d{14}', args[0]):
30 # build id
31 build_time = datetime.datetime.strptime(args[0], '%Y%m%d%H%M%S')
32 start_time = build_time
33 end_time = build_time
34 else:
35 start_time = from_iso_date_or_datetime(args[0])
36 if len(args) > 1:
37 end_time = from_iso_date_or_datetime(args[1])
38 else:
39 end_time = datetime.datetime.now()
40 if not start_time.tzinfo:
41 start_time = start_time.replace(tzinfo=pytz.timezone('US/Pacific'))
42 if not end_time.tzinfo:
43 end_time = end_time.replace(tzinfo=pytz.timezone('US/Pacific'))
44 commands = ['triggerjobs %s' % url for url in
45 builds.BuildCache().find_builds(start_time, end_time,
46 options.branch)]
47 logging.info('Connecting to autophone server...')
48 commands.append('exit')
49 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
50 s.connect((options.ip, options.port))
51 logging.info('- %s' % s.recv(1024).strip())
52 for c in commands:
53 logging.info('%s' % c)
54 s.sendall(c + '\n')
55 logging.info('- %s' % s.recv(1024).strip())
56 return 0
57
58
59 if __name__ == '__main__':
60 import errno
61 import sys
62 from optparse import OptionParser
63
64 logging.basicConfig(level=logging.INFO)
65
66 usage = '''%prog [options] <datetime, date/datetime, or date/datetime range>
67 Triggers one or more test runs.
68
69 The argument(s) should be one of the following:
70 - a build ID, e.g. 20120403063158
71 - a date/datetime, e.g. 2012-04-03 or 2012-04-03T06:31:58
72 - a date/datetime range, e.g. 2012-04-03T06:31:58 2012-04-05
73 - the string "latest"
74
75 If a build ID is given, a test run is initiated for that, and only that,
76 particular build.
77
78 If a single date or datetime is given, test runs are initiated for all builds
79 with build IDs between the given date/datetime and now.
80
81 If a date/datetime range is given, test runs are initiated for all builds
82 with build IDs in the given range.
83
84 If "latest" is given, test runs are initiated for the most recent build.'''
85 parser = OptionParser(usage=usage)
86 parser.add_option('-i', '--ip', action='store', type='string', dest='ip',
87 default='127.0.0.1',
88 help='IP address of autophone controller; defaults to localhost')
89 parser.add_option('-p', '--port', action='store', type='int', dest='port',
90 default=28001,
91 help='port of autophone controller; defaults to 28001')
92 parser.add_option('-b', '--branch', action='store', type='string',
93 dest='branch', default='nightly',
94 help='branch to search for builds, defaults to nightly;'
95 ' can be "tinderbox" for both m-c and m-i')
96 (options, args) = parser.parse_args()
97 if len(args) > 2:
98 parser.print_help()
99 sys.exit(errno.EINVAL)
100 sys.exit(main(args, options))
Something went wrong with that request. Please try again.