Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/frontends/py/frontend.py

42 lines
959 B
Python
Raw Permalink Normal View History

2016-10-15 18:12:01 +05:00
#!/usr/bin/env python3
2016-11-04 17:45:06 +05:00
#
# entry point for c++ frontend
#
2016-10-18 16:03:51 +05:00
from nntpchan import message
from nntpchan import db
import logging
import os
2016-10-15 18:12:01 +05:00
import sys
2016-10-18 16:03:51 +05:00
2016-10-15 18:12:01 +05:00
if __name__ == "__main__":
2016-10-18 16:03:51 +05:00
lvl = logging.INFO
if 'NNTPCHAN_DEBUG' in os.environ:
lvl = logging.DEBUG
logging.basicConfig(level=lvl)
l = logging.getLogger(__name__)
cmd = sys.argv[1]
if cmd == 'post':
fpath = sys.argv[2]
msg = None
if not os.path.exists(fpath):
print("{} does not exist".format(fpath))
exit(1)
with open(fpath) as f:
msg = message.parse(f)
if msg:
l.debug("loaded {}".format(fpath))
elif cmd == 'newsgroup':
if db.allowsNewsgroup(sys.argv[2]):
exit(0)
else:
exit(1)
elif cmd == 'msgid':
if db.allowsMessage(sys.argv[2]):
exit(0)
else:
exit(1)
elif cmd == 'init':
db.init()