Вот новый скрипт, теперь он еще пакует в ZIP и номер сборки делает инкриментом, прописывая его в скрипт сборки установочника.

## Код:
```
#!/usr/bin/python

from subprocess import Popen, PIPE
import sys, datetime, fileinput

buildDir = "/var/www/tribiq/build"
localRepository = "/var/www/git/bbcb.git"
devDir = "/var/www/tribiq/dev"
stableDir = "/var/www/tribiq/stable"
wine = "/usr/local/bin/wine"
iscc = "/usr/local/bin/iscc"


# this files contains hashes of last commits in master and development branches
DEVHASH = open(buildDir + "/devHash", "r+")
STABLEHASH = open(buildDir + "/stableHash", "r+")

process1 = Popen("cd " + localRepository + " && git log", stdout=PIPE, stderr=PIPE, shell=True)
(stdout1, stderr1) = process1.communicate()
if stderr1 == "":
   hash1 = stdout1.split("\n")[0].split(" ")[1]
   if STABLEHASH.readline().strip() == hash1:
      rebuildStable = False
      #print "No new commits in 'master'
"
   else:
      rebuildStable = True
      print "New commit in 'master', need to run build pipeline
"
else:
   print stderr1

process2 = Popen("cd " + localRepository + " && git log development", stdout=PIPE, stderr=PIPE, shell=True)
(stdout2, stderr2) = process2.communicate()
if stderr2 == "":
   hash2 = stdout2.split("\n")[0].split(" ")[1]
   if DEVHASH.readline().strip() == hash2:
      rebuildDev = False
      # print "No new commits in 'developent'
"
   else:
      rebuildDev = True
      print "New commit in 'development', need to run build pipeline
"
else:
   print stderr2


def log(out, err):
   if out != "":   
      for line1 in out.split("\n"):
         print line1 + "
"
   if err != "":
      for line2 in err.split("\n"):
         print line2 + "
"

#### BUILDING STABLE
if rebuildStable:
   print "Building from 'master' at " + datetime.datetime.now().isoformat() + "
"
   print "The build pipeline for 'master' branch is not developed..."
   # STABLEHASH.seek(0)
   # STABLEHASH.write(hash1)
   # STABLEHASH.truncate()


#### BUILDING DEVELOPMENT
if rebuildDev:

   print "
<b>Building from 'development' at " + datetime.datetime.now().isoformat() + "</b>
"
   print "Trying to check repository state...
"
   try:
       f = open(localRepository + ".lock", "r")
   except IOError:
       print "Repository is not locked. Continuing.
"
   else:
       print "Repository is locked (possibly because of sync process).
Aborting.
"
       f.close()
       sys.exit()

   print "Trying to clone repository into temporary folder...
"

   process1 = Popen("cd " + buildDir + " && git clone " + localRepository + " bb", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout1, stderr1) = process1.communicate()
   log(stdout1, stderr1)

   print "Checking out development...
"
   process2 = Popen("cd " + buildDir + "/bb && git checkout development", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout2, stderr2) = process2.communicate()
   log(stdout2, stderr2)

   print "Building BlackBox...
"
   process3 = Popen("cd " + buildDir + "/bb && " + wine + " dev0.exe < build.txt 2>&1", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout3, stderr3) = process3.communicate()
   log(stdout3, stderr3)

   NUMBER = open("number", "r+")
   buildNum = int(NUMBER.readline().strip())
   IN = open("bb/appbuild/BlackBox.iss", "r")
   lines = IN.readlines()
   IN.close()
   OUT = open("bb/appbuild/BlackBox.iss", "w")
   n = 0
   for line in lines:
      if n == 1:
         version = line.split('"')[1]
      n = n + 1
      if line[:18] == "VersionInfoVersion":
         print >> OUT, line.strip() + str(buildNum).zfill(3)
      else:
         print >> OUT, line,
   OUT.close()
   

   version = version + "." + str(buildNum).zfill(3)

   print "The version of build: " + version + "
"

   print "Building Setup File...
"
   process4 = Popen("cd " + buildDir + "/bb && mv Code System/ && mv Sym System/ && cd appbuild && " + iscc + " - < ./BlackBox.iss", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout4, stderr4) = process4.communicate()
   log(stdout4, stderr4)


   print "Moving Setup File to dev folder...
"
   process5 = Popen("mv " + buildDir + "/bb/appbuild/Output/setup.exe " + devDir + "/blackbox-" + version + "-setup.exe", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout5, stderr5) = process5.communicate()
   log(stdout5, stderr5)

   if stderr5 == "":
      print "Hash for 'development' branch updated
"
      DEVHASH.seek(0)
      DEVHASH.write(hash2)
      DEVHASH.truncate()
      print "Build number updated to " + str(buildNum + 1) + "
"
      NUMBER.seek(0)
      NUMBER.write(str(buildNum+1))
      NUMBER.truncate()



   print "Zipping...
"
   process6 = Popen("cd " + buildDir + "/bb && rm -R *.txt appbuild dev0.exe && zip -r ../../dev/blackbox-" + version + ".zip *", stdout=PIPE, stderr=PIPE, shell=True)
   (stdout6, stderr6) = process6.communicate()
   log(stdout6, stderr6)



   print "Cleaning...
"
        process7 = Popen("cd " + buildDir + " && rm bb -R", stdout=PIPE, stderr=PIPE, shell=True)
        (stdout7, stderr7) = process7.communicate()
        log(stdout6, stderr7)
```
