summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRaul Cuza <raulcuza@gmail.com>2011-07-05 16:31:36 -0400
committerRaul Cuza <raulcuza@gmail.com>2011-07-06 13:38:00 -0400
commitd2dfb778793bcf635de64f388b96da595f55740a (patch)
tree49563d85a423839b37a1742fd88097d75ead8b79 /tools
parent6a6032322a823eb7bcd4cdd8a08b177d99e74709 (diff)
downloadbcfg2-d2dfb778793bcf635de64f388b96da595f55740a.tar.gz
bcfg2-d2dfb778793bcf635de64f388b96da595f55740a.tar.bz2
bcfg2-d2dfb778793bcf635de64f388b96da595f55740a.zip
Extend dry-run mode to file replacement
Diffstat (limited to 'tools')
-rwxr-xr-xtools/export2.py54
1 files changed, 35 insertions, 19 deletions
diff --git a/tools/export2.py b/tools/export2.py
index 886db0cf0..25ac8335e 100755
--- a/tools/export2.py
+++ b/tools/export2.py
@@ -33,8 +33,13 @@ ftpdir = '/mcs/ftp/pub/bcfg'
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):
+def find_and_replace(f, iftest, rline, startswith=False, dryrun=True):
+ if dryrun:
+ inplace=0
+ print "*** dry-run: New '%s' will look like this:" % f
+ else:
+ inplace=1
+ for line in fileinput.input(f, inplace):
if startswith:
if line.startswith(iftest):
line = line.replace(line, rline)
@@ -43,6 +48,8 @@ def find_and_replace(f, iftest, rline, startswith=False):
if iftest in line and line != "Version: %{version}\n":
line = line.replace(line, rline)
sys.stdout.write(line)
+ if dryrun:
+ print "*** End '%s'" % f
def main(argv=None):
# This is where the options are set up
@@ -108,24 +115,33 @@ def main(argv=None):
# write out the new debian changelog
- try:
- with open('debian/changelog', 'r+') as f:
- old = f.read()
- f.seek(0)
- f.write(newchangelog + old)
- f.close()
- except:
- print "Problem opening debian/changelog"
- print help_message
- quit()
+ if options.dryrun:
+ print "*** Add the following to the top of debian/changelog:\n%s" % newchangelog
+ print "\n"
+ else:
+ try:
+ with open('debian/changelog', 'r+') as f:
+ old = f.read()
+ f.seek(0)
+ f.write(newchangelog + old)
+ f.close()
+ except:
+ print "Problem opening debian/changelog"
+ print help_message
+ 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()
+ if options.dryrun:
+ print "*** Replace redhat/VERIONS content with '%s'." % majorver
+ print "*** Replace redhat/RELEASE content with '%s'." % minorver
+ else:
+ 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)
@@ -170,7 +186,7 @@ def main(argv=None):
commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"]
if options.dryrun:
for cmd in commando_orders:
- print "dry-run: %s" % commando[cmd]
+ print "*** dry-run: %s" % commando[cmd]
else:
for cmd in commando_orders:
output = run(commando[cmd])[0].strip()