Remote tag querying for search and list.
This commit is contained in:
parent
2406776f89
commit
93a11fc9b9
2 changed files with 31 additions and 13 deletions
35
download.nim
35
download.nim
|
|
@ -67,11 +67,14 @@ proc getTagsList(dir: string, meth: TDownloadMethod): seq[string] =
|
||||||
else:
|
else:
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
||||||
proc getTagsListRemote(url: string, meth: TDownloadMethod): seq[string] =
|
proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
||||||
result = @[]
|
result = @[]
|
||||||
case meth
|
case meth
|
||||||
of TDownloadMethod.Git:
|
of TDownloadMethod.Git:
|
||||||
var output = execProcess("git ls-remote --tags " & url)
|
var (output, exitCode) = execCmdEx("git ls-remote --tags " & url)
|
||||||
|
if exitCode != QuitSuccess:
|
||||||
|
raise newException(EOS, "Unable to query remote tags for " & url &
|
||||||
|
". Git returned: " & output)
|
||||||
for i in output.splitLines():
|
for i in output.splitLines():
|
||||||
if i == "": continue
|
if i == "": continue
|
||||||
let start = i.find("refs/tags/")+"refs/tags/".len
|
let start = i.find("refs/tags/")+"refs/tags/".len
|
||||||
|
|
@ -82,7 +85,7 @@ proc getTagsListRemote(url: string, meth: TDownloadMethod): seq[string] =
|
||||||
# http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository
|
# http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository
|
||||||
raise newException(EInvalidValue, "Hg doesn't support remote tag querying.")
|
raise newException(EInvalidValue, "Hg doesn't support remote tag querying.")
|
||||||
|
|
||||||
proc getVersionList(tags: seq[string]): TTable[TVersion, string] =
|
proc getVersionList*(tags: seq[string]): TTable[TVersion, string] =
|
||||||
# Returns: TTable of version -> git tag name
|
# Returns: TTable of version -> git tag name
|
||||||
result = initTable[TVersion, string]()
|
result = initTable[TVersion, string]()
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
|
|
@ -90,7 +93,7 @@ proc getVersionList(tags: seq[string]): TTable[TVersion, string] =
|
||||||
# TODO: Better checking, tags can have any names. Add warnings and such.
|
# TODO: Better checking, tags can have any names. Add warnings and such.
|
||||||
result[newVersion(tag[i .. -1])] = tag
|
result[newVersion(tag[i .. -1])] = tag
|
||||||
|
|
||||||
proc getDownloadMethod(meth: string): TDownloadMethod =
|
proc getDownloadMethod*(meth: string): TDownloadMethod =
|
||||||
case meth
|
case meth
|
||||||
of "git": return TDownloadMethod.Git
|
of "git": return TDownloadMethod.Git
|
||||||
of "hg", "mercurial": return TDownloadMethod.Hg
|
of "hg", "mercurial": return TDownloadMethod.Hg
|
||||||
|
|
@ -148,3 +151,27 @@ proc doDownload*(pkg: TPackage, downloadDir: string, verRange: PVersionRange) =
|
||||||
" exist (this usually means that `git tag` returned nothing)." &
|
" exist (this usually means that `git tag` returned nothing)." &
|
||||||
"Git HEAD also does not satisfy version range: " & $verRange)
|
"Git HEAD also does not satisfy version range: " & $verRange)
|
||||||
# We use GIT HEAD if it satisfies our ver range
|
# We use GIT HEAD if it satisfies our ver range
|
||||||
|
|
||||||
|
proc echoPackage*(pkg: TPackage) =
|
||||||
|
echo(pkg.name & ":")
|
||||||
|
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
|
||||||
|
echo(" tags: " & pkg.tags.join(", "))
|
||||||
|
echo(" description: " & pkg.description)
|
||||||
|
echo(" license: " & pkg.license)
|
||||||
|
if pkg.web.len > 0:
|
||||||
|
echo(" website: " & pkg.web)
|
||||||
|
let downMethod = pkg.downloadMethod.getDownloadMethod()
|
||||||
|
case downMethod
|
||||||
|
of TDownloadMethod.Git:
|
||||||
|
try:
|
||||||
|
let versions = getTagsListRemote(pkg.url, downMethod).getVersionList()
|
||||||
|
if versions.len > 0:
|
||||||
|
echo(" versions: ")
|
||||||
|
for k, ver in versions:
|
||||||
|
echo " ", ver
|
||||||
|
else:
|
||||||
|
echo(" versions: (No versions tagged in the remote repository)")
|
||||||
|
except EOS:
|
||||||
|
echo(getCurrentExceptionMsg())
|
||||||
|
of TDownloadMethod.Hg:
|
||||||
|
echo(" versions: (Remote tag retrieval not supported by " & pkg.downloadMethod & ")")
|
||||||
|
|
@ -264,12 +264,3 @@ proc getRealDir*(pkgInfo: TPackageInfo): string =
|
||||||
result = pkgInfo.mypath.splitFile.dir / pkgInfo.srcDir
|
result = pkgInfo.mypath.splitFile.dir / pkgInfo.srcDir
|
||||||
else:
|
else:
|
||||||
result = pkgInfo.mypath.splitFile.dir
|
result = pkgInfo.mypath.splitFile.dir
|
||||||
|
|
||||||
proc echoPackage*(pkg: TPackage) =
|
|
||||||
echo(pkg.name & ":")
|
|
||||||
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
|
|
||||||
echo(" tags: " & pkg.tags.join(", "))
|
|
||||||
echo(" description: " & pkg.description)
|
|
||||||
echo(" license: " & pkg.license)
|
|
||||||
if pkg.web.len > 0:
|
|
||||||
echo(" website: " & pkg.web)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue