Skip to content

Commit

Permalink
Merge pull request #126 from forderud/autopkg-rm
Browse files Browse the repository at this point in the history
[GE packaging] Remove "autopkg" support & fix Python 3 issue
  • Loading branch information
forderud authored Jan 15, 2019
2 parents 727417d + 7203988 commit 96c91e9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 89 deletions.
6 changes: 3 additions & 3 deletions PackagingGE/BuildNuGet.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ set PATH=%PATH%;C:\Python27
set PATH=%PATH%;"C:\Program Files\Git\bin"

:: Dependencies:
:: * Python.exe in PATH
:: * Python installed
:: * Visual Studio command prompt (msbuild & C++ compiler in PATH)
:: * NuGet.exe in PATH (https://www.nuget.org/downloads)

pushd ..

if DEFINED NUGET_REPO (
python.exe PackagingGE\DetermineNextTag.py minor > NEW_TAG.txt
PackagingGE\DetermineNextTag.py minor > NEW_TAG.txt
) else (
:: Local nuget build. Not to be deployed.
python.exe PackagingGE\DetermineNextTag.py patch > NEW_TAG.txt
PackagingGE\DetermineNextTag.py patch > NEW_TAG.txt
)
IF %ERRORLEVEL% NEQ 0 exit /B 1
set /p VERSION=< NEW_TAG.txt
Expand Down
1 change: 1 addition & 0 deletions PackagingGE/DetermineNextTag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def DetermineHighestTagVersion ():
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
tags = []
for line in p.stdout.readlines():
line = line.decode()
line = line.strip(' /\r\n') # remove '/' & newline suffix
tags.append(line)

Expand Down
2 changes: 1 addition & 1 deletion PackagingGE/PackagePublishNuget.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set VERSION_NUMBER=%2
set NUGET_REPO=%3

:: Change NuGet packaging version and project URL
python.exe ..\PackagingGE\SetAutopkgVersion.py %NUSPEC_FILE% %VERSION_NUMBER% https://github.com/MedicalUltrasound/Image3dAPI/tree/%VERSION_NUMBER%
..\PackagingGE\SetNuspecVersion.py %NUSPEC_FILE% %VERSION_NUMBER% https://github.com/MedicalUltrasound/Image3dAPI/tree/%VERSION_NUMBER%
IF %ERRORLEVEL% NEQ 0 exit /B 1

:: Package artifacts
Expand Down
85 changes: 0 additions & 85 deletions PackagingGE/SetAutopkgVersion.py

This file was deleted.

70 changes: 70 additions & 0 deletions PackagingGE/SetNuspecVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import print_function
import fileinput
import os
import sys
from xml.dom import minidom


def IdentifyDependencies (filename):
'''Parse NuGet dependencies from a 'packages.config'-style file'''

# parse dependencies into a dict
xml_doc = minidom.parse(filename)
dep_dict = {}
for package in xml_doc.childNodes[0].childNodes:
if package.nodeName == 'package':
id = package.attributes['id'].value
version = package.attributes['version'].value
dep_dict[id] = version

return dep_dict


def UpdateNuspec (filename, version, url, dependencies):
'''Set the minor version in an nuspec file'''

for line in fileinput.input(filename, inplace=True):
if '<<GIT-VERSION>>' in line:
# use current git version
print(line.replace('<<GIT-VERSION>>', version), end='')
elif '<<SOURCE-URL>>' in line:
print(line.replace('<<SOURCE-URL>>', url), end='')
elif '<<VERSION>>' in line:
# line on "<dependency id="xxx" version="<<VERSION>>" />" format
tokens = line.split()
for token in tokens:
if token[:4] == 'id="':
package = token[4:-1]
elif token[:6] == 'version="':
pass # assume that tag contains "<<VERSION>>" string
line = ' <dependency id="'+package+'" version="'+dependencies[package]+'" />'
print(line, end='\n')
elif '<<DEPENDENCIES>>' in line:
# convert dependency dict to nuspec XML representation
dep_str = ''
for key in dependencies:
dep_str += '<dependency id="'+key+'" version="'+dependencies[key]+'" />\n '
print(line.replace('<<DEPENDENCIES>>', dep_str), end='')
else:
print(line, end='')


if __name__ == "__main__":
filename = sys.argv[1] # nuspec file
version = sys.argv[2] # version number
url = sys.argv[3] # release URL

# parse dependencies from NuGet config file arguments
deps = {}
for i in range(4, len(sys.argv)):
print('Parsing dependencies from '+sys.argv[i])
tmp = IdentifyDependencies(sys.argv[i])
for key in tmp:
if key in deps:
if deps[key] != tmp[key]:
raise BaseException('Version mismatch in package '+key+': '+deps[key]+' vs. '+tmp[key])
else:
deps[key] = tmp[key]

print('Setting version and URL of '+filename+' to '+version+' and '+url)
UpdateNuspec(filename, version, url, deps)

0 comments on commit 96c91e9

Please sign in to comment.