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:
|
||||
result = @[]
|
||||
|
||||
proc getTagsListRemote(url: string, meth: TDownloadMethod): seq[string] =
|
||||
proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
||||
result = @[]
|
||||
case meth
|
||||
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():
|
||||
if i == "": continue
|
||||
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
|
||||
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
|
||||
result = initTable[TVersion, string]()
|
||||
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.
|
||||
result[newVersion(tag[i .. -1])] = tag
|
||||
|
||||
proc getDownloadMethod(meth: string): TDownloadMethod =
|
||||
proc getDownloadMethod*(meth: string): TDownloadMethod =
|
||||
case meth
|
||||
of "git": return TDownloadMethod.Git
|
||||
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)." &
|
||||
"Git HEAD also does not satisfy version range: " & $verRange)
|
||||
# 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
|
||||
else:
|
||||
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