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
1=== added file 'applypatch.py'
2--- applypatch.py 1970-01-01 00:00:00 +0000
3+++ applypatch.py 2012-07-12 06:27:20 +0000
4@@ -0,0 +1,78 @@
5+#!/usr/bin/python -- tested on Python 2.5+ only
6+# coding: utf-8
7+'''
8+"applypatch.py" is the python program used to apply a mailman patch.
9+LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
10+USAGE: python applypatch.py
11+'''
12+
13+# Python modules
14+import sys
15+import os
16+import os.path
17+import subprocess
18+from optparse import OptionParser
19+
20+# Adding Parser for command line options
21+Parser = OptionParser()
22+Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
23+ help="Mailman source directory path", metavar="PATH")
24+Parser.add_option("-p", "--patch-path", dest="patch_path",
25+ help="Patch path", metavar="PATH")
26+Parser.add_option("--dry-run", action="store_true", dest="dry_run",
27+ help="Do not actually change any files; just print what would happen.")
28+
29+(options, args) = Parser.parse_args()
30+
31+if(options.mailman_dir is None):
32+ print "\nerror: Mailman directory path is missing"
33+ print "Try `./applypatch.py --help' for more information."
34+ sys.exit()
35+
36+if(options.patch_path is None):
37+ print "\nerror: Patch path is missing"
38+ print "Try `./applypatch.py --help' for more information."
39+ sys.exit()
40+
41+# Get the paths
42+mailman_dir = os.path.abspath(options.mailman_dir)
43+patch_path = os.path.abspath(options.patch_path)
44+dry_run = options.dry_run
45+current_dir = os.getcwd()
46+
47+# Open log file
48+log_file = open('log-applypatch.txt', 'w')
49+
50+dry_run_arg = ""
51+if(dry_run):
52+ dry_run_arg = "--dry-run"
53+
54+# Commands list, along with the description
55+commands_list = [
56+["patch %s -p0 < %s" % (dry_run_arg, patch_path) , "Applying patch"]
57+]
58+
59+# Change the current working directory to mailman source directory
60+os.chdir(mailman_dir)
61+
62+#Execute the commands
63+for i in range(len(commands_list)):
64+ cmd = commands_list[i][0]
65+ desc = commands_list[i][1]
66+ try:
67+ print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
68+
69+ retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
70+ if retcode < 0:
71+ print "...FAIL:", -retcode
72+ sys.exit()
73+ else:
74+ print "...OK"
75+ except OSError, e:
76+ print "...ERROR: ", e
77+
78+# Change the current working directory
79+os.chdir(current_dir)
80+
81+# Close the log file
82+log_file.close()
83
84=== modified file 'createpatch.py'
85--- createpatch.py 2010-08-15 10:14:18 +0000
86+++ createpatch.py 2012-07-12 06:27:20 +0000
87@@ -2,163 +2,90 @@
88 # coding: utf-8
89 '''
90 "createpatch.py" is the python program used used to create a mailman patch.
91-LICENSE: Copyright(C)2010, Vidya [svaksha] Ayer <vid@svaksha.com>, GPLv3.
92-https://code.launchpad.net/~systers-dev/systers/product-release-systers
93-http://systers.org/systers-dev/doku.php/how_to_create_a_patch
94-
95-USAGE: python createpatch.py (While the execution feedback will be displayed
96-on the terminal, its output is also logged in the "log-createpatch.txt" file.
97+LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
98+USAGE: python createpatch.py
99 '''
100
101 #python modules
102 import sys
103 import os
104 import os.path
105-import popen2
106-import shlex
107-import string
108-import time
109-import commands
110-import datetime
111 import subprocess
112-from glob import glob
113-
114-#python path.
115-filepath, filename = os.path.split(os.path.abspath(os.path.dirname(__file__)))
116-sys.path.append(filepath)
117-sys.path.append("/usr/lib/python2.5/")
118-sys.path.append("/usr/lib/python2.5/sitepackages/bzrlib/")
119-sys.path.append("/usr/share/pyshared/bzrlib/")
120-
121-#print $user
122-user = os.environ['USER']
123-print '\n User:', user
124-startTime = datetime.datetime.now()
125-print '\nThe starting date, time is:', str(startTime)
126-
127-#logging to file and scr.
128-sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
129-tee = subprocess.Popen(["tee", "log-createpatch.txt"], stdin=subprocess.PIPE)
130-os.dup2(tee.stdin.fileno(), sys.stdout.fileno())
131-os.dup2(tee.stdin.fileno(), sys.stderr.fileno())
132-
133-#Terminal user input
134-print "\nThis script automates the patch creation process for these steps: \
135- \n001. Make a patch with 2 files \
136- \n002. Patch with a directory of files \
137- \n003. Dry run before applying the patch \
138- \n004. Apply the patch only when there are no errors. "
139-print "\nEnter a step number [Ex. 001, to start from step one]:"
140-
141-#******************************************************************************
142-#CREATE A PATCH steps are based on this write-up:
143-#http://systers.org/systers-dev/doku.php/how_to_create_a_patch
144-#******************************************************************************
145-#ask user to input starting step number.
146-InpStpNo = int(input())
147-print "\nStarting step number is: %d" % InpStpNo
148-print "\nBatch job begins for: Creating a Patch."
149-
150-#1.Make a patch with 2 files (this works on most Linux distros):
151-#*****************************************************************************
152-#if start from step1
153-if int('001') >= InpStpNo:
154- try:
155- #ask user input for file path.
156- print "\nEnter 'oldfile' path (ex. '/home/path/olddir/oldfile' : "
157- oldfile = str(input())
158- print "\nEnter 'newfile' path (ex. '/home/path/newdir/newfile' : "
159- newfile = str(input())
160- retcode = subprocess.call(["diff -u %s %s > file.patch" % (oldfile, newfile)], shell=True)
161- print "\nExecuting, diff -u %s %s > file.patch"
162- if retcode < 0:
163- #if diff fails
164- print >>sys.stderr, "\nFAIL: step 001 (Cannot create a patch with two files)", -retcode
165- sys.exit()
166- else:
167- #create patch for 2 files.
168- print >>sys.stderr, "\nPASS: step001-Created a patch with 2 files. END 001, OK", retcode
169- except OSError, e:
170- print >>sys.stderr, "\nERROR: step 001", e
171-else:
172- pass
173-
174-
175-#2.Creating a patch with a directory of files
176-#*****************************************************************************
177-#if start from step2.
178-if int('002') >= InpStpNo and int('001') != InpStpNo:
179- try:
180- #user input for folder/directory path.
181- print "\nEnter 'oldDirectory' path name (Ex. '/home/path/olddir/' :"
182- olddir = str(input())
183- print "\nEnter 'newDirectory' path name (Ex. '/home/path/newdir/' :"
184- newdir = str(input())
185- retcode = subprocess.call(["diff -Naur %s %s > file.patch" % (olddir, newdir)], shell=True)
186- print "\nExecuting, diff -Naur %s %s > file.patch"
187- if retcode < 0:
188- #if diff of 'old-new' files fail
189- print >>sys.stderr, "FAIL: step002-Cannot create a patch with a directory of files:", -retcode
190- sys.exit()
191- else:
192- #create patch for 2 directory's.
193- print >>sys.stderr, "PASS: step002-Created a patch with a directory of files. END 002, OK.", retcode
194- except OSError, e:
195- print >>sys.stderr, "ERROR: step 002", e
196-else:
197- pass
198-
199-
200-#3.Dry run before applying the patch:
201-#*****************************************************************************
202-#if start from step3.
203-if int('003') >= InpStpNo:
204- try:
205- #execute dry run.
206- retcode = subprocess.call(["patch -p0 --dry-run < file.patch"], shell=True)
207- print "\nExecuting, patch -p0 --dry-run < file.patch"
208- if retcode < 0:
209- #dry run fails
210- print >>sys.stderr, "FAIL: step003-Dry run failed.", -retcode
211- sys.exit()
212- else:
213- #dry run OK.
214- print >>sys.stderr, "PASS: step003-Dry run to check for errors successful. END 003, OK", retcode
215- except OSError, e:
216- print >>sys.stderr, "ERROR: step 003, Dry run.", e
217-else:
218- pass
219-
220-#4.apply the patch only when there are no error
221-#*****************************************************************************
222-#if start from step4
223-if int('004') >= InpStpNo:
224- try:
225- #applying the patch
226- retcode = subprocess.call(["patch -p0 < file.patch"], shell=True)
227- print "\nExecuting, patch -p0 --dry-run < file.patch"
228- if retcode < 0:
229- #Fail to apply patch
230- print >>sys.stderr, "FAIL: step004, Cannot apply patch.", -retcode
231- sys.exit()
232- else:
233- #Patch applied successfully.
234- print >>sys.stderr, "PASS: step004, Application of patch successful. END 004, OK.", retcode
235- print '\nStatus: Patches applied, OK.'
236- except OSError, e:
237- print >>sys.stderr, "ERROR: step 004, Dry run.", e
238-else:
239- pass
240-
241-#Printing Completion and difference TIME.
242-#*****************************************************************************
243-endTime = datetime.datetime.now()
244-print "\nEnding Time for the program 'createpatch.py' is: ", str(endTime)
245-timedelta = endTime - startTime
246-
247-#Printing total system installation time taken by 'createpatch.py'.
248-#*****************************************************************************
249-installationTime = timedelta
250-print "\nTotal time taken by 'createpatch.py': ", installationTime
251-
252-
253+from optparse import OptionParser
254+
255+# Adding Parser for command line options
256+Parser = OptionParser()
257+Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
258+ help="Mailman source directory path", metavar="PATH")
259+Parser.add_option("-s", "--systers-dir", dest="systers_dir",
260+ help="Systers source directory path", metavar="PATH")
261+
262+(options, args) = Parser.parse_args()
263+
264+if(options.mailman_dir is None):
265+ print "\nerror: Mailman directory path is missing"
266+ print "Try `./createpatch.py --help' for more information."
267+ sys.exit()
268+
269+if(options.systers_dir is None):
270+ print "\nerror: Systers directory path is missing"
271+ print "Try `./createpatch.py --help' for more information."
272+ sys.exit()
273+
274+# Get the paths
275+mailman_dir = os.path.abspath(options.mailman_dir)
276+systers_dir = os.path.abspath(options.systers_dir)
277+current_dir = os.getcwd()
278+patch_path = current_dir + "/systers.patch"
279+tmp_dir = os.path.abspath("/tmp/systers-patch/")
280+
281+# Open log file
282+log_file = open('log-createpatch.txt', 'w')
283+
284+# Commands list, along with the description
285+commands_list = [
286+["\cp -rf %s/* %s" % (mailman_dir,tmp_dir) , "Copying mailman source"],
287+["bzr init ." , "Creating bzr repo"],
288+["bzr add ." , "Adding mailman files to repo"],
289+["bzr commit -m 'Init'" , "Initial commit"],
290+["\cp -rf %s/* %s" % (systers_dir, tmp_dir), "Copying systers source"],
291+["bzr add ." , "Adding systers files to repo"],
292+["bzr diff > %s" % (patch_path) , "Generating patch"],
293+["rm -rf %s" % (tmp_dir) , "Cleaning up temporary files"]
294+]
295+
296+
297+# Create the temp directory
298+try:
299+ retcode = subprocess.call([ "mkdir %s" %(tmp_dir) ], shell=True)
300+ if retcode < 0:
301+ print "FAIL:", -retcode
302+ sys.exit()
303+
304+except OSError, e:
305+ print "ERROR: ", e
306+
307+# Change the current working directory to temp directory
308+os.chdir(tmp_dir)
309+
310+#Execute the commands
311+for i in range(len(commands_list)):
312+ cmd = commands_list[i][0]
313+ desc = commands_list[i][1]
314+ try:
315+ print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
316+
317+ retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
318+ if retcode < 0:
319+ print "...FAIL:", -retcode
320+ sys.exit()
321+ else:
322+ print "...OK"
323+ except OSError, e:
324+ print "...ERROR: ", e
325+
326+# Change the current working directory
327+os.chdir(current_dir)
328+
329+# Close the log file
330+log_file.close()
331
332=== added file 'prodpatch-new.py'
333--- prodpatch-new.py 1970-01-01 00:00:00 +0000
334+++ prodpatch-new.py 2012-07-12 06:27:20 +0000
335@@ -0,0 +1,68 @@
336+#!/usr/bin/python -- tested on Python 2.5+ only
337+# coding: utf-8
338+'''
339+"prodpatch.py" is the python program used used to create a mailman patch.
340+LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
341+USAGE: python prodpatch.py
342+'''
343+
344+#python modules
345+import sys
346+import os
347+import os.path
348+import subprocess
349+from optparse import OptionParser
350+
351+# Adding Parser for command line options
352+Parser = OptionParser()
353+Parser.add_option("-m", "--mailman-dir", dest="mailman_dir",
354+ help="Mailman source directory path", metavar="PATH")
355+
356+(options, args) = Parser.parse_args()
357+
358+if(options.mailman_dir is None):
359+ print "\nerror: Mailman directory path is missing"
360+ print "Try `./prodpatch.py --help' for more information."
361+ sys.exit()
362+
363+
364+# Get the paths
365+mailman_dir = os.path.abspath(options.mailman_dir)
366+current_dir = os.getcwd()
367+
368+# Open log file
369+log_file = open('log-prodpatch.txt', 'w')
370+
371+# Commands list, along with the description
372+commands_list = [
373+["sudo /etc/init.d/mailman stop" , "Stop mailman"],
374+["sudo bzr update" , "Update repo with new release"],
375+["bzr conflicts" , "Resolve conflicts"],
376+["bzr resolve -all" , "Clear bzr status log"],
377+["sudo /etc/init.d/mailman start", "Start mailman"]
378+]
379+
380+# Change the current working directory to temp directory
381+os.chdir(mailman_dir)
382+
383+#Execute the commands
384+for i in range(len(commands_list)):
385+ cmd = commands_list[i][0]
386+ desc = commands_list[i][1]
387+ try:
388+ print "Step %d/%d : %s " % ((i+1), len(commands_list), desc),
389+
390+ retcode = subprocess.call([ cmd ], shell=True, stdout=log_file, stderr=log_file)
391+ if retcode < 0:
392+ print "...FAIL:", -retcode
393+ sys.exit()
394+ else:
395+ print "...OK"
396+ except OSError, e:
397+ print "...ERROR: ", e
398+
399+# Change the current working directory
400+os.chdir(current_dir)
401+
402+# Close the log file
403+log_file.close()
404
405=== modified file 'prodpatch.py'
406--- prodpatch.py 2010-08-15 10:14:18 +0000
407+++ prodpatch.py 2012-07-12 06:27:20 +0000
408@@ -1,8 +1,9 @@
409 #!/usr/bin/python - Python 2.5+ only
410 # coding: utf-8
411 '''
412-"prodpatch.py" is a python program used to Pull a New Release to the
413-LICENSE: Copyright(C)2010, Vidya [svaksha] Ayer <vid@svaksha.com>, GPLv3.
414+"prodpatch.py" is a python program used to Pull a New Release to the production server
415+LICENSE: Copyright(C)2012, Mayank Juneja <mayankjuneja1@gmail.com>, GPLv3.
416+(Original code by Vidya [svaksha] Ayer <vid@svaksha.com>)
417 http://systers.org/systers-dev/doku.php/how_to_pull_a_new_release_to_the_production_server
418 https://code.launchpad.net/~systers-dev/systers/product-release-systers
419
420@@ -14,11 +15,6 @@
421 import sys
422 import os
423 import os.path
424-import popen2
425-import shlex
426-import string
427-import time
428-import commands
429 import datetime
430 import subprocess
431
432@@ -48,8 +44,12 @@
433 #******************************************************************************
434
435 #Terminal user input
436-print "\nEnter the step number [Ex. 001, to start from step one]:"
437-InpStpNo = int(input())
438+try:
439+ InpStpNo = int(raw_input("\nEnter the step number [Ex. 001, to start from step one]: "))
440+except ValueError, e:
441+ print >> sys.stderr, e
442+ sys.exit()
443+
444 print "\nStarting step number is: %d" % InpStpNo
445 print "\nBatch job begins for: Production Patch."
446
447@@ -62,14 +62,13 @@
448 retcode = subprocess.call(["sudo /etc/init.d/mailman stop"], shell=True)
449 print "\nExecuting, sudo /etc/init.d/mailman stop"
450 if retcode < 0:
451- print >>sys.stderr, "\nFAIL: Attempt to stop Mailman failed at step001.", -retcode
452+ print >> sys.stderr, "\nFAIL: Attempt to stop Mailman failed at step001.", -retcode
453 sys.exit()
454 else:
455- print >>sys.stderr, "\nPASS: Stopped Mailman to merge updates. Status: step001, OK.", retcode
456+ print >> sys.stderr, "\nPASS: Stopped Mailman to merge updates. Status: step001, OK.", retcode
457 except OSError, e:
458- print >>sys.stderr, "\nERROR: step001. Cannot stop Mailman", e
459-else:
460- pass
461+ print >> sys.stderr, "\nERROR: step001. Cannot stop Mailman", e
462+ sys.exit()
463
464 #2.Update server with new release.
465 #******************************************************************************
466@@ -79,14 +78,13 @@
467 retcode = subprocess.call(["sudo bzr update"], shell=True)
468 print "\nExecuting, sudo bzr update"
469 if retcode < 0:
470- print >>sys.stderr, "\nFAIL: Attempt to update from server", -retcode
471+ print >> sys.stderr, "\nFAIL: Attempt to update from server", -retcode
472 sys.exit()
473 else:
474- print >>sys.stderr, "\nPASS: Updated Mailman. Status: Step002 OK.", retcode
475+ print >> sys.stderr, "\nPASS: Updated Mailman. Status: Step002 OK.", retcode
476 except OSError, e:
477- print >>sys.stderr, "\nERROR: Server Update.", e
478-else:
479- pass
480+ print >> sys.stderr, "\nERROR: Server Update.", e
481+ sys.exit()
482
483
484 #3.Resolve any conflicts.
485@@ -97,14 +95,13 @@
486 retcode = subprocess.call(["bzr conflicts"], shell=True)
487 print "\nExecuting, bzr conflicts"
488 if retcode < 0:
489- print >>sys.stderr, "\nFAIL: A conflict was detected during the Update.", -retcode
490+ print >> sys.stderr, "\nFAIL: A conflict was detected during the Update.", -retcode
491 sys.exit()
492 else:
493- print >>sys.stderr, "\nPASS: Resolved all conflicts in Mailman Update, Status: Step003, OK.", retcode
494+ print >> sys.stderr, "\nPASS: Resolved all conflicts in Mailman Update, Status: Step003, OK.", retcode
495 except OSError, e:
496- print >>sys.stderr, "\nERROR: Could not resolve conflict in update.", e
497-else:
498- pass
499+ print >> sys.stderr, "\nERROR: Could not resolve conflict in update.", e
500+ sys.exit()
501
502 #4.Clear BZR status log.
503 #******************************************************************************
504@@ -114,15 +111,33 @@
505 retcode = subprocess.call(["bzr resolve --all"], shell=True)
506 print "Executing command, bzr resolve --all"
507 if retcode < 0:
508- print >>sys.stderr, "\nFAIL: attempt to clear bzr status log failed.", -retcode
509+ print >> sys.stderr, "\nFAIL: attempt to clear bzr status log failed.", -retcode
510 sys.exit()
511 else:
512- print >>sys.stderr, "\nPASS: Bzr status log cleared, Step004, OK.", retcode
513+ print >> sys.stderr, "\nPASS: Bzr status log cleared, Step004, OK.", retcode
514 print '\nStatus: Pulled the New Release into the Production Server. OK.'
515 except OSError, e:
516- print >>sys.stderr, "\nERROR: Could not clear bzr status log", e
517-else:
518- pass
519+ print >> sys.stderr, "\nERROR: Could not clear bzr status log", e
520+ sys.exit()
521+
522+
523+#5.Start Mailman.
524+#*****************************************************************************
525+#if start from step5
526+if int('005') >= InpStpNo:
527+ try:
528+ #starts mailman
529+ retcode = subprocess.call(["sudo /etc/init.d/mailman start"], shell=True)
530+ print "\nExecuting, sudo /etc/init.d/mailman start"
531+ if retcode < 0:
532+ print >> sys.stderr, "\nFAIL: Attempt to start Mailman failed at step005.", -retcode
533+ sys.exit()
534+ else:
535+ print >> sys.stderr, "\nPASS: Started Mailman after merging updates. Status: step005, OK.", retcode
536+ except OSError, e:
537+ print >> sys.stderr, "\nERROR: step005. Cannot start Mailman", e
538+ sys.exit()
539+
540
541 #To print Completion and difference TIME.
542 endTime = datetime.datetime.now()

Subscribers

People subscribed via source and target branches

to all changes: