File size: 2,771 Bytes
285c5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501a428
 
285c5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
#

# This is a manual mapping of versions of codes_and_flags.yaml from:
# * https://github.com/UniversalDependencies/docs-automation/commits/master/codes_and_flags.yaml
# (identified by commit hash) matched to the closest date of UD versions from:
# * https://github.com/UniversalDependencies/docs
declare -A VER_MAPPING
VER_MAPPING["2.7"]="a5124b817c04ee6c8b01b80b2adad518b06aa9b4"
VER_MAPPING["2.8"]="26d595cd549e904a4d49b62fccb33602c9d18eb8"
VER_MAPPING["2.9"]="6167b04d6dc5d953f4007dcd75b5fbbf8c7645d6"
VER_MAPPING["2.10"]="953b1c6e70836b7a64b764e24f578ca787cfd89c"
VER_MAPPING["2.11"]="25ee28cd173c2fee5e3a7ad493a4c6e137e13f6b"
VER_MAPPING["2.12"]="32a51d28787795eea1c2e11b3572087a3dc228ac"
VER_MAPPING["2.13"]="6712e116f6fda486223e183f56ffb8921695d4a6"
VER_MAPPING["2.14"]="dabe6c89701b6127b867e27c0256eb4f9dfa9d46"
VER_MAPPING["2.15"]="b3b3d95333d603db6aede3601a3cf9929b3470ae"
VER_MAPPING["2.16"]="bc0cc9b94112253e3ea1e00b2dbe3a46c5f53fe3"
VER_MAPPING["2.17"]="e3847a587baa2a5a7345049b8b2c109ad2162c21"
VER_MAPPING["latest"]="e3847a587baa2a5a7345049b8b2c109ad2162c21"

###################
#############
#
# USAGE
#
usage() { OUTPUT=${1:-"verbose"}
echo "Usage: $0 [-o]" >&2
[ $OUTPUT = "short" ] && exit 0
>&2 cat << EOF

Download versions of
* codes_and_flags.yaml
a yaml file mapping UD (long) language names to metadata.

For example:
German:
  flag: DE
  lcode: de
  iso3: deu
  family: IE
  genus: Germanic

Options:
    -h              Print this help message
    -o|--online     Enable online mode: (re-fetch files from GitHub)
EOF
}
#
######
############
##################

ONLINE_MODE=false

VALID_ARGS=$(getopt -o ho --long help,online -- "$@")
if [[ $? -ne 0 ]]; then
  usage "short"
  exit 1;
fi
eval set -- "$VALID_ARGS"
while [ : ]
do
  case "$1" in
    -o | --online) ONLINE_MODE=true; shift   ;;
    -h | --help)   usage;            shift   ; exit 0;;
    --)                              shift   ; break ;;
    *) >&2 echo Unsupported option: $1; usage; exit 1;;
  esac
done

set -uo pipefail
for key in ${!VER_MAPPING[@]}
do
    VER="${key}"
    GIT_HASH="${VER_MAPPING[${key}]}"

    CODES_AND_FLAGS_FN="etc/codes_and_flags-${VER}.yaml"
    CODES_AND_FLAGS_URL="https://github.com/UniversalDependencies/docs-automation/blob/${GIT_HASH}/codes_and_flags.yaml"
    CODES_AND_FLAGS_RAW_URL="https://raw.githubusercontent.com/UniversalDependencies/docs-automation/${GIT_HASH}/codes_and_flags.yaml"

    # Fuction to get github API content
    get_codes_and_flags() {
        wget "${CODES_AND_FLAGS_RAW_URL}" -O "${CODES_AND_FLAGS_FN}"
    }

    # Check if the online argument is present
    if [[ $ONLINE_MODE == true ]] || [[ ! -e ${CODES_AND_FLAGS_FN} ]]; then
      # Download content
      get_codes_and_flags
    fi
done