aboutsummaryrefslogtreecommitdiff
path: root/buildtools/packman/win-bootstrap
diff options
context:
space:
mode:
authorAnton Novoselov <[email protected]>2017-08-01 12:53:38 +0300
committerAnton Novoselov <[email protected]>2017-08-01 12:53:38 +0300
commit236f03c0b9a4982328ed1201978f7f69d192d9b2 (patch)
treee486f2fa39dba203563895541e92c60ed3e25759 /buildtools/packman/win-bootstrap
parentAdded screens to welcome page (diff)
downloadblast-236f03c0b9a4982328ed1201978f7f69d192d9b2.tar.xz
blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.zip
Blast 1.1 release (windows / linux)
see docs/release_notes.txt for details
Diffstat (limited to 'buildtools/packman/win-bootstrap')
-rw-r--r--buildtools/packman/win-bootstrap/configure.bat104
-rw-r--r--buildtools/packman/win-bootstrap/fetch_file.cmd23
-rw-r--r--buildtools/packman/win-bootstrap/fetch_file_from_s3.ps137
-rw-r--r--buildtools/packman/win-bootstrap/fetch_file_from_url.ps137
-rw-r--r--buildtools/packman/win-bootstrap/generate_temp_file_name.ps12
-rw-r--r--buildtools/packman/win-bootstrap/install_package.py39
6 files changed, 242 insertions, 0 deletions
diff --git a/buildtools/packman/win-bootstrap/configure.bat b/buildtools/packman/win-bootstrap/configure.bat
new file mode 100644
index 0000000..8f3d7b8
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/configure.bat
@@ -0,0 +1,104 @@
+@set PM_PACKMAN_VERSION=4.0-rc3
+
+:: Specify where config file could exist
+@set PM_CONFIG_PATH=%~dp0..\packman_config.txt
+
+:: 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%\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
+
+:: The above doesn't work properly from a build step in VisualStudio because a separate process is
+:: spawned for it so it will be lost for subsequent compilation steps - VisualStudio must
+:: be launched from a new process. We catch this odd-ball case here:
+@if defined VSLANG goto ERROR_IN_VS_WITH_NO_ROOT_DEFINED
+
+:: 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%"
+ @if errorlevel 1 goto ERROR_MKDIR_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
+
+@for /f "delims=" %%a in ('powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0\generate_temp_file_name.ps1"') do @set TEMP_FILE_NAME=%%a
+@set TARGET=%TEMP_FILE_NAME%.exe
+@call "%~dp0fetch_file.cmd" s3 %PM_PYTHON_PACKAGE% UNUSED_BOGUS_GUID %TARGET%
+@if errorlevel 1 goto ERROR
+
+@echo Unpacking ...
+@%TARGET% -o"%PM_PYTHON_DIR%" -y 1> nul
+@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
+@for /f "delims=" %%a in ('powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0\generate_temp_file_name.ps1"') do @set TEMP_FILE_NAME=%%a
+@set TARGET=%TEMP_FILE_NAME%
+@call "%~dp0fetch_file.cmd" s3 %PM_MODULE_PACKAGE% UNUSED_BOGUS_GUID %TARGET%
+@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_IN_VS_WITH_NO_ROOT_DEFINED
+@echo The above is a once-per-computer operation. Unfortunately VisualStudio cannot pick up environment change
+@echo unless *VisualStudio is RELAUNCHED*.
+@echo NOTE: If you are launching VisualStudio from command line or command line utility make sure
+@echo you have a fresh environment (relaunch the command line or utility).
+@echo.
+@exit /B 1
+
+:ERROR_MKDIR_PACKAGES_ROOT
+@echo Failed to automatically create packman packages repo at %PM_PACKAGES_ROOT%.
+@echo Please set a location explicitly that packman has permission to write to, by issuing:
+@echo.
+@echo setx PM_PACKAGES_ROOT {path-you-choose-for-storing-packman-packages-locally}
+@echo.
+@echo Then launch a new command console for the changes to take effect and run packman command again.
+@exit /B 1
+
+:ERROR
+@echo !!! Failure while configuring local machine :( !!!
+@exit /B 1
+
+:END
diff --git a/buildtools/packman/win-bootstrap/fetch_file.cmd b/buildtools/packman/win-bootstrap/fetch_file.cmd
new file mode 100644
index 0000000..298b6a0
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/fetch_file.cmd
@@ -0,0 +1,23 @@
+:: You need to specify <package-source> <package-name> <package-guid> <target-name> as input to this command
+
+@set PACKAGE_NAME=%2
+@set PACKAGE_GUID=%3
+@set TARGET=%4
+
+@echo Fetching %PACKAGE_NAME% from %1 ...
+
+@if ["%1"] EQU ["s3"] set SOURCE_OPT=-sourceName %PACKAGE_NAME%
+@if ["%1"] EQU ["gtl"] set SOURCE_OPT=-sourceGUID %PACKAGE_GUID%
+
+@powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0fetch_file_from_%1.ps1" %SOURCE_OPT% -output %TARGET%
+:: A bug in powershell prevents the errorlevel code from being set when using the -File execution option
+:: We must therefore do our own failure analysis, basically make sure the file exists and is larger than 0 bytes:
+@if not exist %TARGET% goto ERROR_DOWNLOAD_FAILED
+@if %~z4==0 goto ERROR_DOWNLOAD_FAILED
+
+@exit /b 0
+
+:ERROR_DOWNLOAD_FAILED
+@echo Failed to download file from %1
+@echo Most likely because endpoint cannot be reached (VPN connection down?)
+@exit /b 1 \ No newline at end of file
diff --git a/buildtools/packman/win-bootstrap/fetch_file_from_s3.ps1 b/buildtools/packman/win-bootstrap/fetch_file_from_s3.ps1
new file mode 100644
index 0000000..e424058
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/fetch_file_from_s3.ps1
@@ -0,0 +1,37 @@
+param(
+[Parameter(Mandatory=$true)][string]$sourceName=$null,
+[string]$output="out.exe"
+)
+$source = "http://packman.s3.amazonaws.com/" + $sourceName
+$filename = $output
+
+$req = [System.Net.httpwebrequest]::Create($source)
+$req.cookiecontainer = New-Object System.net.CookieContainer
+
+Write-Host "Connecting to S3 ..."
+$res = $req.GetResponse()
+
+if($res.StatusCode -eq "OK") {
+ Write-Host "Downloading ..."
+ [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/buildtools/packman/win-bootstrap/fetch_file_from_url.ps1 b/buildtools/packman/win-bootstrap/fetch_file_from_url.ps1
new file mode 100644
index 0000000..5b566f1
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/fetch_file_from_url.ps1
@@ -0,0 +1,37 @@
+param(
+[Parameter(Mandatory=$true)][string]$sourceUrl=$null,
+[Parameter(Mandatory=$true)][string]$output=$null
+)
+$source = $sourceUrl
+$filename = $output
+
+$req = [System.Net.httpwebrequest]::Create($source)
+$req.cookiecontainer = New-Object System.net.CookieContainer
+
+Write-Host "Connecting to $source ..."
+$res = $req.GetResponse()
+
+if($res.StatusCode -eq "OK") {
+ Write-Host "Downloading ..."
+ [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/buildtools/packman/win-bootstrap/generate_temp_file_name.ps1 b/buildtools/packman/win-bootstrap/generate_temp_file_name.ps1
new file mode 100644
index 0000000..cefbda4
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/generate_temp_file_name.ps1
@@ -0,0 +1,2 @@
+$out = [System.IO.Path]::GetTempFileName()
+Write-Host $out \ No newline at end of file
diff --git a/buildtools/packman/win-bootstrap/install_package.py b/buildtools/packman/win-bootstrap/install_package.py
new file mode 100644
index 0000000..730962a
--- /dev/null
+++ b/buildtools/packman/win-bootstrap/install_package.py
@@ -0,0 +1,39 @@
+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, packaged installation aborted" % package_dst_path)
+ 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