Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 114 lines (97 sloc) 4.236 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':
d1e02c5 @bclary Bug 785086 - Add ability to download unit test prerequisites and to r…
bclary authored
26 cache_build_dir = builds.BuildCache().find_latest_build(options.branch)
27 if not cache_build_dir:
56f5c82 @markrcote Bug 783585 Improve latest-build downloader and handle build errors in…
markrcote authored
28 return 1
d1e02c5 @bclary Bug 785086 - Add ability to download unit test prerequisites and to r…
bclary authored
29 commands = ['triggerjobs %s' % cache_build_dir]
d95f25e @markrcote Bug 783585 Fix line endings. r=wlach
markrcote authored
30 else:
31 if re.match('\d{14}', args[0]):
32 # build id
33 build_time = datetime.datetime.strptime(args[0], '%Y%m%d%H%M%S')
34 start_time = build_time
35 end_time = build_time
36 else:
37 start_time = from_iso_date_or_datetime(args[0])
38 if len(args) > 1:
39 end_time = from_iso_date_or_datetime(args[1])
40 else:
41 end_time = datetime.datetime.now()
42 if not start_time.tzinfo:
43 start_time = start_time.replace(tzinfo=pytz.timezone('US/Pacific'))
44 if not end_time.tzinfo:
45 end_time = end_time.replace(tzinfo=pytz.timezone('US/Pacific'))
d1e02c5 @bclary Bug 785086 - Add ability to download unit test prerequisites and to r…
bclary authored
46 cache_build_dir_list = builds.BuildCache().find_builds(start_time, end_time,
47 options.branch)
48 if not cache_build_dir_list:
56f5c82 @markrcote Bug 783585 Improve latest-build downloader and handle build errors in…
markrcote authored
49 return 1
d1e02c5 @bclary Bug 785086 - Add ability to download unit test prerequisites and to r…
bclary authored
50 commands = ['triggerjobs %s' % cache_build_dir for cache_build_dir in
51 cache_build_dir_list]
d95f25e @markrcote Bug 783585 Fix line endings. r=wlach
markrcote authored
52 logging.info('Connecting to autophone server...')
53 commands.append('exit')
54 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
55 s.connect((options.ip, options.port))
56 logging.info('- %s' % s.recv(1024).strip())
57 for c in commands:
58 logging.info('%s' % c)
59 s.sendall(c + '\n')
60 logging.info('- %s' % s.recv(1024).strip())
61 return 0
62
63
64 if __name__ == '__main__':
65 import errno
66 import sys
67 from optparse import OptionParser
68
69 usage = '''%prog [options] <datetime, date/datetime, or date/datetime range>
70 Triggers one or more test runs.
71
72 The argument(s) should be one of the following:
73 - a build ID, e.g. 20120403063158
74 - a date/datetime, e.g. 2012-04-03 or 2012-04-03T06:31:58
75 - a date/datetime range, e.g. 2012-04-03T06:31:58 2012-04-05
76 - the string "latest"
77
78 If a build ID is given, a test run is initiated for that, and only that,
79 particular build.
80
81 If a single date or datetime is given, test runs are initiated for all builds
82 with build IDs between the given date/datetime and now.
83
84 If a date/datetime range is given, test runs are initiated for all builds
85 with build IDs in the given range.
86
87 If "latest" is given, test runs are initiated for the most recent build.'''
88 parser = OptionParser(usage=usage)
89 parser.add_option('-i', '--ip', action='store', type='string', dest='ip',
90 default='127.0.0.1',
91 help='IP address of autophone controller; defaults to localhost')
92 parser.add_option('-p', '--port', action='store', type='int', dest='port',
93 default=28001,
94 help='port of autophone controller; defaults to 28001')
95 parser.add_option('-b', '--branch', action='store', type='string',
96 dest='branch', default='nightly',
97 help='branch to search for builds, defaults to nightly;'
98 ' can be "tinderbox" for both m-c and m-i')
6464449 @markrcote Bug 818188 - Fix ftp-directory-name generation. r=bc
markrcote authored
99 parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
100 default=False, help='verbose output')
d95f25e @markrcote Bug 783585 Fix line endings. r=wlach
markrcote authored
101 (options, args) = parser.parse_args()
102 if len(args) > 2:
103 parser.print_help()
104 sys.exit(errno.EINVAL)
6464449 @markrcote Bug 818188 - Fix ftp-directory-name generation. r=bc
markrcote authored
105
106 if options.verbose:
107 log_level = logging.DEBUG
108 else:
109 log_level = logging.INFO
110
111 logging.basicConfig(level=log_level)
112
d95f25e @markrcote Bug 783585 Fix line endings. r=wlach
markrcote authored
113 sys.exit(main(args, options))
Something went wrong with that request. Please try again.