Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Created September 26, 2013 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewconnell/6713804 to your computer and use it in GitHub Desktop.
Save andrewconnell/6713804 to your computer and use it in GitHub Desktop.
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Script: StageModule.ps1
#
# Author: Andrew Connell
# http://www.AndrewConnell.com
#
# Description: Extracts a course module assets for submission to Pluralsight.
#
# Parameters: $VideoClipStorePath - Fully qualified path to the location where the video clips are stored
# $BuildPath - Fully qualified path to the location where the files will be staged
# ex: "D:\CourseBuilds"
# $CourseId - Unique ID of the course in TFS
# ex: "cpt-sp2013-dev-ramp-part1"
# $ModuleNumber - the number of the module
# Optional Parameters:
# $RootSourcePath - Fully qualified path to the root location in TFS where courses are stored
# ex: "D:\Dev\ACI\zPluralsight\Main"
# Sample usage:
# .\StageCourse.ps1
# -BuildPath "D:\Temp"
# -CourseId "cpt-sp2013-dev-ramp-part1"
# -VideoClipStorePath "\\rivercity-nas1\Work\Clients\Pluralsight\Courses-cpt\cpt-sp2013-dev-ramp-part-REFRESH\produced"
# -ModuleNumber 1
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
param(
[string]$VideoClipStorePath,
[string]$RootSourcePath = "D:\Dev\ACI\zPluralsight\Main",
[string]$BuildPath,
[string]$CourseId,
[int]$ModuleNumber
)
$ErrorActionPreference = 'Stop'
# get reference to logging script & load
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$loggerScriptPath = Join-Path -Path $scriptPath -ChildPath "Logger.ps1"
. $loggerScriptPath
# -----------------------------------------------
# verify parameters
LogSection "Verifying Script Parameters"
LogInfo 'Validating parameter $RootSourcePath'
$pathExists = Test-Path -Path $RootSourcePath
if ($pathExists -ne $true){
LogError " Path does not exist; Terminal Error"
Exit
} else { LogInfo "..parameter valid" }
LogInfo 'Validating parameter $BuildPath'
$pathExists = Test-Path -Path $BuildPath
if ($pathExists -ne $true){
LogError " Path does not exist; Terminal Error"
Exit
} else { LogInfo "..parameter valid" }
LogInfo 'Validating parameter $VideoClipStorePath'
$pathExists = Test-Path -Path $VideoClipStorePath
if ($pathExists -ne $true){
LogError " Path does not exist; Terminal Error"
Exit
} else { LogInfo "..parameter valid" }
LogHighlight "Script parameters verified"
# -----------------------------------------------
# get paths
LogSection "Preparing Course Path"
#source course path
$CourseSourcePath = Join-Path -Path $RootSourcePath -ChildPath $CourseId
LogInfo "Course source path: $CourseSourcePath"
$pathExists = Test-Path -Path $CourseSourcePath
if ($pathExists -ne $true){
LogError "Path doesn't exist"
Exit
} else { LogInfo "..path verified" }
# stage course path
$CourseTargetPath = Join-Path -Path $BuildPath -ChildPath $CourseId
$CourseTargetPath = $CourseTargetPath.ToLower()
LogInfo "Course target staging path: $CourseTargetPath"
$pathExists = Test-Path -Path $CourseTargetPath
if ($pathExists -eq $true){
LogInfo "..target course staging path already exists"
} else {
LogInfo "..creating path: $CourseTargetPath"
New-Item -Path $CourseTargetPath -ItemType Directory | Out-Null
# test path creation
$pathExists = Test-Path -Path $CourseTargetPath
if ($pathExists -ne $true){
LogError "Failed creating the path"
Exit
} else { LogHighlight "..path created & verified" }
}
LogHighlight "Target path prepared"
# -----------------------------------------------
LogSection "Capturing Course Metadata File"
$courseSourceMetaFilePath = Join-Path -Path $CourseSourcePath -ChildPath "course.meta"
# verify source course metadata file exists
$pathExists = Test-Path -Path $courseSourceMetaFilePath
if ($pathExists -ne $true){
LogError "Course metadata file not found: $sourceFilePath"
Exit
}
$targetFilePath = Join-Path -Path $CourseTargetPath -ChildPath "$CourseId.meta"
# copy course metadata file to target
LogInfo "Verifying course metadata file staged.."
$pathExists = Test-Path -Path $targetFilePath
if ($pathExists -ne $true){
LogWarning "..course metadata file missing"
LogInfo "..copying FROM $sourceFilePath"
LogInfo "..copying TO $targetFilePath"
Copy-Item -Path $courseSourceMetaFilePath -Destination $targetFilePath
LogInfo "Course metadata file staged"
}
LogHighlight "Verified course metadata file staged"
# -----------------------------------------------
LogSection "Capturing Module to Process"
# find target module ID
LogInfo "Searching for module ID from specified module number.."
$courseModuleIds = ([xml](Get-Content -Path $courseSourceMetaFilePath)).course.modules.module
$moduleIndex = 0
$targetModuleId = ""
$courseModuleIds | ForEach-Object {
$moduleIndex = $moduleIndex+1
if ($moduleIndex -eq $ModuleNumber) {
$TargetModuleId = $_.name
LogInfo "..found module ID = $targetModuleId"
}
}
# check if module ID found
if ($TargetModuleId -eq "") {
LogError "Failed to obtain reference to specified module number ($ModuleNumber)"
Exit
}
LogInfo "..obtaining reference to module metadata file"
$ModuleSourePath = Join-Path -Path $CourseSourcePath -ChildPath $TargetModuleId
$moduleSourceMetaFilePath = Join-Path -Path $ModuleSourePath -ChildPath "module.meta"
LogInfo "..verifying module metadata file source exists.."
$pathExists = Test-Path -Path $moduleSourceMetaFilePath
if ($pathExists -ne $true){
LogError "Module metadata file not found"
Exit
}
LogHighlight "Obtained reference to module ID & metadata file"
# -----------------------------------------------
LogSection "Preparing Module Path"
# stage module path
$ModuleTargetPath = Join-Path -Path $BuildPath -ChildPath $CourseId
$ModuleTargetPath = Join-Path -Path $ModuleTargetPath -ChildPath $TargetModuleId
$ModuleTargetPath = $ModuleTargetPath.ToLower()
LogInfo "Module target staging path: $ModuleTargetPath"
$pathExists = Test-Path -Path $ModuleTargetPath
if ($pathExists -eq $true){
LogWarning "..target module path already exists"
LogInfo "..removing previously staged module"
Remove-Item -Path $ModuleTargetPath -Recurse -Confirm:$false
LogInfo "..previously staged module removed"
}
LogInfo "..creating path: $ModuleTargetPath"
New-Item -Path $ModuleTargetPath -ItemType Directory | Out-Null
# test path creation
$pathExists = Test-Path -Path $ModuleTargetPath
if ($pathExists -ne $true){
LogError "Failed creating the path"
Exit
} else { LogHighlight "..path created & verified" }
LogHighlight "Target path prepared"
# -----------------------------------------------
LogSection "Processing Module"
# capture module metadata file
LogInfo "Capturing course metadata file"
$sourceFilePath = Join-Path -Path $ModuleSourePath -ChildPath "module.meta"
#LogInfo "..module metadata path: $sourceFilePath"
$targetFilePath = Join-Path -Path $ModuleTargetPath -ChildPath "$TargetModuleId.meta"
Copy-Item -Path $sourceFilePath -Destination $targetFilePath
LogHighlight "..module metadata file captured"
# capture module slides
Write-Host
LogInfo "Capturing module slides file"
$sourceFilePath = Join-Path -Path $ModuleSourePath -ChildPath "slides.pptx"
#LogInfo "..module slides path: $sourceFilePath"
$targetFilePath = Join-Path -Path $ModuleTargetPath -ChildPath "slides.pptx"
Copy-Item -Path $sourceFilePath -Destination $targetFilePath
LogHighlight "..module slides file captured"
# capture module assessment questions
Write-Host
LogInfo "Capturing module assessment questions file"
$sourceFilePath = Join-Path -Path $ModuleSourePath -ChildPath "questions.txt"
$pathExists = Test-Path -Path $sourceFilePath
if ($pathExists -eq $true) {
LogInfo "..capturing assessment questions"
$targetFilePath = Join-Path -Path $ModuleTargetPath -ChildPath "questions.txt"
Copy-Item -Path $sourceFilePath -Destination $targetFilePath
LogHighlight "..captured assessment questions"
} else {LogInfo "..no assessment questions found... skipping step"}
# capture exercise files
LogInfo "Capturing module exercises files"
$tempExerciseFolderPath = Join-Path -Path $Env:TEMP -ChildPath $TargetModuleId
# if the path exists, delete it
$pathExists = Test-Path -Path $tempExerciseFolderPath
if ($pathExists -eq $true) {
LogInfo "..temp folder already present... deleting it"
Remove-Item -Path $tempExerciseFolderPath -Recurse -Confirm:$false
}
$moduleHasExerciseFiles = $false
# copy before exercise files if they exist
$sourceModuleExerciseFiles = Join-Path -Path $ModuleSourePath -ChildPath "ExBefore"
$pathExists = Test-Path -Path $sourceModuleExerciseFiles
if ($pathExists -eq $true){
$moduleHasExerciseFiles = $true
LogInfo "..capturing before exercise files to temp location"
$targetModuleExerciseFiles = Join-Path -Path $tempExerciseFolderPath -ChildPath "Before"
$targetModuleExerciseFiles = $targetModuleExerciseFiles.ToLower()
Copy-Item -Path $sourceModuleExerciseFiles -Destination $targetModuleExerciseFiles -Recurse
LogHighlight "..captured before exercise files to temp location"
} else {LogInfo "..no before exercise files found... skipping step"}
# copy after exercise files if they exist
$sourceModuleExerciseFiles = Join-Path -Path $ModuleSourePath -ChildPath "ExAfter"
$pathExists = Test-Path -Path $sourceModuleExerciseFiles
if ($pathExists -eq $true){
$moduleHasExerciseFiles = $true
LogInfo "..capturing before exercise files to temp location"
$targetModuleExerciseFiles = Join-Path -Path $tempExerciseFolderPath -ChildPath "After"
$targetModuleExerciseFiles = $targetModuleExerciseFiles.ToLower()
Copy-Item -Path $sourceModuleExerciseFiles -Destination $targetModuleExerciseFiles -Recurse
LogHighlight "..captured before exercise files to temp location"
} else {LogInfo "..no after exercise files found... skipping step"}
# zip exercise files
if ($moduleHasExerciseFiles -eq $true){
LogInfo "..loading ZIP compression library"
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
LogHighlight "..ZIP compression library loaded"
$targetExerciseFilesZipPath = Join-Path -Path $ModuleTargetPath -ChildPath "demos.zip"
$targetExerciseFilesZipPath = $targetExerciseFilesZipPath.ToLower()
LogInfo "..compressing module exercise files to staging location"
[System.IO.Compression.ZipFile]::CreateFromDirectory($tempExerciseFolderPath, $targetExerciseFilesZipPath)
LogHighlight "..module exercise files zipped and saved in staging folder"
} else {
LogInfo "..no exercise files present for module... skipping ZIP step"
LogInfo "..creating 'no-demos.txt' placeholder"
$targetExerciseFilesZipPath = Join-Path -Path $ModuleTargetPath -ChildPath "no-demos.txt"
New-Item $targetExerciseFilesZipPath -type file | Out-Null
LogHighlight "..created 'no-demos' file"
}
# capture video files
Write-Host
LogInfo "Capturing module video clips"
# load the module metadata file
$sourceFilePath = Join-Path -Path $ModuleSourePath -ChildPath "module.meta"
$moduleVideoClips = ([xml](Get-Content -Path $sourceFilePath)).module.clips.clip
$moduleVideoClips | ForEach-Object{
$clipName = $_.href
LogInfo "..processing clip $clipName"
$clipSourcePath = Join-Path -Path $VideoClipStorePath -ChildPath $clipName
$clipTargetPath = Join-Path -Path $ModuleTargetPath -ChildPath $clipName
$clipTargetPath = $clipTargetPath.ToLower()
# verify the video path exists
$pathExists = Test-Path -Path $clipSourcePath
if ($pathExists -eq $true){
LogInfo "..capturing clip $clipName"
Copy-Item -Path $clipSourcePath -Destination $clipTargetPath
LogHighlight "..captured clip $clipName"
} else {LogWarning "..clip not found in source"}
# copy video path locally
}
# -----------------------------------------------
Write-Host
LogSuccess "Module staged successfully!"
Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment