summaryrefslogtreecommitdiff
path: root/gen_tests.py
blob: 085f94da9cd0b26457df2d2f666e444c69809324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: ascii -*-
'''
$Id: gen_tests.py,v 1.15 2005/01/07 04:51:30 zenzen Exp $
'''

import os, os.path, re, subprocess, sys
from gen_tzinfo import allzones
import gen_tzinfo
from time import strptime
from datetime import datetime, timedelta

zdump = os.path.abspath(os.path.join(
        os.path.dirname(__file__), 'build','etc','zdump'
        ))

def main():
    dest_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))

    datf = open(os.path.join(dest_dir, 'zdump.out'), 'w')

    for zone in allzones():
        print 'Collecting zdump(1) output for %s in zdump.out' % (zone,)
        tname = zone.replace(
                '+', '_plus_').replace('-', '_minus_').replace('/','_')
        # We don't yet support v2 format tzfile(5) files, so limit
        # the daterange we test against - zdump understands v2 format
        # files and will output historical records we can't cope with
        # otherwise.
        command = '%s -v -c 1902,2038 %s' % (zdump, zone)
        process = subprocess.Popen(
            command, shell=True,
            stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
        zd_in, zd_out = (process.stdin, process.stdout)
        # Skip bogus output on 64bit architectures, per Bug #213816
        lines = [
            line.strip() for line in zd_out.readlines()
            if not line.decode('utf-8').strip().endswith('NULL')]

        for line in lines:
            print >> datf, line
    datf.flush()
    datf.close()

if __name__ == '__main__':
    try:
        gen_tzinfo.target = sys.argv[1:]
    except IndexError:
        gen_tzinfo.target = None
    main()

# vim: set filetype=python ts=4 sw=4 et