Skip to content

Commit

Permalink
Updating to include NetRC.jl for setup of package
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Jun 24, 2022
1 parent 8bf28db commit 94135c4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: 1.3
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
GeoRegions = "b001f823-fa75-4bff-bf55-6610c8f3688a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NetRC = "4ceb92a4-8458-42c6-ac22-7a21adf6253e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -20,6 +21,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Downloads = "1"
GeoRegions = "^2.1"
NCDatasets = "0.11"
NetRC = "0.1"
Reexport = "1"
julia = "^1.6"

Expand Down
6 changes: 5 additions & 1 deletion src/NASAPrecipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module NASAPrecipitation
## Modules Used
using Logging
using NCDatasets
using NetRC
using Printf
using Statistics

Expand All @@ -25,7 +26,7 @@ export

getLandSea, addNPDGeoRegions,

download, read, npdfnc
download, read, npdfnc, setup

## Abstract types
"""
Expand Down Expand Up @@ -75,6 +76,7 @@ abstract type TRMMDataset <: NASAPrecipitationDataset end
modulelog() = "$(now()) - NASAPrecipitation.jl"

function __init__()
setup()
@info "$(modulelog()) - Checking to see if GeoRegions required by NASAPrecipitation.jl have been added to the list of available GeoRegions"
disable_logging(Logging.Warn)
if !isGeoRegion("IMERG",throw=false) ||
Expand All @@ -94,6 +96,8 @@ end

## Including Relevant Files

include("setup.jl")

include("IMERG/halfhourly.jl")
include("IMERG/daily.jl")
include("IMERG/monthly.jl")
Expand Down
49 changes: 49 additions & 0 deletions src/setup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function setup(;
login :: AbstractString = "",
password :: AbstractString = "",
overwrite :: Bool = false
)

fdodsrc = joinpath(homedir(),".dodsrc")
if !isfile(fdodsrc)
@info "$(modulelog()) - Setting up .dodsrc file for NASA OPeNDAP servers to point at cookie and .netrc directories ..."
open(fdodsrc,"w") do f
write(f,"HTTP.COOKIEJAR=$(joinpath(homedir(),".urs_cookies"))")
write(f,"HTTP.NETRC=$(joinpath(homedir(),".netrc"))")
end
else
if overwrite
@warn "$(modulelog()) - .dodsrc file exists at $fdodsrc, overwriting again"
open(fdodsrc,"w") do f
write(f,"HTTP.COOKIEJAR=$(joinpath(homedir(),".urs_cookies"))")
write(f,"HTTP.NETRC=$(joinpath(homedir(),".netrc"))")
end
else
@info "$(modulelog()) - .dodsrc file exists at $fdodsrc"
end
end

if !netrc_check()
if login == "" && password == ""
@warn "$(modulelog()) - .netrc file does not exist at $(netrc_file()), you need to setup the .netrc file in order for NASAPrecipitation.jl to work"
end
end

if netrc_check() && !netrc_checkmachine(netrc_read(logging=false),machine="urs.earthdata.nasa.gov")
if login == "" && password == ""
@warn "$(modulelog()) - No existing machine urs.earthdata.nasa.gov in .netrc file, please setup login and password for this machine for NASAPrecipitation.jl to work"
end
end

if login != "" && password != ""
@info "$(modulelog()) - Setting up .netrc file containing login and password information for NASA OPeNDAP servers ..."
netrc = netrc_read()
if netrc_check() && netrc_checkmachine(netrc,machine="urs.earthdata.nasa.gov")
netrc_modify!(netrc,machine="urs.earthdata.nasa.gov",login=login,password=password)
else
netrc_add!(netrc,machine="urs.earthdata.nasa.gov",login=login,password=password)
end
netrc_write(netrc)
end

end

2 comments on commit 94135c4

@natgeo-wong
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

  • Adding limits to date range
  • Better functionality for LandSea datasets
  • Updating to include NetRC.jl for the setup of .netrc and .dodsrc for the setup of the package

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/63040

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 94135c48cb7b8bd35598dfa8f2adeca52cbd0bf8
git push origin v0.1.2

Please sign in to comment.