From 56de41bc8043ad9274a9297f5cebfc389dc9edda Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 11 Feb 2021 15:08:59 +0000 Subject: [PATCH 1/4] lib.licenses.fdl11Plus: init --- lib/licenses.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/licenses.nix b/lib/licenses.nix index 830cb95aff9..ee136c7337c 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -306,6 +306,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { fullName = "GNU Free Documentation License v1.1 only"; }; + fdl11Plus = spdx { + spdxId = "GFDL-1.1-or-later"; + fullName = "GNU Free Documentation License v1.1 or later"; + }; + fdl12Only = spdx { spdxId = "GFDL-1.2-only"; fullName = "GNU Free Documentation License v1.2 only"; From e72f99c1c001187b4007fa0073207d2f5573e978 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 11 Feb 2021 16:18:11 +0000 Subject: [PATCH 2/4] dictdDBs.wiktionary: 20161001 -> 20210201 --- pkgs/servers/dict/dictd-wiktionary.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/servers/dict/dictd-wiktionary.nix b/pkgs/servers/dict/dictd-wiktionary.nix index f591064a3c1..ed6f7357172 100644 --- a/pkgs/servers/dict/dictd-wiktionary.nix +++ b/pkgs/servers/dict/dictd-wiktionary.nix @@ -1,11 +1,11 @@ {lib, stdenv, fetchurl, python, dict, glibcLocales, writeScript}: stdenv.mkDerivation rec { - version = "20161001"; + version = "20210201"; pname = "dict-db-wiktionary"; data = fetchurl { url = "http://dumps.wikimedia.org/enwiktionary/${version}/enwiktionary-${version}-pages-articles.xml.bz2"; - sha256 = "0g3k7kxp2nzg0v56i4cz253af3aqvhn1lwkys2fnam51cn3yqm7m"; + sha256 = "0dc34cbadsg0f6lhfcyx0np7zjnlg6837piqhlvnn0b45xnzn0cs"; }; convert = ./wiktionary2dict.py; From c7c77ab0294562311fcfd70f58bcc7a72ede6625 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 11 Feb 2021 16:25:11 +0000 Subject: [PATCH 3/4] dictdDBs.wiktionary: improve expression * Fix style * Move builder.sh into its own file * Use standard "src" name for source * Add myself as maintainer * Add license --- pkgs/servers/dict/dictd-db.nix | 2 +- pkgs/servers/dict/dictd-wiktionary.nix | 31 ------------------- pkgs/servers/dict/wiktionary/builder.sh | 8 +++++ pkgs/servers/dict/wiktionary/default.nix | 23 ++++++++++++++ .../dict/{ => wiktionary}/wiktionary2dict.py | 0 5 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 pkgs/servers/dict/dictd-wiktionary.nix create mode 100644 pkgs/servers/dict/wiktionary/builder.sh create mode 100644 pkgs/servers/dict/wiktionary/default.nix rename pkgs/servers/dict/{ => wiktionary}/wiktionary2dict.py (100%) diff --git a/pkgs/servers/dict/dictd-db.nix b/pkgs/servers/dict/dictd-db.nix index 584c35bf7f8..da73a94c2aa 100644 --- a/pkgs/servers/dict/dictd-db.nix +++ b/pkgs/servers/dict/dictd-db.nix @@ -91,5 +91,5 @@ in rec { locale = "en_UK"; }; wordnet = callPackage ./dictd-wordnet.nix {}; - wiktionary = callPackage ./dictd-wiktionary.nix {}; + wiktionary = callPackage ./wiktionary {}; } diff --git a/pkgs/servers/dict/dictd-wiktionary.nix b/pkgs/servers/dict/dictd-wiktionary.nix deleted file mode 100644 index ed6f7357172..00000000000 --- a/pkgs/servers/dict/dictd-wiktionary.nix +++ /dev/null @@ -1,31 +0,0 @@ -{lib, stdenv, fetchurl, python, dict, glibcLocales, writeScript}: - -stdenv.mkDerivation rec { - version = "20210201"; - pname = "dict-db-wiktionary"; - data = fetchurl { - url = "http://dumps.wikimedia.org/enwiktionary/${version}/enwiktionary-${version}-pages-articles.xml.bz2"; - sha256 = "0dc34cbadsg0f6lhfcyx0np7zjnlg6837piqhlvnn0b45xnzn0cs"; - }; - - convert = ./wiktionary2dict.py; - buildInputs = [python dict glibcLocales]; - - builder = writeScript "wiktionary-builder.sh" '' - source $stdenv/setup - - mkdir -p $out/share/dictd/ - cd $out/share/dictd - - python -O ${convert} ${data} - dictzip wiktionary-en.dict - echo en_US.UTF-8 > locale - ''; - - meta = { - description = "DICT version of English Wiktionary"; - homepage = "http://en.wiktionary.org/"; - maintainers = [ ]; - platforms = lib.platforms.all; - }; -} diff --git a/pkgs/servers/dict/wiktionary/builder.sh b/pkgs/servers/dict/wiktionary/builder.sh new file mode 100644 index 00000000000..65652ad4bdb --- /dev/null +++ b/pkgs/servers/dict/wiktionary/builder.sh @@ -0,0 +1,8 @@ +source $stdenv/setup + +mkdir -p $out/share/dictd/ +cd $out/share/dictd + +python -O "$convert" "$src" +dictzip wiktionary-en.dict +echo en_US.UTF-8 > locale diff --git a/pkgs/servers/dict/wiktionary/default.nix b/pkgs/servers/dict/wiktionary/default.nix new file mode 100644 index 00000000000..3c18056821d --- /dev/null +++ b/pkgs/servers/dict/wiktionary/default.nix @@ -0,0 +1,23 @@ +{ lib, stdenv, fetchurl, python, dict, glibcLocales }: + +stdenv.mkDerivation rec { + version = "20210201"; + pname = "dict-db-wiktionary"; + + src = fetchurl { + url = "https://dumps.wikimedia.org/enwiktionary/${version}/enwiktionary-${version}-pages-articles.xml.bz2"; + sha256 = "0dc34cbadsg0f6lhfcyx0np7zjnlg6837piqhlvnn0b45xnzn0cs"; + }; + + convert = ./wiktionary2dict.py; + buildInputs = [ python dict glibcLocales ]; + builder = ./builder.sh; + + meta = with lib; { + description = "DICT version of English Wiktionary"; + homepage = "http://en.wiktionary.org/"; + maintainers = with maintainers; [ qyliss ]; + platforms = platforms.all; + license = with licenses; [ cc-by-sa-30 fdl11Plus ]; + }; +} diff --git a/pkgs/servers/dict/wiktionary2dict.py b/pkgs/servers/dict/wiktionary/wiktionary2dict.py similarity index 100% rename from pkgs/servers/dict/wiktionary2dict.py rename to pkgs/servers/dict/wiktionary/wiktionary2dict.py From f6f8170a60fb2dffb93b8eda44a5a6e76f6fae5a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 11 Feb 2021 16:43:36 +0000 Subject: [PATCH 4/4] dictdDBs.wiktionary: add updateScript --- pkgs/servers/dict/wiktionary/default.nix | 2 + .../servers/dict/wiktionary/latest_version.py | 42 +++++++++++++++++++ pkgs/servers/dict/wiktionary/update.sh | 7 ++++ 3 files changed, 51 insertions(+) create mode 100644 pkgs/servers/dict/wiktionary/latest_version.py create mode 100755 pkgs/servers/dict/wiktionary/update.sh diff --git a/pkgs/servers/dict/wiktionary/default.nix b/pkgs/servers/dict/wiktionary/default.nix index 3c18056821d..cd0c9c6c24b 100644 --- a/pkgs/servers/dict/wiktionary/default.nix +++ b/pkgs/servers/dict/wiktionary/default.nix @@ -13,6 +13,8 @@ stdenv.mkDerivation rec { buildInputs = [ python dict glibcLocales ]; builder = ./builder.sh; + passthru.updateScript = ./update.sh; + meta = with lib; { description = "DICT version of English Wiktionary"; homepage = "http://en.wiktionary.org/"; diff --git a/pkgs/servers/dict/wiktionary/latest_version.py b/pkgs/servers/dict/wiktionary/latest_version.py new file mode 100644 index 00000000000..2833a1e05b0 --- /dev/null +++ b/pkgs/servers/dict/wiktionary/latest_version.py @@ -0,0 +1,42 @@ +import subprocess + +from html.parser import HTMLParser +from os.path import abspath, dirname +from urllib.request import urlopen + +class WiktionaryLatestVersionParser(HTMLParser): + def __init__(self, current_version, *args, **kwargs): + self.latest_version = current_version + super().__init__(*args, **kwargs) + + + def handle_starttag(self, tag, attrs): + if tag != 'a': + return + + href = dict(attrs)['href'][0:-1] + if href == 'latest': + return + + self.latest_version = max(self.latest_version, href) + + +def nix_prefetch_url(url, algo='sha256'): + """Prefetches the content of the given URL.""" + print(f'nix-prefetch-url {url}') + out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url]) + return out.decode('utf-8').rstrip() + + +current_version = subprocess.check_output([ + 'nix', 'eval', '--raw', + '-f', dirname(abspath(__file__)) + '/../../../..', + 'dictdDBs.wiktionary.version', +]).decode('utf-8') + +parser = WiktionaryLatestVersionParser(current_version) + +with urlopen('https://dumps.wikimedia.org/enwiktionary/') as resp: + parser.feed(resp.read().decode('utf-8')) + +print(parser.latest_version) diff --git a/pkgs/servers/dict/wiktionary/update.sh b/pkgs/servers/dict/wiktionary/update.sh new file mode 100755 index 00000000000..ff5e0fc3551 --- /dev/null +++ b/pkgs/servers/dict/wiktionary/update.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p common-updater-scripts python3 + +set -ueo pipefail + +version="$(python "$(dirname "${BASH_SOURCE[0]}")"/latest_version.py)" +update-source-version dictdDBs.wiktionary "$version"