#!/usr/bin/env python2
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import os, sys, re

SourceDir = "duplicity"
specfile = "duplicity.spec"

if len(sys.argv) == 2: version = sys.argv[1]
else:
    print "Syntax:  %s version_number" % sys.argv[0]
    sys.exit(1)

base = "duplicity-%s" % (version,)
fedora_release = 6
i386rpm = "%s-0.fdr.%d.i386.rpm" % (base, fedora_release)
source_rpm = "%s-0.fdr.%d.src.rpm" % (base, fedora_release)
tarfile = base + ".tar.gz"

# These assume the rpm root directory $HOME/rpmbuild.  The
# nonstandard location allows for building by non-root user.
assert not os.system("cp %s $HOME/rpmbuild/SOURCES/" % (tarfile,))
assert not os.system("rpmbuild -ba -vv --target i386 " + specfile)
assert not os.system("cp $HOME/rpmbuild/RPMS/i386/%s ." % i386rpm)
assert not os.system("cp $HOME/rpmbuild/SRPMS/%s ." % source_rpm)

# Old root RPM instructions
#assert not os.system("install -o root -g root -m 644 %s "
#                    "/usr/src/redhat/SOURCES" % (tarfile,))
#assert not os.system("install -o ben -g ben -m 644 "
#                    "/usr/src/redhat/RPMS/i386/%s ." % i386rpm)
#assert not os.system("install -o ben -g ben -m 644 "
#                    "/usr/src/redhat/SRPMS/%s ." % source_rpm)
