|
| 1 | + |
| 2 | +# Check last updated time |
| 3 | +import Dates |
| 4 | + |
| 5 | +dates_now = Dates.now() |
| 6 | + |
| 7 | +update_required = false; |
| 8 | + |
| 9 | +if !isfile("checkupdate") |
| 10 | + update_required = true; |
| 11 | + Base.Filesystem.touch("checkupdate") |
| 12 | +else |
| 13 | + dates_lastchecked = Dates.unix2datetime(Base.Filesystem.mtime("checkupdate")) |
| 14 | + if (dates_now - dates_lastchecked > Dates.Day(7)) |
| 15 | + update_required = true; |
| 16 | + end |
| 17 | +end |
| 18 | +if update_required |
| 19 | + println(" Update required. Automatic update checking started") |
| 20 | + println(" Visit https://kaist-elst.github.io/DFTforge.jl/ for more update news.") |
| 21 | +end |
| 22 | + |
| 23 | +try |
| 24 | + # Download metainfo (https://raw.githubusercontent.com/KAIST-ELST/DFTforge.jl/master/Project.toml) |
| 25 | + metainfo_path = "https://github.com/KAIST-ELST/DFTforge.jl/raw/master/Project.toml" |
| 26 | + # If update is required, download and replace |
| 27 | + metadownload_path = download(metainfo_path); |
| 28 | + |
| 29 | + s_remote = open(metadownload_path) do f |
| 30 | + readlines(f) |
| 31 | + end |
| 32 | + |
| 33 | + s_local = open("Project.toml") do f |
| 34 | + readlines(f) |
| 35 | + end |
| 36 | + |
| 37 | + function getVersionNumber(s) |
| 38 | + version_remote = "" |
| 39 | + for i in 1:length(s) |
| 40 | + v = s[i] |
| 41 | + if occursin("version = ",v) |
| 42 | + a = split(v,[' ','"']; keepempty=false)[3] |
| 43 | + version_remote = VersionNumber(a) |
| 44 | + end |
| 45 | + end |
| 46 | + return version_remote |
| 47 | + end |
| 48 | + |
| 49 | + version_Remote = getVersionNumber(s_remote) |
| 50 | + version_Local = getVersionNumber(s_local) |
| 51 | + |
| 52 | + |
| 53 | + if version_Remote > version_Local |
| 54 | + Pkg.update("DFTforge") |
| 55 | + println(" New version: ",version_Remote, " current version: ", version_Local) |
| 56 | + println(" git pull github.com/KAIST-ELST/DFTforge.jl ") |
| 57 | + println(" Or visit https://kaist-elst.github.io/DFTforge.jl/ for update.") |
| 58 | + end |
| 59 | + |
| 60 | +# ziped src https://github.com/KAIST-ELST/DFTforge.jl/archive/master.zip |
| 61 | +finally |
| 62 | + |
| 63 | +end |
0 commit comments