1- #/usr/bin/python
1+ #! /usr/bin/python
22# @file createBinaryDistr.py
33# @author David Zemon
44# @project PropWare
1717import subprocess
1818from time import sleep
1919from shutil import copy2
20+ import argparse
2021
2122from propwareImporter import importAll
2223import propwareUtils
@@ -29,13 +30,12 @@ class CreateBinaryDistr:
2930 "jpg" , "lang" , "pdf" , "png" ]
3031 BLACKLISTED_DIRECTORIES = ["docs" , ".idea" , ".settings" , ".git" , propwareUtils .DOWNLOADS_DIRECTORY ]
3132 BRANCHES = ["master" , "development" , "release-2.0" , "release-2.0-nightly" ]
33+ TAGS = ["v1.1" , "v1.2" , "v2.0-beta1" ]
3234 CURRENT_SUGGESTION = "release-2.0"
3335
3436 def __init__ (self ):
35- CreateBinaryDistr .BRANCHES .sort ()
3637 self .successes = []
3738
38- def run (self ):
3939 propwareUtils .checkProperWorkingDirectory ()
4040
4141 # Import all extra libraries
@@ -45,22 +45,29 @@ def run(self):
4545 os .chdir (".." )
4646 CreateBinaryDistr .cleanOldArchives ()
4747
48+ def run (self , branches , areTags = False ):
49+ assert (isinstance (branches , list ))
50+ assert (isinstance (areTags , bool ))
51+
52+ branches .sort ()
53+ self .successes = []
54+
4855 try :
49- for branch in CreateBinaryDistr . BRANCHES :
50- self .runInBranch (branch )
56+ for branch in branches :
57+ self .runInBranch (branch , areTags )
5158 except Exception as e :
5259 print (e , file = sys .stderr )
5360 finally :
5461 CreateBinaryDistr .attemptCleanExit ()
5562
56- self .printSummary ()
63+ self .printSummary (branches )
5764
58- def runInBranch (self , branch ):
65+ def runInBranch (self , branch , isTag ):
5966 # Clean any leftover crud
6067 CreateBinaryDistr .clean ()
6168
6269 # Attempt to checkout the next branch
63- if 0 == CreateBinaryDistr .checkout (branch ):
70+ if 0 == CreateBinaryDistr .checkout (branch , isTag ):
6471 # Compile the static libraries and example projects
6572 CreateBinaryDistr .compile ()
6673
@@ -111,18 +118,21 @@ def clean():
111118 raise e
112119
113120 @staticmethod
114- def checkout (branch ):
121+ def checkout (branch , isTag = False ):
122+ assert (isinstance (isTag , bool ))
123+
115124 try :
116125 subprocess .check_output (["git" , "checkout" , branch ])
117126 except subprocess .CalledProcessError :
118127 print ("Failed to checkout " + branch , file = sys .stderr )
119128 return 1
120129
121- try :
122- subprocess .check_output (["git" , "pull" ])
123- except subprocess .CalledProcessError :
124- print ("Failed to pull latest sources" , file = sys .stderr )
125- return 1
130+ if not isTag :
131+ try :
132+ subprocess .check_output (["git" , "pull" ])
133+ except subprocess .CalledProcessError :
134+ print ("Failed to pull latest sources" , file = sys .stderr )
135+ return 1
126136
127137 return 0
128138
@@ -154,15 +164,15 @@ def attemptCleanExit():
154164 print ("Caused by: " + str (e ), file = sys .stderr )
155165 print (e .output .decode (), file = sys .stderr )
156166
157- def printSummary (self ):
167+ def printSummary (self , branches ):
158168 # Let the stdout and stderr buffers catch up
159169 sleep (1 )
160170
161171 print ("\n \n Summary:" )
162172 self .successes .sort ()
163173 for branch in self .successes :
164174 print ("\t PASS: " + branch )
165- for branch in CreateBinaryDistr . BRANCHES :
175+ for branch in branches :
166176 if branch not in self .successes :
167177 print ("\t FAIL: " + branch )
168178
@@ -176,5 +186,14 @@ def __str__(self):
176186
177187
178188if "__main__" == __name__ :
189+ parser = argparse .ArgumentParser (description = "Create binary distributions of all branches (and optionally tags too)"
190+ " of PropWare" )
191+ parser .add_argument ("--tags" , action = "store_true" ,
192+ help = "Create binary distributions for all tagged commits as well" )
193+ args = parser .parse_args ()
194+
179195 runMe = CreateBinaryDistr ()
180- runMe .run ()
196+ runMe .run (CreateBinaryDistr .BRANCHES )
197+
198+ if args .tags :
199+ runMe .run (CreateBinaryDistr .TAGS , True )
0 commit comments