Skip to content

Instantly share code, notes, and snippets.

@71
Last active November 17, 2017 15:24
Show Gist options
  • Save 71/2c95536941ae07bf5e13d68a706cc2f4 to your computer and use it in GitHub Desktop.
Save 71/2c95536941ae07bf5e13d68a706cc2f4 to your computer and use it in GitHub Desktop.
Make an EPITA submission using PowerShell.
<#
.SYNOPSIS
Creates a .zip file matching the submission format required by EPITA.
.EXAMPLE
Make-Submission -Author gregoire.geis -Nth 0 -Items ./TP0 -Exclude bin,obj -ReadMe "First submission!"
Make-Submission -Author gregoire.geis -Nth 0 -Items tp0.ml
#>
function Make-Submission (
[Parameter(Mandatory=$true)] [string] $Author,
[Parameter(Mandatory=$true)] [int] $Nth,
[Parameter(Mandatory=$true)] [string[]] $Items,
[string[]] $Include,
[string[]] $Exclude,
[string] $ReadMe = $null
) {
New-Item -Force -ItemType Directory -Path ./Tmp/$Author > $null
Set-Content ./Tmp/$Author/AUTHORS -Value "* $Author"
if ($ReadMe) {
Set-Content ./Tmp/$Author/README -Value "$ReadMe"
} else {
$RMFile = $Items | % { Get-ChildItem -File -Recurse -Path $_ -Include 'README','README.md' } | select -First 1
if ($RMFile) {
Set-Content ./Tmp/$Author/README -Value (Get-Content $RMFile)
} else {
Set-Content ./Tmp/$Author/README -Value "This archive was automatically generated by a program. Refer to [its source](https://gist.github.com/6A/2c95536941ae07bf5e13d68a706cc2f4) for more information."
}
}
foreach ($ItemName in $Items) {
$Item = Get-Item $ItemName
Get-ChildItem $Item -Recurse -Exclude $Exclude -Include $Include | % {
$NI = Join-Path ./Tmp/$Author $_.FullName.Substring($Item.Parent.FullName.Length)
New-Item -ItemType File $NI -Force > $null
Copy-Item $_ $NI -Force > $null
}
}
7z a -tzip "rendu-tp$Nth-$Author.zip" ./Tmp/$Author > $null
Remove-Item -Recurse -Path ./Tmp
Write-Host -ForegroundColor Green "[+] Archive successfully created as rendu-tp$Nth-$Author.zip"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment