summaryrefslogtreecommitdiff
path: root/licenses/05-organize-gnu-licenses.py
blob: 63bc67752212f679752424101f6a5fa1fe9e58b6 (plain)
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
#!/usr/bin/env python3

import os
import shutil
import sys

def main(argv):
    source_dir = 'www.gnu.org/'
    target_dir = 'gnu/'

    # Organize GNU license files
    gnu_licenses = [
        {
            'name': 'licenses/old-licenses/fdl-1.1.html',
            'code': 'FDL-1.1'
        },
        {
            'name': 'licenses/old-licenses/fdl-1.2.html',
            'code': 'FDL-1.2'
        },
        {
            'name': 'licenses/fdl-1.3.html',
            'code': 'FDL-1.3'
        }
    ]
    copy_license_files(source_dir, target_dir, gnu_licenses)

    copy_requisite_files(source_dir, target_dir)

def copy_license_files(source_dir, target_dir, licenses):
    # GNU licenses are not translated, yet we need the licenses in the C locale directory
    # for these licenses to be served by the API.
    locale_dir = os.path.join(target_dir, 'C')
    try:
        os.makedirs(locale_dir)
    except OSError:
        pass

    for license in licenses:
        license_name = license['name']
        license_code = license['code']
        source_license_path = source_dir + license_name
        target_license_path = locale_dir + '/' + license_code + '.html'

        print('cp ' + license_name + ' ' + target_license_path)
        shutil.copy(source_license_path, target_license_path)

def copy_requisite_files(source_dir, target_dir):
    shutil.copytree(source_dir + 'graphics/', target_dir + 'images/')

    try:
        os.makedirs(target_dir + 'css/')
    except OSError:
        pass

    for css in ['combo.css', 'layout.min.css', 'mini.css', 'print.min.css']:
        print('cp ' + source_dir + css + ' ' + target_dir + 'css/' + css)
        shutil.copy(source_dir + css, target_dir + 'css/' + css)

if __name__ == '__main__':
    main(sys.argv[1:])