Addition of required license field.

This commit is contained in:
Dominik Picheta 2012-12-08 12:42:05 +00:00
commit c732892116
2 changed files with 38 additions and 2 deletions

View file

@ -5,22 +5,43 @@ type
version*: string version*: string
author*: string author*: string
description*: string description*: string
library*: bool license*: string
skipDirs*: seq[string] skipDirs*: seq[string]
skipFiles*: seq[string] skipFiles*: seq[string]
TPackage* = object TPackage* = object
name*: string name*: string
version*: string version*: string
license*: string
url*: string url*: string
dvcsTag*: string dvcsTag*: string
downloadMethod*: string downloadMethod*: string
tags*: seq[string] tags*: seq[string]
description*: string description*: string
proc readPackageInfo*(path: string): TPackageInfo = proc initPackageInfo(): TPackageInfo =
result.name = ""
result.version = ""
result.author = ""
result.description = ""
result.license = ""
result.skipDirs = @[] result.skipDirs = @[]
result.skipFiles = @[] result.skipFiles = @[]
proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) =
if pkgInfo.name == "":
quit("Incorrect .babel file: " & path & " does not contain a name field.")
if pkgInfo.version == "":
quit("Incorrect .babel file: " & path & " does not contain a version field.")
if pkgInfo.author == "":
quit("Incorrect .babel file: " & path & " does not contain an author field.")
if pkgInfo.description == "":
quit("Incorrect .babel file: " & path & " does not contain a description field.")
if pkgInfo.license == "":
quit("Incorrect .babel file: " & path & " does not contain a license field.")
proc readPackageInfo*(path: string): TPackageInfo =
result = initPackageInfo()
var fs = newFileStream(path, fmRead) var fs = newFileStream(path, fmRead)
if fs != nil: if fs != nil:
var p: TCfgParser var p: TCfgParser
@ -41,6 +62,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
of "version": result.version = ev.value of "version": result.version = ev.value
of "author": result.author = ev.value of "author": result.author = ev.value
of "description": result.description = ev.value of "description": result.description = ev.value
of "license": result.license = ev.value
of "library": of "library":
case ev.key.normalize case ev.key.normalize
of "skipdirs": of "skipdirs":
@ -54,6 +76,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
close(p) close(p)
else: else:
quit("Cannot open package info: " & path, QuitFailure) quit("Cannot open package info: " & path, QuitFailure)
validatePackageInfo(result, path)
proc optionalField(obj: PJsonNode, name: string): string = proc optionalField(obj: PJsonNode, name: string): string =
if existsKey(obj, name): if existsKey(obj, name):
@ -81,6 +104,7 @@ proc getPackage*(pkg: string, packagesPath: string, resPkg: var TPackage): bool
resPkg.version = p.optionalField("version") resPkg.version = p.optionalField("version")
resPkg.downloadMethod = p.requiredField("method") resPkg.downloadMethod = p.requiredField("method")
resPkg.dvcsTag = p.optionalField("dvcs-tag") resPkg.dvcsTag = p.optionalField("dvcs-tag")
resPkg.license = p.requiredField("license")
resPkg.tags = @[] resPkg.tags = @[]
for t in p["tags"]: for t in p["tags"]:
resPkg.tags.add(t.str) resPkg.tags.add(t.str)
@ -98,6 +122,7 @@ proc getPackageList*(packagesPath: string): seq[TPackage] =
pkg.url = p.requiredField("url") pkg.url = p.requiredField("url")
pkg.downloadMethod = p.requiredField("method") pkg.downloadMethod = p.requiredField("method")
pkg.dvcsTag = p.optionalField("dvcs-tag") pkg.dvcsTag = p.optionalField("dvcs-tag")
pkg.license = p.requiredField("license")
pkg.tags = @[] pkg.tags = @[]
for t in p["tags"]: for t in p["tags"]:
pkg.tags.add(t.str) pkg.tags.add(t.str)
@ -106,6 +131,14 @@ proc getPackageList*(packagesPath: string): seq[TPackage] =
proc echoPackage*(pkg: TPackage) = proc echoPackage*(pkg: TPackage) =
echo(pkg.name & ":") echo(pkg.name & ":")
if pkg.version != "":
echo(" version: " & pkg.version)
else:
echo(" version: HEAD")
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")") echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
echo(" tags: " & pkg.tags.join(", ")) echo(" tags: " & pkg.tags.join(", "))
echo(" description: " & pkg.description) echo(" description: " & pkg.description)
echo(" license: " & pkg.license)
if pkg.dvcsTag != "":
echo(" dvcs-tag: " & pkg.dvcsTag)

View file

@ -38,12 +38,15 @@ name = "ProjectName"
version = "0.1.0" version = "0.1.0"
author = "Dominik Picheta" author = "Dominik Picheta"
description = """Example .babel file.""" description = """Example .babel file."""
license = "MIT"
[Library] [Library]
SkipDirs = "SomeDir" ; ./ProjectName/SomeDir will be skipped. SkipDirs = "SomeDir" ; ./ProjectName/SomeDir will be skipped.
SkipFiles = "file.txt,file2.txt" ; ./ProjectName/{file.txt, file2.txt} will be skipped. SkipFiles = "file.txt,file2.txt" ; ./ProjectName/{file.txt, file2.txt} will be skipped.
``` ```
All the fields under ``[Package]`` are required.
## Submitting your package to the package list. ## Submitting your package to the package list.
Babel's packages list is stored on github and everyone is encouraged to add Babel's packages list is stored on github and everyone is encouraged to add
their own packages to it! Take a look at their own packages to it! Take a look at