summaryrefslogtreecommitdiff
path: root/mwcfeedserver.py
blob: 0bca4b0680d7f12af90617747c1595d3bb1f085b (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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright: (2013-2017) Michael Till Beck <Debianguru@gmx.de>
# License: GPL-2.0+


import http.server
import socketserver
import importlib
import sys
import getopt


bind = 'localhost'
port = 8000
configMod = 'config'


try:
    opts, args = getopt.getopt(sys.argv[1:], 'hc:b:p:', ['help', 'config=', 'bind=', 'port='])
except getopt.GetoptError:
    print('Usage: FeedServer.py --config=config --port=8000 --bind=localhost')
    sys.exit(1)

for opt, arg in opts:
    if opt == '-h':
        print('Usage: FeedServer.py --config=config --bind=localhost --port=8000')
        exit()
    elif opt in ('-c', '--config'):
        configMod = arg
    elif opt in ('-b', '--bind'):
        bind = arg
    elif opt in ('-p', '--port'):
        port = int(arg)

config = importlib.import_module(configMod)


handler = http.server.SimpleHTTPRequestHandler

httpd = socketserver.TCPServer((bind, port), handler)

print('Bond to ' + bind + ', listening on port ' + str(port))
httpd.serve_forever()