Merge lp:~mayankjuneja/systers/product-release-systers into lp:~systers-dev/systers/product-release-systers

Proposed by Mayank Juneja
Status: Superseded
Proposed branch: lp:~mayankjuneja/systers/product-release-systers
Merge into: lp:~systers-dev/systers/product-release-systers
Diff against target: 542 lines (+270/-182)
4 files modified
applypatch.py (+78/-0)
createpatch.py (+80/-153)
prodpatch-new.py (+68/-0)
prodpatch.py (+44/-29)
To merge this branch: bzr merge lp:~mayankjuneja/systers/product-release-systers
Reviewer Review Type Date Requested Status
Emanuel Danci Pending
Sneha Priscilla Pending
Robin J Pending
Ana Cutillas Pending
Jennifer Redman Pending
Systers-Dev Pending
Review via email: mp+113920@code.launchpad.net

Description of the change

- Modified script for pulling code to production server.
- Scripts for creating and applying systers patch.

To post a comment you must log in.
12. By Mayank Juneja

New version of prodpatch (doesn't take step number as input)

13. By Mayank Juneja

Minor changes based on Code review

14. By root <email address hidden>

Added patch file

Unmerged revisions

14. By root <email address hidden>

Added patch file

13. By Mayank Juneja

Minor changes based on Code review

12. By Mayank Juneja

New version of prodpatch (doesn't take step number as input)

11. By Mayank Juneja

- Fixes in createpatch
- Added script for applying patch

10. By Mayank Juneja

Minor

9. By Mayank Juneja

Rewrote createpatch.py

8. By Mayank Juneja

Changes to prodpatch.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'applypatch.py'
--- applypatch.py 1970-01-01 00:00:00 +0000
+++ applypatch.py 2012-07-12 06:27:20 +0000
@@ -0,0 +1,78 @@
1#!/usr/bin/python -- tested on Python 2.5+ only
2# coding: utf-8
3'''
4"applypatch.py" is the python program used to apply a mailman patch.
5LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
6USAGE: python applypatch.py
7'''
8
9# Python modules
10import sys
11import os
12import os.path
13import subprocess
14from optparse import OptionParser
15
16# Adding Parser for command line options
17Parser = OptionParser()
18Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
19 help="Mailman source directory path", metavar="PATH")
20Parser.add_option("-p", "--patch-path", dest="patch_path",
21 help="Patch path", metavar="PATH")
22Parser.add_option("--dry-run", action="store_true", dest="dry_run",
23 help="Do not actually change any files; just print what would happen.")
24
25(options, args) = Parser.parse_args()
26
27if(options.mailman_dir is None):
28 print "\nerror: Mailman directory path is missing"
29 print "Try `./applypatch.py --help' for more information."
30 sys.exit()
31
32if(options.patch_path is None):
33 print "\nerror: Patch path is missing"
34 print "Try `./applypatch.py --help' for more information."
35 sys.exit()
36
37# Get the paths
38mailman_dir = os.path.abspath(options.mailman_dir)
39patch_path = os.path.abspath(options.patch_path)
40dry_run = options.dry_run
41current_dir = os.getcwd()
42
43# Open log file
44log_file = open('log-applypatch.txt', 'w')
45
46dry_run_arg = ""
47if(dry_run):
48 dry_run_arg = "--dry-run"
49
50# Commands list, along with the description
51commands_list = [
52["patch %s -p0 < %s" % (dry_run_arg, patch_path) , "Applying patch"]
53]
54
55# Change the current working directory to mailman source directory
56os.chdir(mailman_dir)
57
58#Execute the commands
59for i in range(len(commands_list)):
60 cmd = commands_list[i][0]
61 desc = commands_list[i][1]
62 try:
63 print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
64
65 retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
66 if retcode < 0:
67 print "...FAIL:", -retcode
68 sys.exit()
69 else:
70 print "...OK"
71 except OSError, e:
72 print "...ERROR: ", e
73
74# Change the current working directory
75os.chdir(current_dir)
76
77# Close the log file
78log_file.close()
079
=== modified file 'createpatch.py'
--- createpatch.py 2010-08-15 10:14:18 +0000
+++ createpatch.py 2012-07-12 06:27:20 +0000
@@ -2,163 +2,90 @@
2# coding: utf-8 2# coding: utf-8
3'''3'''
4"createpatch.py" is the python program used used to create a mailman patch. 4"createpatch.py" is the python program used used to create a mailman patch.
5LICENSE: Copyright(C)2010, Vidya [svaksha] Ayer <vid@svaksha.com>, GPLv3. 5LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
6https://code.launchpad.net/~systers-dev/systers/product-release-systers6USAGE: python createpatch.py
7http://systers.org/systers-dev/doku.php/how_to_create_a_patch
8
9USAGE: python createpatch.py (While the execution feedback will be displayed
10on the terminal, its output is also logged in the "log-createpatch.txt" file.
11'''7'''
128
13#python modules9#python modules
14import sys10import sys
15import os11import os
16import os.path12import os.path
17import popen2
18import shlex
19import string
20import time
21import commands
22import datetime
23import subprocess13import subprocess
24from glob import glob14from optparse import OptionParser
2515
26#python path.16# Adding Parser for command line options
27filepath, filename = os.path.split(os.path.abspath(os.path.dirname(__file__)))17Parser = OptionParser()
28sys.path.append(filepath)18Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
29sys.path.append("/usr/lib/python2.5/")19 help="Mailman source directory path", metavar="PATH")
30sys.path.append("/usr/lib/python2.5/sitepackages/bzrlib/")20Parser.add_option("-s", "--systers-dir", dest="systers_dir",
31sys.path.append("/usr/share/pyshared/bzrlib/")21 help="Systers source directory path", metavar="PATH")
3222
33#print $user 23(options, args) = Parser.parse_args()
34user = os.environ['USER']24
35print '\n User:', user25if(options.mailman_dir is None):
36startTime = datetime.datetime.now()26 print "\nerror: Mailman directory path is missing"
37print '\nThe starting date, time is:', str(startTime)27 print "Try `./createpatch.py --help' for more information."
3828 sys.exit()
39#logging to file and scr.29
40sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)30if(options.systers_dir is None):
41tee = subprocess.Popen(["tee", "log-createpatch.txt"], stdin=subprocess.PIPE)31 print "\nerror: Systers directory path is missing"
42os.dup2(tee.stdin.fileno(), sys.stdout.fileno())32 print "Try `./createpatch.py --help' for more information."
43os.dup2(tee.stdin.fileno(), sys.stderr.fileno())33 sys.exit()
4434
45#Terminal user input35# Get the paths
46print "\nThis script automates the patch creation process for these steps: \36mailman_dir = os.path.abspath(options.mailman_dir)
47 \n001. Make a patch with 2 files \37systers_dir = os.path.abspath(options.systers_dir)
48 \n002. Patch with a directory of files \38current_dir = os.getcwd()
49 \n003. Dry run before applying the patch \39patch_path = current_dir + "/systers.patch"
50 \n004. Apply the patch only when there are no errors. "40tmp_dir = os.path.abspath("/tmp/systers-patch/")
51print "\nEnter a step number [Ex. 001, to start from step one]:"41
5242# Open log file
53#******************************************************************************43log_file = open('log-createpatch.txt', 'w')
54#CREATE A PATCH steps are based on this write-up:44
55#http://systers.org/systers-dev/doku.php/how_to_create_a_patch45# Commands list, along with the description
56#******************************************************************************46commands_list = [
57#ask user to input starting step number.47["\cp -rf %s/* %s" % (mailman_dir,tmp_dir) , "Copying mailman source"],
58InpStpNo = int(input()) 48["bzr init ." , "Creating bzr repo"],
59print "\nStarting step number is: %d" % InpStpNo 49["bzr add ." , "Adding mailman files to repo"],
60print "\nBatch job begins for: Creating a Patch."50["bzr commit -m 'Init'" , "Initial commit"],
6151["\cp -rf %s/* %s" % (systers_dir, tmp_dir), "Copying systers source"],
62#1.Make a patch with 2 files (this works on most Linux distros):52["bzr add ." , "Adding systers files to repo"],
63#*****************************************************************************53["bzr diff > %s" % (patch_path) , "Generating patch"],
64#if start from step154["rm -rf %s" % (tmp_dir) , "Cleaning up temporary files"]
65if int('001') >= InpStpNo:55]
66 try:56
67 #ask user input for file path.57
68 print "\nEnter 'oldfile' path (ex. '/home/path/olddir/oldfile' : "58# Create the temp directory
69 oldfile = str(input())59try:
70 print "\nEnter 'newfile' path (ex. '/home/path/newdir/newfile' : "60 retcode = subprocess.call([ "mkdir %s" %(tmp_dir) ], shell=True)
71 newfile = str(input())61 if retcode < 0:
72 retcode = subprocess.call(["diff -u %s %s > file.patch" % (oldfile, newfile)], shell=True)62 print "FAIL:", -retcode
73 print "\nExecuting, diff -u %s %s > file.patch" 63 sys.exit()
74 if retcode < 0:64
75 #if diff fails65except OSError, e:
76 print >>sys.stderr, "\nFAIL: step 001 (Cannot create a patch with two files)", -retcode66 print "ERROR: ", e
77 sys.exit()67
78 else:68# Change the current working directory to temp directory
79 #create patch for 2 files.69os.chdir(tmp_dir)
80 print >>sys.stderr, "\nPASS: step001-Created a patch with 2 files. END 001, OK", retcode70
81 except OSError, e:71#Execute the commands
82 print >>sys.stderr, "\nERROR: step 001", e72for i in range(len(commands_list)):
83else:73 cmd = commands_list[i][0]
84 pass 74 desc = commands_list[i][1]
8575 try:
8676 print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
87#2.Creating a patch with a directory of files77
88#*****************************************************************************78 retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
89#if start from step2.79 if retcode < 0:
90if int('002') >= InpStpNo and int('001') != InpStpNo:80 print "...FAIL:", -retcode
91 try:81 sys.exit()
92 #user input for folder/directory path.82 else:
93 print "\nEnter 'oldDirectory' path name (Ex. '/home/path/olddir/' :"83 print "...OK"
94 olddir = str(input()) 84 except OSError, e:
95 print "\nEnter 'newDirectory' path name (Ex. '/home/path/newdir/' :"85 print "...ERROR: ", e
96 newdir = str(input()) 86
97 retcode = subprocess.call(["diff -Naur %s %s > file.patch" % (olddir, newdir)], shell=True)87# Change the current working directory
98 print "\nExecuting, diff -Naur %s %s > file.patch" 88os.chdir(current_dir)
99 if retcode < 0:89
100 #if diff of 'old-new' files fail90# Close the log file
101 print >>sys.stderr, "FAIL: step002-Cannot create a patch with a directory of files:", -retcode91log_file.close()
102 sys.exit()
103 else:
104 #create patch for 2 directory's.
105 print >>sys.stderr, "PASS: step002-Created a patch with a directory of files. END 002, OK.", retcode
106 except OSError, e:
107 print >>sys.stderr, "ERROR: step 002", e
108else:
109 pass
110
111
112#3.Dry run before applying the patch:
113#*****************************************************************************
114#if start from step3.
115if int('003') >= InpStpNo:
116 try:
117 #execute dry run.
118 retcode = subprocess.call(["patch -p0 --dry-run < file.patch"], shell=True)
119 print "\nExecuting, patch -p0 --dry-run < file.patch"
120 if retcode < 0:
121 #dry run fails
122 print >>sys.stderr, "FAIL: step003-Dry run failed.", -retcode
123 sys.exit()
124 else:
125 #dry run OK.
126 print >>sys.stderr, "PASS: step003-Dry run to check for errors successful. END 003, OK", retcode
127 except OSError, e:
128 print >>sys.stderr, "ERROR: step 003, Dry run.", e
129else:
130 pass
131
132#4.apply the patch only when there are no error
133#*****************************************************************************
134#if start from step4
135if int('004') >= InpStpNo:
136 try:
137 #applying the patch
138 retcode = subprocess.call(["patch -p0 < file.patch"], shell=True)
139 print "\nExecuting, patch -p0 --dry-run < file.patch"
140 if retcode < 0:
141 #Fail to apply patch
142 print >>sys.stderr, "FAIL: step004, Cannot apply patch.", -retcode
143 sys.exit()
144 else:
145 #Patch applied successfully.
146 print >>sys.stderr, "PASS: step004, Application of patch successful. END 004, OK.", retcode
147 print '\nStatus: Patches applied, OK.'
148 except OSError, e:
149 print >>sys.stderr, "ERROR: step 004, Dry run.", e
150else:
151 pass
152
153#Printing Completion and difference TIME.
154#*****************************************************************************
155endTime = datetime.datetime.now()
156print "\nEnding Time for the program 'createpatch.py' is: ", str(endTime)
157timedelta = endTime - startTime
158
159#Printing total system installation time taken by 'createpatch.py'.
160#*****************************************************************************
161installationTime = timedelta
162print "\nTotal time taken by 'createpatch.py': ", installationTime
163
164
16592
=== added file 'prodpatch-new.py'
--- prodpatch-new.py 1970-01-01 00:00:00 +0000
+++ prodpatch-new.py 2012-07-12 06:27:20 +0000
@@ -0,0 +1,68 @@
1#!/usr/bin/python -- tested on Python 2.5+ only
2# coding: utf-8
3'''
4"prodpatch.py" is the python program used used to create a mailman patch.
5LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
6USAGE: python prodpatch.py
7'''
8
9#python modules
10import sys
11import os
12import os.path
13import subprocess
14from optparse import OptionParser
15
16# Adding Parser for command line options
17Parser = OptionParser()
18Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
19 help="Mailman source directory path", metavar="PATH")
20
21(options, args) = Parser.parse_args()
22
23if(options.mailman_dir is None):
24 print "\nerror: Mailman directory path is missing"
25 print "Try `./prodpatch.py --help' for more information."
26 sys.exit()
27
28
29# Get the paths
30mailman_dir = os.path.abspath(options.mailman_dir)
31current_dir = os.getcwd()
32
33# Open log file
34log_file = open('log-prodpatch.txt', 'w')
35
36# Commands list, along with the description
37commands_list = [
38["sudo /etc/init.d/mailman stop" , "Stop mailman"],
39["sudo bzr update" , "Update repo with new release"],
40["bzr conflicts" , "Resolve conflicts"],
41["bzr resolve -all" , "Clear bzr status log"],
42["sudo /etc/init.d/mailman start", "Start mailman"]
43]
44
45# Change the current working directory to temp directory
46os.chdir(mailman_dir)
47
48#Execute the commands
49for i in range(len(commands_list)):
50 cmd = commands_list[i][0]
51 desc = commands_list[i][1]
52 try:
53 print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
54
55 retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
56 if retcode < 0:
57 print "...FAIL:", -retcode
58 sys.exit()
59 else:
60 print "...OK"
61 except OSError, e:
62 print "...ERROR: ", e
63
64# Change the current working directory
65os.chdir(current_dir)
66
67# Close the log file
68log_file.close()
069
=== modified file 'prodpatch.py'
--- prodpatch.py 2010-08-15 10:14:18 +0000
+++ prodpatch.py 2012-07-12 06:27:20 +0000
@@ -1,8 +1,9 @@
1#!/usr/bin/python - Python 2.5+ only1#!/usr/bin/python - Python 2.5+ only
2# coding: utf-8 2# coding: utf-8
3'''3'''
4"prodpatch.py" is a python program used to Pull a New Release to the 4"prodpatch.py" is a python program used to Pull a New Release to the production server
5LICENSE: Copyright(C)2010, Vidya [svaksha] Ayer <vid@svaksha.com>, GPLv3. 5LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
6(Original code by Vidya [svaksha] Ayer <vid@svaksha.com>)
6http://systers.org/systers-dev/doku.php/how_to_pull_a_new_release_to_the_production_server7http://systers.org/systers-dev/doku.php/how_to_pull_a_new_release_to_the_production_server
7https://code.launchpad.net/~systers-dev/systers/product-release-systers8https://code.launchpad.net/~systers-dev/systers/product-release-systers
89
@@ -14,11 +15,6 @@
14import sys15import sys
15import os16import os
16import os.path17import os.path
17import popen2
18import shlex
19import string
20import time
21import commands
22import datetime18import datetime
23import subprocess19import subprocess
2420
@@ -48,8 +44,12 @@
48#******************************************************************************44#******************************************************************************
4945
50#Terminal user input46#Terminal user input
51print "\nEnter the step number [Ex. 001, to start from step one]:"47try:
52InpStpNo = int(input()) 48 InpStpNo = int(raw_input("\nEnter the step number [Ex. 001, to start from step one]: "))
49except ValueError, e:
50 print >> sys.stderr, e
51 sys.exit()
52
53print "\nStarting step number is: %d" % InpStpNo 53print "\nStarting step number is: %d" % InpStpNo
54print "\nBatch job begins for: Production Patch."54print "\nBatch job begins for: Production Patch."
5555
@@ -62,14 +62,13 @@
62 retcode = subprocess.call(["sudo /etc/init.d/mailman stop"], shell=True)62 retcode = subprocess.call(["sudo /etc/init.d/mailman stop"], shell=True)
63 print "\nExecuting, sudo /etc/init.d/mailman stop" 63 print "\nExecuting, sudo /etc/init.d/mailman stop"
64 if retcode < 0: 64 if retcode < 0:
65 print >>sys.stderr, "\nFAIL: Attempt to stop Mailman failed at step001.", -retcode65 print >> sys.stderr, "\nFAIL: Attempt to stop Mailman failed at step001.", -retcode
66 sys.exit()66 sys.exit()
67 else:67 else:
68 print >>sys.stderr, "\nPASS: Stopped Mailman to merge updates. Status: step001, OK.", retcode68 print >> sys.stderr, "\nPASS: Stopped Mailman to merge updates. Status: step001, OK.", retcode
69 except OSError, e:69 except OSError, e:
70 print >>sys.stderr, "\nERROR: step001. Cannot stop Mailman", e70 print >> sys.stderr, "\nERROR: step001. Cannot stop Mailman", e
71else:71 sys.exit()
72 pass
7372
74#2.Update server with new release.73#2.Update server with new release.
75#******************************************************************************74#******************************************************************************
@@ -79,14 +78,13 @@
79 retcode = subprocess.call(["sudo bzr update"], shell=True)78 retcode = subprocess.call(["sudo bzr update"], shell=True)
80 print "\nExecuting, sudo bzr update" 79 print "\nExecuting, sudo bzr update"
81 if retcode < 0:80 if retcode < 0:
82 print >>sys.stderr, "\nFAIL: Attempt to update from server", -retcode81 print >> sys.stderr, "\nFAIL: Attempt to update from server", -retcode
83 sys.exit()82 sys.exit()
84 else:83 else:
85 print >>sys.stderr, "\nPASS: Updated Mailman. Status: Step002 OK.", retcode84 print >> sys.stderr, "\nPASS: Updated Mailman. Status: Step002 OK.", retcode
86 except OSError, e:85 except OSError, e:
87 print >>sys.stderr, "\nERROR: Server Update.", e86 print >> sys.stderr, "\nERROR: Server Update.", e
88else:87 sys.exit()
89 pass
9088
9189
92#3.Resolve any conflicts.90#3.Resolve any conflicts.
@@ -97,14 +95,13 @@
97 retcode = subprocess.call(["bzr conflicts"], shell=True)95 retcode = subprocess.call(["bzr conflicts"], shell=True)
98 print "\nExecuting, bzr conflicts" 96 print "\nExecuting, bzr conflicts"
99 if retcode < 0:97 if retcode < 0:
100 print >>sys.stderr, "\nFAIL: A conflict was detected during the Update.", -retcode98 print >> sys.stderr, "\nFAIL: A conflict was detected during the Update.", -retcode
101 sys.exit()99 sys.exit()
102 else:100 else:
103 print >>sys.stderr, "\nPASS: Resolved all conflicts in Mailman Update, Status: Step003, OK.", retcode101 print >> sys.stderr, "\nPASS: Resolved all conflicts in Mailman Update, Status: Step003, OK.", retcode
104 except OSError, e:102 except OSError, e:
105 print >>sys.stderr, "\nERROR: Could not resolve conflict in update.", e103 print >> sys.stderr, "\nERROR: Could not resolve conflict in update.", e
106else:104 sys.exit()
107 pass
108105
109#4.Clear BZR status log.106#4.Clear BZR status log.
110#******************************************************************************107#******************************************************************************
@@ -114,15 +111,33 @@
114 retcode = subprocess.call(["bzr resolve --all"], shell=True)111 retcode = subprocess.call(["bzr resolve --all"], shell=True)
115 print "Executing command, bzr resolve --all" 112 print "Executing command, bzr resolve --all"
116 if retcode < 0:113 if retcode < 0:
117 print >>sys.stderr, "\nFAIL: attempt to clear bzr status log failed.", -retcode114 print >> sys.stderr, "\nFAIL: attempt to clear bzr status log failed.", -retcode
118 sys.exit()115 sys.exit()
119 else:116 else:
120 print >>sys.stderr, "\nPASS: Bzr status log cleared, Step004, OK.", retcode117 print >> sys.stderr, "\nPASS: Bzr status log cleared, Step004, OK.", retcode
121 print '\nStatus: Pulled the New Release into the Production Server. OK.'118 print '\nStatus: Pulled the New Release into the Production Server. OK.'
122 except OSError, e:119 except OSError, e:
123 print >>sys.stderr, "\nERROR: Could not clear bzr status log", e120 print >> sys.stderr, "\nERROR: Could not clear bzr status log", e
124else:121 sys.exit()
125 pass122
123
124#5.Start Mailman.
125#*****************************************************************************
126#if start from step5
127if int('005') >= InpStpNo:
128 try:
129 #starts mailman
130 retcode = subprocess.call(["sudo /etc/init.d/mailman start"], shell=True)
131 print "\nExecuting, sudo /etc/init.d/mailman start"
132 if retcode < 0:
133 print >> sys.stderr, "\nFAIL: Attempt to start Mailman failed at step005.", -retcode
134 sys.exit()
135 else:
136 print >> sys.stderr, "\nPASS: Started Mailman after merging updates. Status: step005, OK.", retcode
137 except OSError, e:
138 print >> sys.stderr, "\nERROR: step005. Cannot start Mailman", e
139 sys.exit()
140
126141
127#To print Completion and difference TIME.142#To print Completion and difference TIME.
128endTime = datetime.datetime.now()143endTime = datetime.datetime.now()

Subscribers

People subscribed via source and target branches

to all changes: