Created
November 10, 2014 16:45
-
-
Save reapazor/ce61eda105706ff449e7 to your computer and use it in GitHub Desktop.
Template Pre Build Numbering System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import Libraries | |
import os | |
import sys | |
import time | |
import getpass | |
def create(productName, fileSystemName, namespace, URI, GUID, projectPath, solutionFile): | |
# Setup Some Basic Things | |
username = getpass.getuser() | |
root = os.path.relpath(".." + os.sep + "..") | |
projectDataFile = os.path.join(root, "Data", fileSystemName + ".dat") | |
countersFolder = os.path.join(root, "Counters", fileSystemName) | |
userCounterFile = os.path.join(countersFolder, username + ".dat") | |
templateInputFile = os.path.join(root, "Templates", "Info.cs") | |
templateOutputFile = os.path.join(projectPath, "Properties", "Info.cs") | |
timestamp = time.strftime("%Y-%m-%d %H:%M:%S %Z") | |
# Get CraDLL Version from Solution File | |
with open (solutionFile, "r") as solutionFileReference: | |
solutionFileContent = solutionFileReference.readlines() | |
for i in range(len(solutionFileContent)): | |
if "version = " in solutionFileContent[i]: | |
version = solutionFileContent[i].replace('version = ', '').strip() | |
# Get Base Build Number | |
with open (projectDataFile, "r") as baseBuildFile: | |
baseBuildNumber=int(baseBuildFile.read().replace('\n', '')) | |
# Get Personal Build Number | |
if os.path.isfile(userCounterFile): | |
with open (userCounterFile, "r") as buildFile: | |
personalBuild=int(buildFile.read().replace('\n', '')) | |
else: | |
personalBuild = 0 | |
# Increment Build Number | |
personalBuild += 1 | |
# Output Personal Build Number to File | |
with open(userCounterFile, "w") as buildFile: | |
buildFile.write(str(personalBuild)) | |
# Get All Build Numbers & Total | |
buildTotal = baseBuildNumber | |
counterDir = os.listdir( countersFolder ) | |
for counter in counterDir: | |
if not counter.startswith('.'): | |
currentCounter = os.path.join(countersFolder, counter) | |
with open (currentCounter, "r") as counterFile: | |
buildTotal+=int(counterFile.read().replace('\n', '')) | |
# Deal with the templated Info file | |
with open (templateInputFile, "r") as infoSource: | |
info = infoSource.readlines() | |
for i in range(len(info)): | |
info[i] = info[i].replace('[NAMESPACE]', namespace) | |
info[i] = info[i].replace('[PRODUCT_NAME]', productName) | |
info[i] = info[i].replace('[VERSION]', version) | |
info[i] = info[i].replace('[URI]', URI) | |
info[i] = info[i].replace('[USERNAME]', username) | |
info[i] = info[i].replace('[BUILD_NUMBER]', str(buildTotal)) | |
info[i] = info[i].replace('[BUILD_REVISION]', str(personalBuild)) | |
info[i] = info[i].replace('[BUILD_STAMP]', timestamp) | |
info[i] = info[i].replace('[GUID]', GUID) | |
# This creates the number of build since the last time we cached our build number, which happens | |
# when we increment the version file usually. | |
info[i] = info[i].replace('[LOCAL_BUILD_NUMBER]', str(buildTotal-baseBuildNumber)) | |
# Output template file | |
with open (templateOutputFile, "w") as infoOutput: | |
infoOutput.writelines(info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment