summaryrefslogtreecommitdiffstats
path: root/tools/export2.py
blob: bb7ad23ca6f656fdb53b5b250c2f04c325ba16e5 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
# encoding: utf-8

"""
Second attempt to make our export script more portable than export.sh
"""

import fileinput
from subprocess import Popen, PIPE
import sys

# py3k compatibility
try:
    from email.Utils import formatdate
except ImportError:
    from email.utils import formatdate

def run(command):
    return Popen(command, shell=True, stdout=PIPE).communicate()

def find_and_replace(f, iftest, rline, startswith=False):
    for line in fileinput.input(f, inplace=1):
        if startswith:
            if line.startswith(iftest):
                line = line.replace(line, rline)
            sys.stdout.write(line)
        else:
            if iftest in line and line != "Version: %{version}\n":
                line = line.replace(line, rline)
            sys.stdout.write(line)


if __name__ == '__main__':
    pkgname = 'bcfg2'
    ftphost = 'terra.mcs.anl.gov'
    ftpdir = '/mcs/ftp/pub/bcfg'
    
    # py3k compatibility
    try:
        version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ")
        name = raw_input("Your name: ")
        email = raw_input("Your email: ")
    except NameError:
        version = input("Please enter the version you are tagging (e.g. 1.0.0): ")
        name = input("Your name: ")
        email = input("Your email: ")
    
    # parse version into Major.Minor.Build and validate
    try:
        [version_major, version_minor, version_build] = version.split(".")
        if not version_major.isdigit() or not version_minor.isdigit():
            raise VersionError('isdigit() test failed')
    except:
        print "Version must be of the form Major.Minor.Build, where Major and Minor are integers and Build is a single digit optionally followed by pre##"
        quit()

    version_macbuild = version_build[0:1]
    
    tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version)
    
    # update the version
    majorver = version[:5]
    minorver = version[5:]

    newchangelog = \
    """bcfg2 (%s%s-0.0) unstable; urgency=low

      * New upstream release

     -- %s <%s>  %s

    """ % (majorver, minorver, name, email, formatdate(localtime=True))
    
    
    # write out the new debian changelog
    with open('debian/changelog', 'r+') as f:
        old = f.read()
        f.seek(0)
        f.write(newchangelog + old)
    f.close()
    quit()
    # Update redhat directory versions
    with open('redhat/VERSION', 'w') as f:
        f.write("%s\n" % majorver)
    f.close()
    with open('redhat/RELEASE', 'w') as f:
        f.write("0.0%s\n" % minorver)
    f.close()
    # update solaris version
    find_and_replace('solaris/Makefile', 'VERS=',
                     'VERS=%s-1\n' % version, startswith=True)
    find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=',
                     'VERSION="%s"\n' % version, startswith=True)
    find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=',
                     'VERSION="%s"\n' % version, startswith=True)
    # set new version in setup.py
    find_and_replace('setup.py', 'version=', '      version="%s",\n' % version)
    # replace version in misc/bcfg2.spec
    find_and_replace('misc/bcfg2.spec', 'Version:',
                     'Version:          %s\n' % version)
    # update the version in reports
    find_and_replace('src/lib/Server/Reports/reports/templates/base.html',
                     'Bcfg2 Version', '    <span>Bcfg2 Version %s</span>\n' % version)
    # update the version in the docs
    find_and_replace('doc/conf.py', 'version =',
                     'version = \'%s\'\n' % majorver[0:3], startswith=True)
    find_and_replace('doc/conf.py', 'release =',
                     'release = \'%s\'\n' % (majorver), startswith=True)

    # tag the release
    #FIXME: do this using python-dulwich
    cmd = "ggit commit -asm 'Version bump to %s'" % version
    output = run(cmd)[0].strip()
    # NOTE: This will use the default email address key. If you want to sign the tag
    #       using a different key, you will need to set 'signingkey' to the proper
    #       value in the [user] section of your git configuration.
    cmd = "ggit tag -s v%s -m 'tagged %s release'" % (version, version)
    output = run(cmd)[0].strip()
    cmd = "ggit archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \
           (pkgname, version, version, tarname)
    output = run(cmd)[0].strip()
    cmd = "gpg --armor --output %s.gpg --detach-sig  %s" % (tarname, tarname)
    output = run(cmd)[0].strip()

    # upload release to ftp
    cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname
    output = run(cmd)[0].strip()