diff options
author | zqqw | 2020-08-05 13:53:43 +0000 |
---|---|---|
committer | GitHub | 2020-08-05 13:53:43 +0000 |
commit | f2a93bea278e9f43cad98ca8e74f9a423f36e333 (patch) | |
tree | 721da2b78793860b6fb020194efe2eccea88bac9 /src/package.nim | |
parent | b2321b0ded6f4a9803daf9dbcbd88d56321a9305 (diff) | |
parent | 4bbf3dc2097f1de206fa053fac32f675d4ae2927 (diff) |
Merge pull request #4 from shirleyquirk/lc_useVersion
I mean it this time
Diffstat (limited to 'src/package.nim')
-rw-r--r-- | src/package.nim | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/src/package.nim b/src/package.nim index 612f98f..feab377 100644 --- a/src/package.nim +++ b/src/package.nim @@ -1,6 +1,6 @@ import options, os, re, sequtils, sets, strutils, sugar, tables, utils, - "wrapper/alpm", "listcomp" + "wrapper/alpm" type ConstraintOperation* {.pure.} = enum @@ -91,8 +91,14 @@ const static: # test only single match available - let osSet = lc[x | (r <- packageRepos, x <- r.os), string].toHashSet - let repoSet = lc[x | (r <- packageRepos, x <- r.repo), string].toHashSet + let osSet = collect(initHashSet): + for r in packageRepos: + for x in r.os: + {x} + let repoSet = collect(initHashSet): + for r in packageRepos: + for x in r.repo: + {x} for os in osSet: for repo in repoSet: let osValue = os @@ -102,10 +108,14 @@ static: "only single matching repo available: " & os & ":" & repo) # test unique url <> bareName links - let bareNameToUrl = lc[(x, r.git.url) | - (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable - let urlToBareName = lc[(r.git.url, x) | - (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable + let bareNameToUrl = collect(initTable): + for r in packageRepos: + for x in r.git.bareName: + {x:r.git.url} + let urlToBareName = collect(initTable): + for r in packageRepos: + for x in r.git.bareName: + {r.git.url:x} template testBareNamesAndUrls(m1: untyped, m2: untyped) = for x1, x2 in m1: @@ -262,9 +272,12 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int rpcInfos: seq[RpcPackageInfo], baseSeq: ref seq[SrcInfoPair], nameSeq: ref seq[SrcInfoPair], arch: string, gitUrl: string, gitSubdir: Option[string]): Option[PackageInfo] = proc collectFromPairs(pairs: seq[SrcInfoPair], keyName: string): seq[string] = - lc[x.value | (x <- pairs, x.key == keyName), string] - - proc collect(baseOnly: bool, keyName: string): seq[string] = + collect(newSeq): + for x in pairs: + if x.key == keyName: + x.value + #changed the name as shadows collect macro from sugar + proc collectName(baseOnly: bool, keyName: string): seq[string] = let res = if baseOnly: @[] else: collectFromPairs(nameSeq[], keyName) if res.len == 0: collectFromPairs(baseSeq[], keyName).filter(x => x.len > 0) @@ -272,28 +285,35 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int res.filter(x => x.len > 0) proc collectArch(baseOnly: bool, keyName: string): seq[PackageReference] = - (collect(baseOnly, keyName) & collect(baseOnly, keyName & "_" & arch)) + (collectName(baseOnly, keyName) & collectName(baseOnly, keyName & "_" & arch)) .map(n => parsePackageReference(n, true)) .filter(c => c.name.len > 0) proc filterReferences(references: seq[PackageReference], filterWith: seq[PackageReference]): seq[PackageReference] = references.filter(r => filterWith.filter(w => r.isProvidedBy(w, true)).len == 0) - - let base = lc[x.value | (x <- baseSeq[], x.key == "pkgbase"), string].optLast - - let version = collect(true, "pkgver").optLast - let release = collect(true, "pkgrel").optLast - let epoch = collect(true, "epoch").optLast - let versionFull = lc[(v & "-" & r) | (v <- version, r <- release), string].optLast - .map(v => epoch.map(e => e & ":" & v).get(v)) - - let description = collect(false, "pkgdesc").optLast - let archs = collect(false, "arch").filter(a => a != "any") - let url = collect(false, "url").optLast - let licenses = collect(false, "license") - let groups = collect(false, "groups") - let pgpKeys = collect(true, "validpgpkeys") + + let base = optLast: + collect(newSeq): + for x in baseSeq[]: + if x.key == "pkgbase": + x.value + + let version = collectName(true, "pkgver").optLast + let release = collectName(true, "pkgrel").optLast + let epoch = collectName(true, "epoch").optLast + let versionFull = (block:collect(newSeq): + for v in version: + for r in release: + (v & "-" & r) + ).optLast.map(v => epoch.map(e => e & ":" & v).get(v)) + + let description = collectName(false, "pkgdesc").optLast + let archs = collectName(false, "arch").filter(a => a != "any") + let url = collectName(false, "url").optLast + let licenses = collectName(false, "license") + let groups = collectName(false, "groups") + let pgpKeys = collectName(true, "validpgpkeys") let baseDepends = collectArch(true, "depends") let depends = collectArch(false, "depends") @@ -308,12 +328,16 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int let info = rpcInfos.filter(i => i.name == name).optLast - lc[((repo, b, name, v, description, info.map(i => i.maintainer).flatten, - info.map(i => i.firstSubmitted).flatten, info.map(i => i.lastModified).flatten, - info.map(i => i.outOfDate).flatten, info.map(i => i.votes).get(0), - info.map(i => i.popularity).get(0), gitUrl, gitSubdir), baseIndex, baseCount, - archs, url, licenses, groups, pgpKeys, depends, makeDepends, checkDepends, - optional, provides, conflicts, replaces) | (b <- base, v <- versionFull), PackageInfo].optLast + optLast: + collect(newSeq): + for b in base: + for v in versionFull: + ((repo, b, name, v, description, info.map(i => i.maintainer).flatten, + info.map(i => i.firstSubmitted).flatten, info.map(i => i.lastModified).flatten, + info.map(i => i.outOfDate).flatten, info.map(i => i.votes).get(0), + info.map(i => i.popularity).get(0), gitUrl, gitSubdir), baseIndex, baseCount, + archs, url, licenses, groups, pgpKeys, depends, makeDepends, checkDepends, + optional, provides, conflicts, replaces) proc parseSrcInfo*(repo: string, srcInfo: string, arch: string, gitUrl: string, gitSubdir: Option[string], rpcInfos: seq[RpcPackageInfo] = @[]): seq[PackageInfo] = |