Better download dir names for URL dependencies.

This commit is contained in:
Dominik Picheta 2013-12-15 17:21:41 +00:00
commit e14ffd5628
3 changed files with 39 additions and 5 deletions

View file

@ -323,14 +323,14 @@ proc installFromDir(dir: string, latest: bool, options: TOptions): string =
proc downloadPkg(url: string, verRange: PVersionRange,
downMethod: TDownloadMethod): string =
let downloadDir = (getTempDir() / "babel" / "url_unknown")
let downloadDir = (getTempDir() / "babel" / getDownloadDirName(url, verRange))
if not existsDir(getTempDir() / "babel"): createDir(getTempDir() / "babel")
echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...")
doDownload(url, downloadDir, verRange, downMethod)
result = downloadDir
proc downloadPkg(pkg: TPackage, verRange: PVersionRange): string =
let downloadDir = (getTempDir() / "babel" / pkg.name)
let downloadDir = (getTempDir() / "babel" / getDownloadDirName(pkg, verRange))
if not existsDir(getTempDir() / "babel"): createDir(getTempDir() / "babel")
let downMethod = pkg.downloadMethod.getDownloadMethod()
echo("Downloading ", pkg.name, " into ", downloadDir, " using ", downMethod, "...")

View file

@ -2,8 +2,8 @@
# BSD License. Look at license.txt for more info.
#
# Various miscellaneous utility functions reside here.
import osproc, pegs, strutils, os
import version, common
import osproc, pegs, strutils, os, parseurl
import version, common, packageinfo
# TODO: Merge with common.nim?
@ -45,4 +45,25 @@ proc changeRoot*(origRoot, newRoot, path: string): string =
return newRoot / path[origRoot.len .. -1]
else:
raise newException(EInvalidValue,
"Cannot change root of path: Path does not begin with original root.")
"Cannot change root of path: Path does not begin with original root.")
proc getDownloadDirName*(url: string, verRange: PVersionRange): string =
## Creates a directory name based on the specified ``url``
result = ""
let purl = parseUrl(url)
for i in purl.hostname:
case i
of strutils.Letters, strutils.Digits:
result.add i
else: nil
result.add "_"
for i in purl.path:
case i
of strutils.Letters, strutils.Digits:
result.add i
else: nil
result.add "_"
result.add getSimpleString(verRange)
proc getDownloadDirName*(pkg: TPackage, verRange: PVersionRange): string =
result = pkg.name & "_" & verRange.getSimpleString

View file

@ -202,6 +202,19 @@ proc `$`*(verRange: PVersionRange): String =
result.add(string(verRange.ver))
proc getSimpleString*(verRange: PVersionRange): string =
## Gets a string with no special symbols and spaces. Used for dir name creation
## in tools.nim
case verRange.kind
of verSpecial:
result = $verRange.spe
of verLater, verEarlier, verEqLater, verEqEarlier, verEq:
result = $verRange.ver
of verIntersect:
result = getSimpleString(verRange.verILeft) & "_" & getSimpleString(verRange.verIRight)
of verAny:
result = ""
proc newVRAny*(): PVersionRange =
new(result)
result.kind = verAny