Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Conflicts:
	src/nimble.nim
  • Loading branch information
lou15b committed Jan 4, 2015
2 parents f4c052e + e6bdf43 commit ceb1e48
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
27 changes: 23 additions & 4 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type
Options = object
forcePrompts: ForcePrompt
queryVersions: bool
queryInstalled: bool
action: Action
config: Config
nimbleData: JsonNode ## Nimbledata.json
Expand All @@ -37,6 +38,7 @@ type
search: seq[string] # Search string.
of actionInit:
projName: string
else:nil

ForcePrompt = enum
dontForcePrompt, forcePromptYes, forcePromptNo
Expand All @@ -55,6 +57,7 @@ Commands:
search [--ver] pkg/tag Searches for a specified package. Search is
performed by tag and by name.
list [--ver] Lists all packages.
[-i, --installed] Lists all installed packages.
path pkgname ... Shows absolute path to the installed packages
specified.
Expand Down Expand Up @@ -171,7 +174,7 @@ proc parseCmdLine(): Options =
let pkgTup = (key[0 .. i-1], key[i+1 .. -1].parseVersionRange())
result.action.packages.add(pkgTup)
else:
result.action.packages.add((key, VersionRangeRef(kind: verAny)))
result.action.packages.add((key, VersionRange(kind: verAny)))
of actionUpdate:
result.action.optionalURL = key
of actionSearch:
Expand All @@ -192,6 +195,7 @@ proc parseCmdLine(): Options =
of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo
of "ver": result.queryVersions = true
of "installed", "i": result.queryInstalled = true
else: discard
of cmdEnd: assert(false) # cannot happen
if result.action.typ == actionNil:
Expand Down Expand Up @@ -576,15 +580,15 @@ proc getNimbleTempDir(): string =
else:
result.add($getpid())

proc downloadPkg(url: string, verRange: VersionRangeRef,
proc downloadPkg(url: string, verRange: VersionRange,
downMethod: DownloadMethod): string =
let downloadDir = (getNimbleTempDir() / getDownloadDirName(url, verRange))
createDir(downloadDir)
echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...")
doDownload(url, downloadDir, verRange, downMethod)
result = downloadDir

proc downloadPkg(pkg: Package, verRange: VersionRangeRef): string =
proc downloadPkg(pkg: Package, verRange: VersionRange): string =
let downloadDir = (getNimbleTempDir() / getDownloadDirName(pkg, verRange))
let downMethod = pkg.downloadMethod.getDownloadMethod()
createDir(downloadDir)
Expand Down Expand Up @@ -677,6 +681,20 @@ proc list(options: Options) =
echoPackageVersions(pkg)
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]

proc listPaths(options: Options) =
Expand Down Expand Up @@ -830,7 +848,8 @@ proc doAction(options: Options) =
of actionSearch:
search(options)
of actionList:
list(options)
if options.queryInstalled: listInstalled(options)
else: list(options)
of actionPath:
listPaths(options)
of actionBuild:
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/download.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ proc checkUrlType*(url: string): DownloadMethod =
proc isURL*(name: string): bool =
name.startsWith(peg" @'://' ")

proc doDownload*(url: string, downloadDir: string, verRange: VersionRangeRef,
proc doDownload*(url: string, downloadDir: string, verRange: VersionRange,
downMethod: DownloadMethod) =
template getLatestByTag(meth: stmt): stmt {.dirty, immediate.} =
echo("Found tags...")
Expand Down
6 changes: 3 additions & 3 deletions src/nimblepkg/packageinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import parsecfg, json, streams, strutils, parseutils, os
import version, tools, nimbletypes
type
## Tuple containing package name and version range.
PkgTuple* = tuple[name: string, ver: VersionRangeRef]
PkgTuple* = tuple[name: string, ver: VersionRange]

PackageInfo* = object
mypath*: string ## The path of this .nimble file
Expand Down Expand Up @@ -95,7 +95,7 @@ proc parseRequires(req: string): PkgTuple =
result.ver = parseVersionRange(req[i .. -1])
else:
result.name = req.strip
result.ver = VersionRangeRef(kind: verAny)
result.ver = VersionRange(kind: verAny)
except ParseVersionError:
raise newException(NimbleError,
"Unable to parse dependency version range: " & getCurrentExceptionMsg())
Expand Down Expand Up @@ -351,7 +351,7 @@ proc echoPackage*(pkg: Package) =
if pkg.web.len > 0:
echo(" website: " & pkg.web)

proc getDownloadDirName*(pkg: Package, verRange: VersionRangeRef): string =
proc getDownloadDirName*(pkg: Package, verRange: VersionRange): string =
result = pkg.name
let verSimple = getSimpleString(verRange)
if verSimple != "":
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/tools.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ proc copyDirD*(fro, to: string): seq[string] =
createDir(changeRoot(fro, to, path.splitFile.dir))
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)
result = ""
let puri = parseUri(uri)
Expand Down
Binary file removed src/nimblepkg/version
Binary file not shown.
30 changes: 15 additions & 15 deletions src/nimblepkg/version.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ type
verAny, # *
verSpecial # #head

VersionRangeRef* = ref VersionRange
VersionRange* = object
VersionRange* = ref VersionRangeObj
VersionRangeObj = object
case kind*: VersionRangeEnum
of verLater, verEarlier, verEqLater, verEqEarlier, verEq:
ver*: Version
of verSpecial:
spe*: Special
of verIntersect:
verILeft, verIRight: VersionRangeRef
verILeft, verIRight: VersionRange
of verAny:
nil

Expand Down Expand Up @@ -80,7 +80,7 @@ proc `==`*(spe: Special, spe2: Special): bool =
proc `<=`*(ver: Version, ver2: Version): bool =
return (ver == ver2) or (ver < ver2)

proc withinRange*(ver: Version, ran: VersionRangeRef): bool =
proc withinRange*(ver: Version, ran: VersionRange): bool =
case ran.kind
of verLater:
return ver > ran.ver
Expand All @@ -99,7 +99,7 @@ proc withinRange*(ver: Version, ran: VersionRangeRef): bool =
of verAny:
return true

proc withinRange*(spe: Special, ran: VersionRangeRef): bool =
proc withinRange*(spe: Special, ran: VersionRange): bool =
case ran.kind
of verLater, verEarlier, verEqLater, verEqEarlier, verEq, verIntersect:
return false
Expand All @@ -108,13 +108,13 @@ proc withinRange*(spe: Special, ran: VersionRangeRef): bool =
of verAny:
return true

proc contains*(ran: VersionRangeRef, ver: Version): bool =
proc contains*(ran: VersionRange, ver: Version): bool =
return withinRange(ver, ran)

proc contains*(ran: VersionRangeRef, spe: Special): bool =
proc contains*(ran: VersionRange, spe: Special): bool =
return withinRange(spe, ran)

proc makeRange*(version: string, op: string): VersionRangeRef =
proc makeRange*(version: string, op: string): VersionRange =
new(result)
if version == "":
raise newException(ParseVersionError,
Expand All @@ -134,7 +134,7 @@ proc makeRange*(version: string, op: string): VersionRangeRef =
raise newException(ParseVersionError, "Invalid operator: " & op)
result.ver = Version(version)

proc parseVersionRange*(s: string): VersionRangeRef =
proc parseVersionRange*(s: string): VersionRange =
# >= 1.5 & <= 1.8
new(result)
if s[0] == '#':
Expand Down Expand Up @@ -184,7 +184,7 @@ proc parseVersionRange*(s: string): VersionRangeRef =
"Unexpected char in version range: " & s[i])
inc(i)

proc `$`*(verRange: VersionRangeRef): string =
proc `$`*(verRange: VersionRange): string =
case verRange.kind
of verLater:
result = "> "
Expand All @@ -205,7 +205,7 @@ proc `$`*(verRange: VersionRangeRef): string =

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
## creation in tools.nim
case verRange.kind
Expand All @@ -219,21 +219,21 @@ proc getSimpleString*(verRange: VersionRangeRef): string =
of verAny:
result = ""

proc newVRAny*(): VersionRangeRef =
proc newVRAny*(): VersionRange =
new(result)
result.kind = verAny

proc newVREarlier*(ver: string): VersionRangeRef =
proc newVREarlier*(ver: string): VersionRange =
new(result)
result.kind = verEarlier
result.ver = newVersion(ver)

proc newVREq*(ver: string): VersionRangeRef =
proc newVREq*(ver: string): VersionRange =
new(result)
result.kind = verEq
result.ver = newVersion(ver)

proc findLatest*(verRange: VersionRangeRef,
proc findLatest*(verRange: VersionRange,
versions: Table[Version, string]): tuple[ver: Version, tag: string] =
result = (newVersion(""), "")
for ver, tag in versions:
Expand Down

0 comments on commit ceb1e48

Please sign in to comment.