File: gen-manpage-listfile

package info (click to toggle)
manpages-zh 1.6.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,460 kB
  • sloc: python: 129; makefile: 4
file content (60 lines) | stat: -rwxr-xr-x 1,527 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3

# Generate src/man*/manpages file, used by make.
#
# Copyright (c) 2020 Boyuan Yang <byang@debian.org>
# This script is released into the public domain.

# Man pages under 'src/man?'
#
# Assumed man page naming scheme: *.\d*

import sys
from pathlib import Path


MIN_PYTHON = (3, 4)
if sys.version_info < MIN_PYTHON:
    sys.exit('Python %s.%s or later is required.' % MIN_PYTHON)


MAN_DIR_LIST = ['man{}'.format(x) for x in [1, 2, 3, 4, 5, 6, 7, 8, 'n']]
EXCLUDE_FILES = ['Makefile.am']


def _ensure_pwd():
    'Ensure the script to be ran under project topdir.'
    pass

def _scan_filelist(dirpath):
    my_pathlist = dirpath.glob('*.*')
    my_filelist = list()
    for i in my_pathlist:
        if (i.name not in EXCLUDE_FILES) and (i.is_file()):
            my_filelist.append(i.name)
    return sorted(my_filelist)

def do_generate(dirpath):
    assert dirpath.exists()
    assert dirpath.is_dir()
    filelist = _scan_filelist(dirpath)
    with open(dirpath / 'manpages', mode='wt', encoding='UTF-8') as f:
        f.write('MANPAGES = \\\n')
        _is_first_iter = True
        for entry in filelist:
            if _is_first_iter:
                f.write('\t' + entry)
                _is_first_iter = False
            else:
                f.write(' \\\n' + '\t' + entry)
        f.write('\n')

def main():
    _ensure_pwd()
    for mandir in MAN_DIR_LIST:
        my_dirpath = Path('.') / 'src' / mandir
        do_generate(my_dirpath)
    return

if __name__ == '__main__':
    main()