Updated source to eliminate stuff deprecated by nim 0.10.2
This commit is contained in:
parent
1efd705731
commit
383e0f2a4c
7 changed files with 56 additions and 45 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, streams, strutils, os
|
||||
|
||||
import tools, version
|
||||
import tools, version, nimbletypes
|
||||
|
||||
type
|
||||
TConfig* = object
|
||||
|
|
@ -32,7 +32,7 @@ proc parseConfig*(): TConfig =
|
|||
|
||||
if f != nil:
|
||||
echo("Reading from config file at ", confFile)
|
||||
var p: TCfgParser
|
||||
var p: CfgParser
|
||||
open(p, f, confFile)
|
||||
while true:
|
||||
var e = next(p)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import parseutils, os, osproc, strutils, tables, pegs
|
||||
|
||||
import packageinfo, version, tools
|
||||
import packageinfo, version, tools, nimbletypes
|
||||
|
||||
type
|
||||
TDownloadMethod* {.pure.} = enum
|
||||
|
|
@ -98,7 +98,7 @@ proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
|||
of TDownloadMethod.Git:
|
||||
var (output, exitCode) = doCmdEx("git ls-remote --tags " & url)
|
||||
if exitCode != QuitSuccess:
|
||||
raise newException(EOS, "Unable to query remote tags for " & url &
|
||||
raise newException(OSError, "Unable to query remote tags for " & url &
|
||||
". Git returned: " & output)
|
||||
for i in output.splitLines():
|
||||
if i == "": continue
|
||||
|
|
@ -108,9 +108,9 @@ proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
|||
|
||||
of TDownloadMethod.Hg:
|
||||
# http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository
|
||||
raise newException(EInvalidValue, "Hg doesn't support remote tag querying.")
|
||||
raise newException(ValueError, "Hg doesn't support remote tag querying.")
|
||||
|
||||
proc getVersionList*(tags: seq[string]): TTable[TVersion, string] =
|
||||
proc getVersionList*(tags: seq[string]): Table[TVersion, string] =
|
||||
# Returns: TTable of version -> git tag name
|
||||
result = initTable[TVersion, string]()
|
||||
for tag in tags:
|
||||
|
|
@ -225,7 +225,7 @@ proc echoPackageVersions*(pkg: TPackage) =
|
|||
echo(" versions: " & vstr)
|
||||
else:
|
||||
echo(" versions: (No versions tagged in the remote repository)")
|
||||
except EOS:
|
||||
except OSError:
|
||||
echo(getCurrentExceptionMsg())
|
||||
of TDownloadMethod.Hg:
|
||||
echo(" versions: (Remote tag retrieval not supported by " & pkg.downloadMethod & ")")
|
||||
|
|
|
|||
7
src/nimblepkg/nimbletypes.nim
Normal file
7
src/nimblepkg/nimbletypes.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
#
|
||||
# Various miscellaneous common types reside here, to avoid problems with
|
||||
# recursive imports
|
||||
|
||||
type
|
||||
ENimble* = object of Exception
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, json, streams, strutils, parseutils, os
|
||||
import version, tools
|
||||
import version, tools, nimbletypes
|
||||
type
|
||||
## Tuple containing package name and version range.
|
||||
TPkgTuple* = tuple[name: string, ver: PVersionRange]
|
||||
|
|
@ -120,7 +120,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
result.mypath = path
|
||||
var fs = newFileStream(path, fmRead)
|
||||
if fs != nil:
|
||||
var p: TCfgParser
|
||||
var p: CfgParser
|
||||
open(p, fs, path)
|
||||
var currentSection = ""
|
||||
while true:
|
||||
|
|
@ -159,6 +159,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
result.backend = ev.value.toLower()
|
||||
case result.backend.normalize
|
||||
of "javascript": result.backend = "js"
|
||||
else: discard
|
||||
else:
|
||||
raise newException(ENimble, "Invalid field: " & ev.key)
|
||||
of "deps", "dependencies":
|
||||
|
|
@ -174,23 +175,23 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
raise newException(ENimble, "Error parsing .nimble file: " & ev.msg)
|
||||
close(p)
|
||||
else:
|
||||
raise newException(EInvalidValue, "Cannot open package info: " & path)
|
||||
raise newException(ValueError, "Cannot open package info: " & path)
|
||||
validatePackageInfo(result, path)
|
||||
|
||||
proc optionalField(obj: PJsonNode, name: string, default = ""): string =
|
||||
proc optionalField(obj: JsonNode, name: string, default = ""): string =
|
||||
## Queries ``obj`` for the optional ``name`` string.
|
||||
##
|
||||
## Returns the value of ``name`` if it is a valid string, or aborts execution
|
||||
## if the field exists but is not of string type. If ``name`` is not present,
|
||||
## returns ``default``.
|
||||
if existsKey(obj, name):
|
||||
if hasKey(obj, name):
|
||||
if obj[name].kind == JString:
|
||||
return obj[name].str
|
||||
else:
|
||||
raise newException(ENimble, "Corrupted packages.json file. " & name & " field is of unexpected type.")
|
||||
else: return default
|
||||
|
||||
proc requiredField(obj: PJsonNode, name: string): string =
|
||||
proc requiredField(obj: JsonNode, name: string): string =
|
||||
## Queries ``obj`` for the required ``name`` string.
|
||||
##
|
||||
## Aborts execution if the field does not exist or is of invalid json type.
|
||||
|
|
@ -199,7 +200,7 @@ proc requiredField(obj: PJsonNode, name: string): string =
|
|||
raise newException(ENimble,
|
||||
"Package in packages.json file does not contain a " & name & " field.")
|
||||
|
||||
proc fromJson(obj: PJSonNode): TPackage =
|
||||
proc fromJson(obj: JSonNode): TPackage =
|
||||
## Constructs a TPackage object from a JSON node.
|
||||
##
|
||||
## Aborts execution if the JSON node doesn't contain the required fields.
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
#
|
||||
# Various miscellaneous utility functions reside here.
|
||||
import osproc, pegs, strutils, os, parseurl, sets, json
|
||||
import version, packageinfo
|
||||
|
||||
type
|
||||
ENimble* = object of EBase
|
||||
import osproc, pegs, strutils, os, uri, sets, json
|
||||
import version, packageinfo, nimbletypes
|
||||
|
||||
proc doCmd*(cmd: string) =
|
||||
let bin = cmd.split(' ')[0]
|
||||
|
|
@ -61,7 +58,7 @@ proc changeRoot*(origRoot, newRoot, path: string): string =
|
|||
if path.startsWith(origRoot):
|
||||
return newRoot / path[origRoot.len .. -1]
|
||||
else:
|
||||
raise newException(EInvalidValue,
|
||||
raise newException(ValueError,
|
||||
"Cannot change root of path: Path does not begin with original root.")
|
||||
|
||||
proc copyFileD*(fro, to: string): string =
|
||||
|
|
@ -78,37 +75,37 @@ proc copyDirD*(fro, to: string): seq[string] =
|
|||
createDir(changeRoot(fro, to, path.splitFile.dir))
|
||||
result.add copyFileD(path, changeRoot(fro, to, path))
|
||||
|
||||
proc getDownloadDirName*(url: string, verRange: PVersionRange): string =
|
||||
## Creates a directory name based on the specified ``url``
|
||||
proc getDownloadDirName*(uri: string, verRange: PVersionRange): string =
|
||||
## Creates a directory name based on the specified ``uri`` (url)
|
||||
result = ""
|
||||
let purl = parseUrl(url)
|
||||
for i in purl.hostname:
|
||||
let puri = parseUri(uri)
|
||||
for i in puri.hostname:
|
||||
case i
|
||||
of strutils.Letters, strutils.Digits:
|
||||
result.add i
|
||||
else: nil
|
||||
else: discard
|
||||
result.add "_"
|
||||
for i in purl.path:
|
||||
for i in puri.path:
|
||||
case i
|
||||
of strutils.Letters, strutils.Digits:
|
||||
result.add i
|
||||
else: nil
|
||||
else: discard
|
||||
|
||||
let verSimple = getSimpleString(verRange)
|
||||
if verSimple != "":
|
||||
result.add "_"
|
||||
result.add verSimple
|
||||
|
||||
proc incl*(s: var TSet[string], v: seq[string] | TSet[string]) =
|
||||
proc incl*(s: var HashSet[string], v: seq[string] | HashSet[string]) =
|
||||
for i in v:
|
||||
s.incl i
|
||||
|
||||
proc contains*(j: PJsonNode, elem: PJsonNode): bool =
|
||||
proc contains*(j: JsonNode, elem: JsonNode): bool =
|
||||
for i in j:
|
||||
if i == elem:
|
||||
return true
|
||||
|
||||
proc contains*(j: PJsonNode, elem: tuple[key: string, val: PJsonNode]): bool =
|
||||
proc contains*(j: JsonNode, elem: tuple[key: string, val: JsonNode]): bool =
|
||||
for key, val in pairs(j):
|
||||
if key == elem.key and val == elem.val:
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type
|
|||
of verAny:
|
||||
nil
|
||||
|
||||
EParseVersion* = object of EInvalidValue
|
||||
EParseVersion* = object of ValueError
|
||||
|
||||
proc newVersion*(ver: string): TVersion = return TVersion(ver)
|
||||
proc newSpecial*(spe: string): TSpecial = return TSpecial(spe)
|
||||
|
|
@ -55,7 +55,7 @@ proc `<`*(ver: TVersion, ver2: TVersion): bool =
|
|||
if sVerI < sVerI2:
|
||||
return true
|
||||
elif sVerI == sVerI2:
|
||||
nil
|
||||
discard
|
||||
else:
|
||||
return false
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ proc newVREq*(ver: string): PVersionRange =
|
|||
result.kind = verEq
|
||||
result.ver = newVersion(ver)
|
||||
|
||||
proc findLatest*(verRange: PVersionRange, versions: TTable[TVersion, string]): tuple[ver: TVersion, tag: string] =
|
||||
proc findLatest*(verRange: PVersionRange, versions: Table[TVersion, string]): tuple[ver: TVersion, tag: string] =
|
||||
result = (newVersion(""), "")
|
||||
for ver, tag in versions:
|
||||
if not withinRange(ver, verRange): continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue