Skip to content

Commit

Permalink
Merge branch 'release-2.0-nightly' into release-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZemon committed Jul 6, 2014
2 parents 9e4903c + f5b7bbc commit 014796c
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 9 deletions.
182 changes: 182 additions & 0 deletions util/completePackageSystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/python
# File: createBinaryDistr_v2
# Author: David Zemon
# Project: PropWare
#
# Created with: PyCharm Community Edition

"""
@description:
"""

from __future__ import print_function
import argparse
import os
import shutil
import tempfile
import sys
import subprocess
import types

# noinspection PyUnresolvedReferences
import importLibpropeller
# noinspection PyUnresolvedReferences
import importSimple
# noinspection PyUnresolvedReferences
import propwareImporter
import createBinaryDistr

PROPWARE_PATH = os.environ['PROPWARE_PATH']
REPO_URL = "https://github.com/SwimDude0614/PropWare.git"
BINARY_CREATOR_FILENAME = "createBinaryDistr.py"
BROKEN_TAGS = ["v2.0-beta1"]


def completePackager():
global newestBinaryCreator
args = parseArgs()

tempdir = tempfile.gettempdir()
newPropWarePath = tempdir + os.sep + "PropWare"
newestBinaryCreator = createBinaryDistr.CreateBinaryDistr(newPropWarePath)
fixSystemPath()

os.environ['PROPWARE_PATH'] = newPropWarePath
sys.path = [newPropWarePath + os.sep + "util"] + sys.path

branches = newestBinaryCreator.BRANCHES
if args.tags:
branches += newestBinaryCreator.TAGS

failList = []
for branch in branches:
checkoutNewRepo(tempdir, branch)
os.chdir(newPropWarePath)

binaryCreator = getBinaryCreator(branch, newPropWarePath)

run(binaryCreator, branch)

copyZipAndCleanDir(binaryCreator, newPropWarePath, branch, failList)

printSummary(branches, failList)


def parseArgs():
parser = argparse.ArgumentParser(description="Create binary distributions of all branches (and optionally tags too)"
" of PropWare")
parser.add_argument("--tags", action="store_true",
help="Create binary distributions for all tagged commits as well")
return parser.parse_args()


def fixSystemPath():
originPath = sys.path[0]
originPath = originPath[:-5] # Truncate the "/util" from the end

removeMe = []
for path in sys.path:
if originPath in path:
removeMe.append(path)

sys.path = [path for path in sys.path if path not in removeMe]


def checkoutNewRepo(parentDir, branch):
os.chdir(parentDir)

if os.path.exists("PropWare"):
shutil.rmtree("PropWare")

try:
subprocess.check_output(["git", "clone", REPO_URL])
os.chdir("PropWare")
subprocess.check_output(["git", "checkout", branch])
except subprocess.CalledProcessError:
print("Failed to clone from GitHub", file=sys.stderr)
return 1

return 0


def getBinaryCreator(branch, newPropWarePath):
import createBinaryDistr

if hasCreationScript(newPropWarePath):
os.chdir("util")
loadImportScripts()
binaryCreator = reloadModule(createBinaryDistr)
binaryCreator = binaryCreator.CreateBinaryDistr()
if branch in BROKEN_TAGS:
bandageBrokenTag()
else:
binaryCreator = newestBinaryCreator

return binaryCreator


def hasCreationScript(propwarePath):
utilPackage = propwarePath + os.sep + "util"
return os.path.exists(utilPackage) and os.path.exists(utilPackage + os.sep + BINARY_CREATOR_FILENAME)


def loadImportScripts():
# noinspection PyGlobalUndefined
global importAll

sys.modules['importLibpropeller'] = reloadModule(sys.modules['importLibpropeller'])
sys.modules['importSimple'] = reloadModule(sys.modules['importSimple'])
sys.modules['propwareImporter'] = reloadModule(sys.modules['propwareImporter'])
# noinspection PyUnresolvedReferences
from propwareImporter import importAll


def reloadModule(module):
if not module or not isinstance(module, types.ModuleType):
raise TypeError("reload() argument must be module")

try:
# noinspection PyUnboundLocalVariable,PyUnresolvedReferences
return reload(module)
except NameError:
import importlib
return importlib.reload(module)


def run(binaryCreator, branch):
requiresSecondArg = False
try:
binaryCreator.runInBranch(branch)
except TypeError:
requiresSecondArg = True
if requiresSecondArg:
# noinspection PyArgumentList
binaryCreator.runInBranch(branch, branch in newestBinaryCreator.TAGS)


def copyZipAndCleanDir(binaryCreator, newPropWarePath, branch, failList):
newZipFile = binaryCreator.ARCHIVE_FILE_NAME % branch
if os.path.exists(newZipFile):
shutil.copy(newZipFile, PROPWARE_PATH)
else:
failList.append(branch)
shutil.rmtree(newPropWarePath)


def printSummary(branches, failList):
print("\n\nSummary:")
for branch in branches:
if branch not in failList:
print("\tPASS: " + branch)
for branch in failList:
print("\tFAIL: " + branch)


def bandageBrokenTag():
os.chdir("util")
importAll()
os.chdir("..")


if "__main__" == __name__:
completePackager()
17 changes: 10 additions & 7 deletions util/createBinaryDistr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from shutil import copy2
import argparse

from propwareImporter import importAll
import propwareUtils


Expand All @@ -37,17 +36,20 @@ class CreateBinaryDistr:
MAKE_CLEAN_FAILED_CODE = 2
CMAKE_GENERATE_FAILED_CODE = 1

def __init__(self):
def __init__(self, propWareRoot=None):
self.successes = []
self.currentBranch = ""

propwareUtils.checkProperWorkingDirectory()

# Get the current path and truncate "/util" from the end (therefore resulting in PropWare's root)
CreateBinaryDistr.PROPWARE_ROOT = os.getcwd()[:-5]
if None == propWareRoot:
propwareUtils.checkProperWorkingDirectory()
CreateBinaryDistr.PROPWARE_ROOT = os.getcwd()[:-5]

# The remainder of this script needs to be run from the PropWare root directory
os.chdir("..")
else:
CreateBinaryDistr.PROPWARE_ROOT = propWareRoot

# The remainder of this script needs to be run from the PropWare root directory
os.chdir("..")
CreateBinaryDistr.cleanOldArchives()

# noinspection PyShadowingNames
Expand Down Expand Up @@ -77,6 +79,7 @@ def runInBranch(self, branch):
if 0 == CreateBinaryDistr.checkout(branch):
if CreateBinaryDistr.isBranchWithImporter():
os.chdir("util")
from propwareImporter import importAll
importAll()
os.chdir("..")

Expand Down
5 changes: 3 additions & 2 deletions util/propwareImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"""
__author__ = 'david'

from importLibpropeller import ImportLibpropeller
from importSimple import ImportSimple
import propwareUtils


def importAll():
from importLibpropeller import ImportLibpropeller
from importSimple import ImportSimple

propwareUtils.checkProperWorkingDirectory()

# Import libpropeller
Expand Down

0 comments on commit 014796c

Please sign in to comment.