Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/nimble.nim
This commit is contained in:
Louis Berube 2015-01-03 19:04:09 -05:00
commit ceb1e48a80
6 changed files with 43 additions and 24 deletions

View file

@ -16,6 +16,7 @@ type
Options = object Options = object
forcePrompts: ForcePrompt forcePrompts: ForcePrompt
queryVersions: bool queryVersions: bool
queryInstalled: bool
action: Action action: Action
config: Config config: Config
nimbleData: JsonNode ## Nimbledata.json nimbleData: JsonNode ## Nimbledata.json
@ -37,6 +38,7 @@ type
search: seq[string] # Search string. search: seq[string] # Search string.
of actionInit: of actionInit:
projName: string projName: string
else:nil
ForcePrompt = enum ForcePrompt = enum
dontForcePrompt, forcePromptYes, forcePromptNo dontForcePrompt, forcePromptYes, forcePromptNo
@ -55,6 +57,7 @@ Commands:
search [--ver] pkg/tag Searches for a specified package. Search is search [--ver] pkg/tag Searches for a specified package. Search is
performed by tag and by name. performed by tag and by name.
list [--ver] Lists all packages. list [--ver] Lists all packages.
[-i, --installed] Lists all installed packages.
path pkgname ... Shows absolute path to the installed packages path pkgname ... Shows absolute path to the installed packages
specified. specified.
@ -171,7 +174,7 @@ proc parseCmdLine(): Options =
let pkgTup = (key[0 .. i-1], key[i+1 .. -1].parseVersionRange()) let pkgTup = (key[0 .. i-1], key[i+1 .. -1].parseVersionRange())
result.action.packages.add(pkgTup) result.action.packages.add(pkgTup)
else: else:
result.action.packages.add((key, VersionRangeRef(kind: verAny))) result.action.packages.add((key, VersionRange(kind: verAny)))
of actionUpdate: of actionUpdate:
result.action.optionalURL = key result.action.optionalURL = key
of actionSearch: of actionSearch:
@ -192,6 +195,7 @@ proc parseCmdLine(): Options =
of "accept", "y": result.forcePrompts = forcePromptYes of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo of "reject", "n": result.forcePrompts = forcePromptNo
of "ver": result.queryVersions = true of "ver": result.queryVersions = true
of "installed", "i": result.queryInstalled = true
else: discard else: discard
of cmdEnd: assert(false) # cannot happen of cmdEnd: assert(false) # cannot happen
if result.action.typ == actionNil: if result.action.typ == actionNil:
@ -576,7 +580,7 @@ proc getNimbleTempDir(): string =
else: else:
result.add($getpid()) result.add($getpid())
proc downloadPkg(url: string, verRange: VersionRangeRef, proc downloadPkg(url: string, verRange: VersionRange,
downMethod: DownloadMethod): string = downMethod: DownloadMethod): string =
let downloadDir = (getNimbleTempDir() / getDownloadDirName(url, verRange)) let downloadDir = (getNimbleTempDir() / getDownloadDirName(url, verRange))
createDir(downloadDir) createDir(downloadDir)
@ -584,7 +588,7 @@ proc downloadPkg(url: string, verRange: VersionRangeRef,
doDownload(url, downloadDir, verRange, downMethod) doDownload(url, downloadDir, verRange, downMethod)
result = downloadDir result = downloadDir
proc downloadPkg(pkg: Package, verRange: VersionRangeRef): string = proc downloadPkg(pkg: Package, verRange: VersionRange): string =
let downloadDir = (getNimbleTempDir() / getDownloadDirName(pkg, verRange)) let downloadDir = (getNimbleTempDir() / getDownloadDirName(pkg, verRange))
let downMethod = pkg.downloadMethod.getDownloadMethod() let downMethod = pkg.downloadMethod.getDownloadMethod()
createDir(downloadDir) createDir(downloadDir)
@ -677,6 +681,20 @@ proc list(options: Options) =
echoPackageVersions(pkg) echoPackageVersions(pkg)
echo(" ") echo(" ")
proc listInstalled(options: Options) =
var h = initTable[string, seq[string]]()
let pkgs = getInstalledPkgs(options.getPkgsDir())
for x in pkgs.items():
let
pName = x.pkginfo.name
pVer = x.pkginfo.version
if not h.hasKey(pName): h[pName] = @[]
var s = h[pName]
add(s, pVer)
h[pName] = s
for k in keys(h):
echo k & " [" & h[k].join(", ") & "]"
type VersionAndPath = tuple[version: Version, path: string] type VersionAndPath = tuple[version: Version, path: string]
proc listPaths(options: Options) = proc listPaths(options: Options) =
@ -830,7 +848,8 @@ proc doAction(options: Options) =
of actionSearch: of actionSearch:
search(options) search(options)
of actionList: of actionList:
list(options) if options.queryInstalled: listInstalled(options)
else: list(options)
of actionPath: of actionPath:
listPaths(options) listPaths(options)
of actionBuild: of actionBuild:

View file

@ -146,7 +146,7 @@ proc checkUrlType*(url: string): DownloadMethod =
proc isURL*(name: string): bool = proc isURL*(name: string): bool =
name.startsWith(peg" @'://' ") name.startsWith(peg" @'://' ")
proc doDownload*(url: string, downloadDir: string, verRange: VersionRangeRef, proc doDownload*(url: string, downloadDir: string, verRange: VersionRange,
downMethod: DownloadMethod) = downMethod: DownloadMethod) =
template getLatestByTag(meth: stmt): stmt {.dirty, immediate.} = template getLatestByTag(meth: stmt): stmt {.dirty, immediate.} =
echo("Found tags...") echo("Found tags...")

View file

@ -4,7 +4,7 @@ import parsecfg, json, streams, strutils, parseutils, os
import version, tools, nimbletypes import version, tools, nimbletypes
type type
## Tuple containing package name and version range. ## Tuple containing package name and version range.
PkgTuple* = tuple[name: string, ver: VersionRangeRef] PkgTuple* = tuple[name: string, ver: VersionRange]
PackageInfo* = object PackageInfo* = object
mypath*: string ## The path of this .nimble file mypath*: string ## The path of this .nimble file
@ -95,7 +95,7 @@ proc parseRequires(req: string): PkgTuple =
result.ver = parseVersionRange(req[i .. -1]) result.ver = parseVersionRange(req[i .. -1])
else: else:
result.name = req.strip result.name = req.strip
result.ver = VersionRangeRef(kind: verAny) result.ver = VersionRange(kind: verAny)
except ParseVersionError: except ParseVersionError:
raise newException(NimbleError, raise newException(NimbleError,
"Unable to parse dependency version range: " & getCurrentExceptionMsg()) "Unable to parse dependency version range: " & getCurrentExceptionMsg())
@ -351,7 +351,7 @@ proc echoPackage*(pkg: Package) =
if pkg.web.len > 0: if pkg.web.len > 0:
echo(" website: " & pkg.web) echo(" website: " & pkg.web)
proc getDownloadDirName*(pkg: Package, verRange: VersionRangeRef): string = proc getDownloadDirName*(pkg: Package, verRange: VersionRange): string =
result = pkg.name result = pkg.name
let verSimple = getSimpleString(verRange) let verSimple = getSimpleString(verRange)
if verSimple != "": if verSimple != "":

View file

@ -81,7 +81,7 @@ proc copyDirD*(fro, to: string): seq[string] =
createDir(changeRoot(fro, to, path.splitFile.dir)) createDir(changeRoot(fro, to, path.splitFile.dir))
result.add copyFileD(path, changeRoot(fro, to, path)) result.add copyFileD(path, changeRoot(fro, to, path))
proc getDownloadDirName*(uri: string, verRange: VersionRangeRef): string = proc getDownloadDirName*(uri: string, verRange: VersionRange): string =
## Creates a directory name based on the specified ``uri`` (url) ## Creates a directory name based on the specified ``uri`` (url)
result = "" result = ""
let puri = parseUri(uri) let puri = parseUri(uri)

Binary file not shown.

View file

@ -17,15 +17,15 @@ type
verAny, # * verAny, # *
verSpecial # #head verSpecial # #head
VersionRangeRef* = ref VersionRange VersionRange* = ref VersionRangeObj
VersionRange* = object VersionRangeObj = object
case kind*: VersionRangeEnum case kind*: VersionRangeEnum
of verLater, verEarlier, verEqLater, verEqEarlier, verEq: of verLater, verEarlier, verEqLater, verEqEarlier, verEq:
ver*: Version ver*: Version
of verSpecial: of verSpecial:
spe*: Special spe*: Special
of verIntersect: of verIntersect:
verILeft, verIRight: VersionRangeRef verILeft, verIRight: VersionRange
of verAny: of verAny:
nil nil
@ -80,7 +80,7 @@ proc `==`*(spe: Special, spe2: Special): bool =
proc `<=`*(ver: Version, ver2: Version): bool = proc `<=`*(ver: Version, ver2: Version): bool =
return (ver == ver2) or (ver < ver2) return (ver == ver2) or (ver < ver2)
proc withinRange*(ver: Version, ran: VersionRangeRef): bool = proc withinRange*(ver: Version, ran: VersionRange): bool =
case ran.kind case ran.kind
of verLater: of verLater:
return ver > ran.ver return ver > ran.ver
@ -99,7 +99,7 @@ proc withinRange*(ver: Version, ran: VersionRangeRef): bool =
of verAny: of verAny:
return true return true
proc withinRange*(spe: Special, ran: VersionRangeRef): bool = proc withinRange*(spe: Special, ran: VersionRange): bool =
case ran.kind case ran.kind
of verLater, verEarlier, verEqLater, verEqEarlier, verEq, verIntersect: of verLater, verEarlier, verEqLater, verEqEarlier, verEq, verIntersect:
return false return false
@ -108,13 +108,13 @@ proc withinRange*(spe: Special, ran: VersionRangeRef): bool =
of verAny: of verAny:
return true return true
proc contains*(ran: VersionRangeRef, ver: Version): bool = proc contains*(ran: VersionRange, ver: Version): bool =
return withinRange(ver, ran) return withinRange(ver, ran)
proc contains*(ran: VersionRangeRef, spe: Special): bool = proc contains*(ran: VersionRange, spe: Special): bool =
return withinRange(spe, ran) return withinRange(spe, ran)
proc makeRange*(version: string, op: string): VersionRangeRef = proc makeRange*(version: string, op: string): VersionRange =
new(result) new(result)
if version == "": if version == "":
raise newException(ParseVersionError, raise newException(ParseVersionError,
@ -134,7 +134,7 @@ proc makeRange*(version: string, op: string): VersionRangeRef =
raise newException(ParseVersionError, "Invalid operator: " & op) raise newException(ParseVersionError, "Invalid operator: " & op)
result.ver = Version(version) result.ver = Version(version)
proc parseVersionRange*(s: string): VersionRangeRef = proc parseVersionRange*(s: string): VersionRange =
# >= 1.5 & <= 1.8 # >= 1.5 & <= 1.8
new(result) new(result)
if s[0] == '#': if s[0] == '#':
@ -184,7 +184,7 @@ proc parseVersionRange*(s: string): VersionRangeRef =
"Unexpected char in version range: " & s[i]) "Unexpected char in version range: " & s[i])
inc(i) inc(i)
proc `$`*(verRange: VersionRangeRef): string = proc `$`*(verRange: VersionRange): string =
case verRange.kind case verRange.kind
of verLater: of verLater:
result = "> " result = "> "
@ -205,7 +205,7 @@ proc `$`*(verRange: VersionRangeRef): string =
result.add(string(verRange.ver)) result.add(string(verRange.ver))
proc getSimpleString*(verRange: VersionRangeRef): string = proc getSimpleString*(verRange: VersionRange): string =
## Gets a string with no special symbols and spaces. Used for dir name ## Gets a string with no special symbols and spaces. Used for dir name
## creation in tools.nim ## creation in tools.nim
case verRange.kind case verRange.kind
@ -219,21 +219,21 @@ proc getSimpleString*(verRange: VersionRangeRef): string =
of verAny: of verAny:
result = "" result = ""
proc newVRAny*(): VersionRangeRef = proc newVRAny*(): VersionRange =
new(result) new(result)
result.kind = verAny result.kind = verAny
proc newVREarlier*(ver: string): VersionRangeRef = proc newVREarlier*(ver: string): VersionRange =
new(result) new(result)
result.kind = verEarlier result.kind = verEarlier
result.ver = newVersion(ver) result.ver = newVersion(ver)
proc newVREq*(ver: string): VersionRangeRef = proc newVREq*(ver: string): VersionRange =
new(result) new(result)
result.kind = verEq result.kind = verEq
result.ver = newVersion(ver) result.ver = newVersion(ver)
proc findLatest*(verRange: VersionRangeRef, proc findLatest*(verRange: VersionRange,
versions: Table[Version, string]): tuple[ver: Version, tag: string] = versions: Table[Version, string]): tuple[ver: Version, tag: string] =
result = (newVersion(""), "") result = (newVersion(""), "")
for ver, tag in versions: for ver, tag in versions: