Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit cb7a2fa

Browse files
hessammehrnalimilan
authored andcommitted
Add Julia 1.0 compatibility changes. (#158)
* Add Julia 1.0 compatibility changes. Basically change `warn` to `@warn`, `info` to `@info` and migrate iterators to the new format. * Make String => Array{UInt8} convesion 1.0 compatible. * Revise `iterate(::Packages)`. * Update `replace` to Julia 1.0 convention. More `replace` revisions. * Adapt to new `Process` API.
1 parent aa56cac commit cb7a2fa

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/WinRPM.jl

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ elseif iswindows()
6565
return read(filename, String), 200
6666
end
6767
else
68-
warn("Unknown download failure, error code: $res")
68+
@warn("Unknown download failure, error code: $res")
6969
end
70-
warn("Retry $i/$retry downloading: $source")
70+
@warn("Retry $i/$retry downloading: $source")
7171
end
7272
return "", 0
7373
end
@@ -145,16 +145,16 @@ function update(ignorecache::Bool=false, allow_remote::Bool=true)
145145
return read(path2, String)
146146
end
147147
if !allow_remote
148-
warn("skipping $path, not in cache -- call WinRPM.update() to download")
148+
@warn("skipping $path, not in cache -- call WinRPM.update() to download")
149149
return nothing
150150
end
151-
info("Downloading $source/$path")
151+
@info("Downloading $source/$path")
152152
data = download("$source/$path")
153153
if data[2] != 200
154-
warn("received error $(data[2]) while downloading $source/$path")
154+
@warn("received error $(data[2]) while downloading $source/$path")
155155
return nothing
156156
end
157-
body = gunzip ? Libz.decompress(convert(Vector{UInt8},data[1])) : data[1]
157+
body = gunzip ? Libz.decompress(Vector{UInt8}(data[1])) : data[1]
158158
open(path2, "w") do f
159159
write(f, body)
160160
end
@@ -211,9 +211,18 @@ Packages(xpath::LibExpat.XPath) = Packages(packages[xpath])
211211
getindex(pkg::Packages,x) = Package(getindex(pkg.p,x))
212212
Base.length(pkg::Packages) = length(pkg.p)
213213
Base.isempty(pkg::Packages) = isempty(pkg.p)
214-
Base.start(pkg::Packages) = start(pkg.p)
215-
Base.next(pkg::Packages,x) = ((p,s)=next(pkg.p,x); (Package(p),s))
216-
Base.done(pkg::Packages,x) = done(pkg.p,x)
214+
function Base.iterate(pkg::Packages)
215+
res = iterate(pkg.p)
216+
res === nothing && return res
217+
p, s = res
218+
(Package(p), s)
219+
end
220+
function Base.iterate(pkg::Packages, x)
221+
res = iterate(pkg.p, x)
222+
res === nothing && return res
223+
p, s = res
224+
(Package(p), s)
225+
end
217226

218227
function show(io::IO, pkg::Package)
219228
println(io,"WinRPM Package: ")
@@ -224,7 +233,7 @@ function show(io::IO, pkg::Package)
224233
println(io," Arch: ", LibExpat.string_value(pkg["arch"][1]))
225234
println(io," URL: ", LibExpat.string_value(pkg["url"][1]))
226235
println(io," License: ", LibExpat.string_value(pkg["format/rpm:license"][1]))
227-
print(io," Description: ", replace(LibExpat.string_value(pkg["description"][1]), r"\r\n|\r|\n", "\n "))
236+
print(io," Description: ", replace(LibExpat.string_value(pkg["description"][1]), r"\r\n|\r|\n" => "\n "))
228237
end
229238

230239
function show(io::IO, pkgs::Packages)
@@ -250,7 +259,7 @@ function select(pkgs::Packages, pkg::AbstractString)
250259
elseif length(pkgs) == 1
251260
pkg = pkgs[1]
252261
else
253-
info("Multiple package candidates found for $pkg, picking newest.")
262+
@info("Multiple package candidates found for $pkg, picking newest.")
254263
epochs = [getepoch(pkg) for pkg in pkgs]
255264
pkgs = pkgs[findall(in(maximum(epochs)), epochs)]
256265
if length(pkgs) > 1
@@ -286,7 +295,7 @@ function rpm_provides(requires::Union{Vector{T},Set{T}}) where T<:AbstractString
286295
for x in requires
287296
pkgs_ = rpm_provides(x)
288297
if isempty(pkgs_)
289-
warn("Package not found that provides $x")
298+
@warn("Package not found that provides $x")
290299
else
291300
push!(pkgs, select(pkgs_,x).pd)
292301
end
@@ -376,13 +385,13 @@ function install(pkg::Union{Package,Packages}; yes=false)
376385
@info("Nothing to do")
377386
else
378387
if !isempty(toup)
379-
info("Packages to update: ", join(names(toup), ", "))
388+
@info("Packages to update: ", join(names(toup), ", "))
380389
yesold = yes || prompt_ok("Continue with updates")
381390
else
382391
yesold = false
383392
end
384393
if !isempty(todo)
385-
info("Packages to install: ", join(names(todo), ", "))
394+
@info("Packages to install: ", join(names(todo), ", "))
386395
yesnew = yes || prompt_ok("Continue with install")
387396
else
388397
yesnew = false
@@ -410,7 +419,7 @@ function prepare_install(pkg::Union{Package,Packages})
410419
end
411420
toupdate = ETree[]
412421
filter!(packages) do p
413-
ver = replace(join(rpm_ver(p), ','), r"\s", "")
422+
ver = replace(join(rpm_ver(p), ','), r"\s" => "")
414423
oldver = false
415424
for entry in p[xpath"format/rpm:provides/rpm:entry[@name]"]
416425
provides = entry.attr["name"]
@@ -453,7 +462,7 @@ const exe7z = iswindows() ? joinpath(BINDIR, "7z.exe") : "7z"
453462
function do_install(package::Package)
454463
name = names(package)
455464
source, path = rpm_url(package)
456-
info("Downloading: ", name)
465+
@info("Downloading: ", name)
457466
data = download("$source/$path")
458467
if data[2] != 200
459468
@info("try running WinRPM.update() and retrying the install")
@@ -464,15 +473,16 @@ function do_install(package::Package)
464473
open(path2, "w") do f
465474
write(f, data[1])
466475
end
467-
info("Extracting: ", name)
476+
@info("Extracting: ", name)
468477

469478
cpio = splitext(joinpath(cache, escape(basename(path))))[1] * ".cpio"
470479

471480
local err = nothing
472481
for cmd = [`$exe7z x -y $path2 -o$cache`, `$exe7z x -y $cpio -o$installdir`]
473-
(out, pc) = open(cmd, "r")
482+
proc = open(cmd, "r")
483+
out, pc = proc.out, proc.exitcode
474484
stdoutstr = read(out, String)
475-
if !success(pc)
485+
if !success(proc)
476486
wait_close(out)
477487
println(stdoutstr)
478488
err = pc
@@ -489,7 +499,7 @@ function do_install(package::Package)
489499
end
490500
end
491501
isfile(cpio) && rm(cpio)
492-
ver = replace(join(rpm_ver(package), ','), r"\s", "")
502+
ver = replace(join(rpm_ver(package), ','), r"\s" => "")
493503
open(installedlist, isfile(installedlist) ? "r+" : "w+") do installed
494504
for entry in package[xpath"format/rpm:provides/rpm:entry[@name]"]
495505
provides = entry.attr["name"]

0 commit comments

Comments
 (0)