-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
|
||
const POWERSYSTEMSTESTDATA_GITHUB_URL = "https://github.com/NREL/PowerSystemsTestData.git" | ||
include(joinpath(@__DIR__, "../src/utils/data.jl")) | ||
using .UtilsData | ||
|
||
base_dir = string(dirname(dirname(@__FILE__))) | ||
const DATA_FOLDER = joinpath(base_dir,"data") | ||
|
||
const CLONE_CMD = `git clone --depth 1 $POWERSYSTEMSTESTDATA_GITHUB_URL $DATA_FOLDER` | ||
|
||
const PULL_CMD = `git -C $DATA_FOLDER pull` | ||
|
||
function download_data() | ||
|
||
if !isdir(DATA_FOLDER) | ||
run(CLONE_CMD) | ||
else | ||
run(PULL_CMD) | ||
end | ||
|
||
end | ||
|
||
download_data() | ||
download(TestData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# this file is included in the build.jl script | ||
|
||
module UtilsData | ||
|
||
__precompile__(true) | ||
|
||
export TestData | ||
|
||
abstract type AbstractOS end | ||
abstract type Unix <: AbstractOS end | ||
abstract type BSD <: Unix end | ||
|
||
abstract type Windows <: AbstractOS end | ||
abstract type MacOS <: BSD end | ||
abstract type Linux <: BSD end | ||
|
||
if Sys.iswindows() | ||
const os = Windows | ||
elseif Sys.isapple() | ||
const os = MacOS | ||
else | ||
const os = Linux | ||
end | ||
|
||
abstract type TestData end | ||
|
||
if Sys.iswindows() | ||
const POWERSYSTEMSTESTDATA_URL = "https://github.com/NREL/PowerSystemsTestData/archive/master.zip" | ||
else | ||
const POWERSYSTEMSTESTDATA_URL = "https://github.com/NREL/PowerSystemsTestData/archive/master.tar.gz" | ||
end | ||
|
||
""" | ||
Download Power System Data into a "data" folder in given argument path. | ||
Defaults to the root of the PowerSystems package. | ||
Returns the downloaded folder name. | ||
""" | ||
function Base.download(::Type{TestData}, folder::AbstractString=joinpath(@__DIR__, "../..") |> abspath) | ||
tempfilename = Base.download(POWERSYSTEMSTESTDATA_URL) | ||
directory = folder |> normpath |> abspath | ||
mkpath(directory) | ||
unzip(os, tempfilename, directory) | ||
mv(joinpath(directory, "PowerSystemsTestData-master"), joinpath(directory, "data"), force=true) | ||
return joinpath(directory, "data") | ||
end | ||
|
||
function unzip(::Type{<:BSD}, filename, directory) | ||
@assert success(`tar -xvf $filename -C $directory`) "Unable to extract $filename to $directory" | ||
end | ||
|
||
function unzip(::Type{Windows}, filename, directory) | ||
home = (Base.VERSION < v"0.7-") ? JULIA_HOME : Sys.BINDIR | ||
@assert success(`$home/7z x $filename -y -o$directory`) "Unable to extract $filename to $directory" | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
@testset "TestData" begin | ||
|
||
@test download(PowerSystems.TestData) |> abspath == joinpath(@__DIR__, "../data") |> abspath | ||
|
||
end # testset | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters