Skip to content

Commit

Permalink
Fix blank line issues on Ubuntu/PowerShell 7 (#137)
Browse files Browse the repository at this point in the history
* fix phantom lines when using linux

* change from arraylist to array as arraylist are deprecated
  • Loading branch information
RichieBzzzt committed Sep 25, 2020
1 parent c5ee8c6 commit d141f28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
11 changes: 6 additions & 5 deletions Private/Get-Notebooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ Function Get-Notebooks ($FolderContents, $OriginalPath, $LocalOutputPath, $Forma
$scriptBlock = { param($DatabricksFile, $Format = "SOURCE", $Headers, $uri, $LocalExportPath, $tempLocalExportPath)
Try {
New-Item -Force -path $tempLocalExportPath -Type File | Out-Null
Invoke-RestMethod -Method Get -Uri $uri -Headers $Headers -OutFile $tempLocalExportPath
$Response = Get-Content $tempLocalExportPath -Encoding UTF8
$Response = $response.Replace("# Databricks notebook source", " ")
Invoke-RestMethod -Method Get -Uri $uri -Headers $Headers -OutFile $tempLocalExportPath
$Response = @()
$Response = Get-Content $tempLocalExportPath -Encoding UTF8
$NewResponse = $Response -ne "# Databricks notebook source"
Remove-Item $tempLocalExportPath
if ($Format -eq "SOURCE") {
$Response = ($Response.replace("[^`r]`n", "`r`n") -Join "`r`n")

This comment has been minimized.

Copy link
@pmooij

pmooij Oct 20, 2020

@RichieBzzzt why are you changing ALL line ending normalization from CRLF to LF? this negatively affects all our exports now as we're exporting on Windows environment and also our Git configurations are normalized to CRLF.
so comparing against any other (CRLF normalised) feature branch leads to LF line ending issues now, whereas we didn't had that before.
could you redo this smartly? i.e. normalise to CRLF on windows and normalise to LF on linux enviroments?

$ResponseString = ($NewResponse.replace("[^`r]`n", "`n") -Join "`n")
}
New-Item -force -path $LocalExportPath -value $Response -type file | out-null
New-Item -force -path $LocalExportPath -value $ResponseString -type file | Out-Null
}
Catch {
Write-Error $_.ErrorDetails.Message
Expand Down
22 changes: 13 additions & 9 deletions Public/Import-DatabricksFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Function Import-DatabricksFolder {
# A 404 response is expected if the specified workspace does not exist in Databricks
# In this case, there will be no existing files to clean so the exception can be safely ignored
}
foreach ($f in $ExistingFiles){
if ($f.object_type -eq "DIRECTORY"){
foreach ($f in $ExistingFiles) {
if ($f.object_type -eq "DIRECTORY") {
Write-Verbose "Removing directory $($f.path)"
Remove-DatabricksNotebook -Path $f.path -Recursive
}
Expand Down Expand Up @@ -86,8 +86,12 @@ Function Import-DatabricksFolder {
# Create folder in Databricks
Add-DatabricksFolder -Path $Path
Write-Verbose "Path: $Path"

$BinaryContents = [System.IO.File]::ReadAllBytes($FileToPush.FullName)
if ($PSVersionTable.PSVersion.Major -lt 6) {
$BinaryContents = [System.IO.File]::ReadAllBytes($FileToPush.FullName)
}
else {
$BinaryContents = Get-Content $FileToPush.FullName -AsByteStream -ReadCount 0
}
$EncodedContents = [System.Convert]::ToBase64String($BinaryContents)
$TargetPath = $Path + '/' + $FileToPush.BaseName

Expand Down Expand Up @@ -137,30 +141,30 @@ Function Import-DatabricksFolder {
}
else {
Write-Verbose "Pushing file $FileToPush to $TargetPath"
$ProgressPreference ='SilentlyContinue'
$ProgressPreference = 'SilentlyContinue'
$threadJobs += Start-ThreadJob -Name $fileToPush -ScriptBlock { Invoke-RestMethod -Uri $args[0] -Body $args[1] -Method 'POST' -Headers $args[2] } -ArgumentList "$global:DatabricksURI/api/2.0/workspace/import", $BodyText, $Headers -ThrottleLimit $throttleLimit
}
}

if ($threadJobs.length -eq 0){
if ($threadJobs.length -eq 0) {
Pop-Location
return
}

Wait-Job -Job $threadJobs | Out-Null
$toThrow = $null
foreach ($threadJob in $threadJobs){
foreach ($threadJob in $threadJobs) {
$getState = Get-Job $threadJob.Name | Select-Object -Last 1
if ($getState.State -eq 'Failed') {
$toThrow = 1
Write-Host ($threadJob.ChildJobs[0].JobStateInfo.Reason.Message) -ForegroundColor Red
}
else{
else {
Write-Verbose "$($getState.Name) has $($getState.State)"
}
}
Pop-Location
if ($null -ne $toThrow){
if ($null -ne $toThrow) {
Write-Error "Oh dear one of the jobs has failed. Check the details of the jobs above."
}
}

0 comments on commit d141f28

Please sign in to comment.