diff options
| author | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-06-05 11:55:29 +0100 |
|---|---|---|
| committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-06-05 11:55:29 +0100 |
| commit | 0087aeb61ffabec7c4edf4c4d34b2a55ccca9742 (patch) | |
| tree | 8e4410ac553c7d8e7b9dcd1dd4c7eedb57567506 | |
| parent | e5aa13923a27c522a41b34de712a9de2403b615e (diff) | |
| parent | 0cb47c2d4d74852578b64edf2fda84d32c4d856f (diff) | |
| download | packages-0087aeb61ffabec7c4edf4c4d34b2a55ccca9742.tar.gz packages-0087aeb61ffabec7c4edf4c4d34b2a55ccca9742.zip | |
Merge pull request #169 from fenekku/package_scanner_fix
improved(?) package_scanner!
| -rw-r--r-- | package_scanner.nim | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/package_scanner.nim b/package_scanner.nim index e775e29..c3312bf 100644 --- a/package_scanner.nim +++ b/package_scanner.nim @@ -4,11 +4,12 @@ # Scans the package list from this repository. # # Check the packages for: -# * Missing/unknown license -# * Missing description # * Missing name # * Missing/unknown method # * Missing/unreachable repository +# * Missing tags +# * Missing description +# * Missing/unknown license # # Usage: nim c -d:ssl -r package_scanner.nim # @@ -41,24 +42,44 @@ const VCS_TYPES = @["git", "hg"] +proc canFetchNimbleRepository(name: string, urlJson: JsonNode): bool = + # The fetch is a lie! + # TODO: Make this check the actual repo url and check if there is a + # nimble file in it + result = true + var url: string + + if not urlJson.isNil: + url = urlJson.str + + try: + discard getContent(url, timeout=1000) + except HttpRequestError, TimeoutError: + echo "E: ", name, ": unable to fetch repository ", url, " ", + getCurrentExceptionMsg() + result = false + except AssertionError: + echo "W: ", name, ": httpclient failed ", url, " ", + getCurrentExceptionMsg() + + proc check(): int = var name: string - url: string - echo "" + let pkg_list = parseJson(readFile(getCurrentDir() / "packages.json")) for pdata in pkg_list: - if not pdata.hasKey("name"): + name = if pdata.hasKey("name"): pdata["name"].str else: nil + + if name.isNil: echo "E: missing package name" result.inc() - continue - name = pdata["name"].str - if not pdata.hasKey("method"): + elif not pdata.hasKey("method"): echo "E: ", name, " has no method" result.inc() @@ -66,36 +87,34 @@ proc check(): int = echo "E: ", name, " has an unknown method: ", pdata["method"].str result.inc() - if not pdata.hasKey("license"): - echo "E: ", name, " has no license" + elif not pdata.hasKey("url"): + echo "E: ", name, " has no URL" + result.inc() + + elif not canFetchNimbleRepository(name, pdata["web"]): result.inc() - elif not (pdata["license"].str in LICENSES): - echo "W: ", name, " has an unexpected license: ", pdata["license"] - if not pdata.hasKey("description"): + elif not pdata.hasKey("tags"): + echo "E: ", name, " has no tags" + result.inc() + + elif not pdata.hasKey("description"): echo "E: ", name, " has no description" result.inc() - if not pdata.hasKey("url"): - echo "E: ", name, " has no URL" + elif not pdata.hasKey("license"): + echo "E: ", name, " has no license" result.inc() - continue - for pdata in pkg_list: - if pdata.hasKey("name") and pdata.hasKey("web"): - name = pdata["name"].str - url = pdata["web"].str - try: - discard getContent(url, timeout=1000) - - except HttpRequestError, TimeoutError: - echo "E: ", name, ": unable to fetch repository ", url, " ", getCurrentExceptionMsg() - result.inc() - except AssertionError: - echo "W: ", name, ": httpclient failed ", url, " ", getCurrentExceptionMsg() - - echo "Error count: ", result - return + else: + # Other warnings should go here + if not (pdata["license"].str in LICENSES): + echo "W: ", name, " has an unexpected license: ", pdata["license"] + + + echo "" + echo "Problematic packages count: ", result + when isMainModule: quit(check()) |
