summaryrefslogtreecommitdiff
path: root/packman
diff options
context:
space:
mode:
authorJason Maskell <Jason Maskell>2016-07-26 16:21:57 +0700
committerJason Maskell <Jason Maskell>2016-07-26 16:21:57 +0700
commit9d3f79f7e7e68ca9e296368587ab22494ffaf19b (patch)
treeeaa4190d763f6504ba5ba91fe367c937406a2a45 /packman
parentModified finders to take Visual Studio platform into account when finding lib... (diff)
downloadwaveworks_archive-9d3f79f7e7e68ca9e296368587ab22494ffaf19b.tar.xz
waveworks_archive-9d3f79f7e7e68ca9e296368587ab22494ffaf19b.zip
Added Packman support - now the GenerateProjects.bat uses Packman to pull dependencies specified in WaveWorksDependencies.xml
Finders of these dependencies are modified to look in the Packman repo.
Diffstat (limited to 'packman')
-rw-r--r--packman/windows/configure/configure_s3.bat79
-rw-r--r--packman/windows/configure/fetch_file_from_s3.ps143
-rw-r--r--packman/windows/configure/install_package.py41
-rw-r--r--packman/windows/packman.cmd18
4 files changed, 181 insertions, 0 deletions
diff --git a/packman/windows/configure/configure_s3.bat b/packman/windows/configure/configure_s3.bat
new file mode 100644
index 0000000..4beae82
--- /dev/null
+++ b/packman/windows/configure/configure_s3.bat
@@ -0,0 +1,79 @@
+@echo off
+set PM_PACKMAN_VERSION=3.0
+:: The external root may already be configured and we should do minimal work in that case
+if defined PM_PACKAGES_ROOT goto ENSURE_DIR
+
+:: If the folder isn't set we assume that the best place for it is on the drive that we are currently
+:: running from
+set PM_DRIVE=%CD:~0,2%
+
+set PM_PACKAGES_ROOT=%PM_DRIVE%\NVIDIA\packman-repo
+
+:: We use *setx* here so that the variable is persisted in the user environment
+echo Setting user environment variable PM_PACKAGES_ROOT to %PM_PACKAGES_ROOT%
+setx PM_PACKAGES_ROOT %PM_PACKAGES_ROOT%
+if errorlevel 1 goto ERROR
+
+:: Check for the directory that we need. Note that mkdir will create any directories
+:: that may be needed in the path
+:ENSURE_DIR
+if not exist %PM_PACKAGES_ROOT% (
+ echo Creating directory %PM_PACKAGES_ROOT%
+ mkdir %PM_PACKAGES_ROOT%
+)
+
+:: The Python interpreter may already be externally configured
+if defined PM_PYTHON_EXT (
+ set PM_PYTHON=%PM_PYTHON_EXT%
+ goto PACKMAN
+)
+
+set PM_PYTHON_DIR=%PM_PACKAGES_ROOT%\python\2.7.6-windows-x86
+set PM_PYTHON=%PM_PYTHON_DIR%\python.exe
+
+if exist %PM_PYTHON% goto PACKMAN
+
+set TARGET=%TEMP%\%PM_PYTHON_PACKAGE%
+echo Fetching %PM_PYTHON_PACKAGE% from S3 ...
+powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File %~dp0\fetch_file_from_s3.ps1 -sourceName %PM_PYTHON_PACKAGE% -output %TARGET%
+:: A bug in powershell prevents the errorlevel code from being set when using the -File execution option
+if errorlevel 1 goto ERROR
+
+echo Unpacking ...
+%TARGET% -o%PM_PYTHON_DIR% -y
+if errorlevel 1 goto ERROR
+
+del %TARGET%
+
+:PACKMAN
+:: The packman module may already be externally configured
+if defined PM_MODULE_EXT (
+ set PM_MODULE=%PM_MODULE_EXT%
+ goto END
+)
+
+set PM_MODULE_DIR=%PM_PACKAGES_ROOT%\packman\%PM_PACKMAN_VERSION%-common
+set PM_MODULE=%PM_MODULE_DIR%\packman.py
+
+if exist %PM_MODULE% goto END
+
+set PM_MODULE_PACKAGE=packman@%PM_PACKMAN_VERSION%-common.zip
+set TARGET=%TEMP%\%PM_MODULE_PACKAGE%
+echo Fetching %PM_MODULE_PACKAGE% from S3 ...
+powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File %~dp0\fetch_file_from_s3.ps1 -sourceName %PM_MODULE_PACKAGE% -output %TARGET%
+:: A bug in powershell prevents the errorlevel code from being set when using the -File execution option
+if errorlevel 1 goto ERROR
+
+echo Unpacking ...
+%PM_PYTHON% %~dp0\install_package.py %TARGET% %PM_MODULE_DIR%
+if errorlevel 1 goto ERROR
+
+del %TARGET%
+
+goto END
+
+:ERROR
+echo !!! Failure while configuring local machine :( !!!
+
+:END
diff --git a/packman/windows/configure/fetch_file_from_s3.ps1 b/packman/windows/configure/fetch_file_from_s3.ps1
new file mode 100644
index 0000000..9e1b457
--- /dev/null
+++ b/packman/windows/configure/fetch_file_from_s3.ps1
@@ -0,0 +1,43 @@
+param(
+[Parameter(Mandatory=$true)][string]$sourceName=$null,
+[string]$output="out.exe"
+)
+$source = "http://packman.s3.amazonaws.com/" + $sourceName
+$filename = $output
+#$key64 = 'QHV0ME1AdDNHVEwkY3IxcHQk'
+#$key = [System.Text.Encoding]::GetEncoding(1252).GetString([Convert]::FromBase64String($key64))
+#$key = $key | ConvertTo-SecureString -asPlainText -Force
+#$credential = New-Object System.Management.Automation.PSCredential('svcgtlautomate', $key)
+#$cache = New-Object System.Net.CredentialCache
+#$cache.Add( "http://sso.nvidia.com", "NTLM", $credential)
+
+$req = [System.Net.httpwebrequest]::Create($source)
+$req.cookiecontainer = New-Object System.net.CookieContainer
+#$req.Credentials = $cache
+Write-Host "Connecting to S3 ..."
+$res = $req.GetResponse()
+
+if($res.StatusCode -eq "OK") {
+ Write-Host "Initiating download ..."
+ [int]$goal = $res.ContentLength
+ $reader = $res.GetResponseStream()
+ $writer = new-object System.IO.FileStream $fileName, "Create"
+ [byte[]]$buffer = new-object byte[] 4096
+ [int]$total = [int]$count = 0
+ do
+ {
+ $count = $reader.Read($buffer, 0, $buffer.Length);
+ $writer.Write($buffer, 0, $count);
+ $total += $count
+ if($goal -gt 0) {
+ Write-Progress "Downloading $url" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100)
+ } else {
+ Write-Progress "Downloading $url" "Saving $total bytes..." -id 0
+ }
+ } while ($count -gt 0)
+
+ $reader.Close()
+ $writer.Flush()
+ $writer.Close()
+}
+
diff --git a/packman/windows/configure/install_package.py b/packman/windows/configure/install_package.py
new file mode 100644
index 0000000..5e30a03
--- /dev/null
+++ b/packman/windows/configure/install_package.py
@@ -0,0 +1,41 @@
+import logging
+import zipfile
+import tempfile
+import sys
+import shutil
+
+__author__ = 'hfannar'
+logging.basicConfig(level=logging.WARNING, format="%(message)s")
+logger = logging.getLogger('install_package')
+
+
+class TemporaryDirectory:
+ def __init__(self):
+ self.path = None
+
+ def __enter__(self):
+ self.path = tempfile.mkdtemp()
+ return self.path
+
+ def __exit__(self, type, value, traceback ):
+ # Remove temporary data created
+ shutil.rmtree(self.path)
+
+
+def install_package(package_src_path, package_dst_path):
+ with zipfile.ZipFile(package_src_path, allowZip64=True) as zip_file, TemporaryDirectory() as temp_dir:
+ zip_file.extractall(temp_dir)
+ # Recursively copy (temp_dir will be automatically cleaned up on exit)
+ try:
+ # Recursive copy is needed because both package name and version folder could be missing in
+ # target directory:
+ shutil.copytree(temp_dir, package_dst_path)
+ except OSError, exc:
+ logger.warning("Directory %s already present, unpacking failed (Exception message: %s)" %
+ (package_dst_path, exc.strerror))
+ raise
+ else:
+ logger.info("Package successfully installed to %s" % package_dst_path)
+
+
+install_package(sys.argv[1], sys.argv[2]) \ No newline at end of file
diff --git a/packman/windows/packman.cmd b/packman/windows/packman.cmd
new file mode 100644
index 0000000..e768674
--- /dev/null
+++ b/packman/windows/packman.cmd
@@ -0,0 +1,18 @@
+@echo off
+:: You can remove the call below if you do your own manual configuration of the dev machines
+call %~dp0\configure\configure_s3.bat
+:: Everything below is mandatory
+if not defined PM_PYTHON goto :PYTHON_ENV_ERROR
+if not defined PM_MODULE goto :MODULE_ENV_ERROR
+
+%PM_PYTHON% %PM_MODULE% %*
+goto :END
+
+:PYTHON_ENV_ERROR
+echo User environment variable PM_PYTHON is not set! Please configure machine for packman or call configure.bat.
+goto :END
+
+:MODULE_ENV_ERROR
+echo User environment variable PM_MODULE is not set! Please configure machine for packman or call configure.bat.
+
+:END