forked from ustclug/mirrors-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genindex.py
executable file
·66 lines (61 loc) · 2.18 KB
/
genindex.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import logging
import argparse
from jinja2 import Environment, FileSystemLoader
import gencontent
#import genisolist
#import genservernews
def main():
logger = logging.getLogger('mirrors-genindex')
ch = logging.StreamHandler()
OUTDIR = os.getenv('HTTPDIR') or gencontent.HTTPDIR
parser = argparse.ArgumentParser(
description="USTC Mirrors Index Page Generator",
epilog="Brought to you by LUG@USTC.")
parser.add_argument(
'-d', '--outdir',
type=str,
default=OUTDIR,
help='specify output directory',
)
parser.add_argument(
'-o', '--output',
type=str,
default=os.path.join(OUTDIR, 'index.html'),
help='specify full output file path, and will overwrite outdir option',
)
parser.add_argument(
'-v', '--verbose',
help='show verbose information',
action='store_true',
)
args = parser.parse_args()
LOGLEVEL = logging.DEBUG if args.verbose else logging.INFO
logger.setLevel(LOGLEVEL)
ch.setLevel(LOGLEVEL)
ch.setFormatter(logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s'))
logger.addHandler(ch)
logger.debug('received command arguments: "{}"'.format(str(args)))
OUTDIR = args.outdir or OUTDIR
OUTFILE = args.output
BASEDIR = os.path.dirname(__file__)
logger.info('OUTFILE is "%(OUTFILE)s"' % locals())
logger.info('BASEDIR is "%(BASEDIR)s"' % locals())
env = Environment(loader=FileSystemLoader(os.path.join(BASEDIR, 'templates')))
template = env.get_template('index.html')
logger.debug('begin parsing template...')
parsed_template = template.render(
repolist=gencontent.genRepoList(),
#revproxy=gencontent.getOthers(),
#isoinfo=genisolist.getImageList(),
#newslist=genservernews.getServerNews(logger)
)
logger.info('begin file writing...')
with open(OUTFILE, 'w') as fout:
fout.write(parsed_template)
fout.write(os.linesep)
logger.info('completed! exiting...')
if __name__ == "__main__":
main()