File: fetch-dictionary.py

package info (click to toggle)
rednotebook 2.39%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,956 kB
  • sloc: python: 9,570; javascript: 4,103; xml: 128; sh: 58; makefile: 11
file content (44 lines) | stat: -rwxr-xr-x 1,178 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python3

import argparse
import os.path
import shutil

import utils


DIR = os.path.dirname(os.path.abspath(__file__))
DICT_DIR = os.path.join(DIR, "dicts")


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "url", help="URL from ftp://ftp.gnu.org/gnu/aspell/dict/0index.html"
    )
    parser.add_argument("dest", help="Destination directory")
    return parser.parse_args()


def fetch_dict(url, dest):
    assert url.endswith(".tar.bz2"), url
    filename = os.path.basename(url)
    utils.fetch(url, os.path.join(DICT_DIR, filename))
    utils.run(["tar", "xjvf", filename], cwd=DICT_DIR)
    name = filename[: -len(".tar.bz2")]
    path = os.path.join(DICT_DIR, name)
    utils.run(["./configure", "--vars", "DESTDIR=tmp"], cwd=path)
    utils.run(["make"], cwd=path)
    utils.run(["make", "install"], cwd=path)
    result_dir = os.path.join(path, "tmp/usr/lib/aspell")
    utils.ensure_path(dest)
    for dict_file in os.listdir(result_dir):
        shutil.copy2(os.path.join(result_dir, dict_file), os.path.join(dest, dict_file))


def main():
    args = parse_args()
    fetch_dict(args.url, args.dest)


main()