-
Notifications
You must be signed in to change notification settings - Fork 4
/
temboz
executable file
·101 lines (99 loc) · 3.08 KB
/
temboz
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
from __future__ import print_function
import sys, os, datetime, resource
import tembozapp.feedfix
def usage():
print("""usage: %s [options]
--refresh : refresh the subscribed feeds
--import <opml_file> : import subscriptions from a OPML file
--server : run the built-in web server
--kill : kill the server
--cleanup : perform database housekeeping and cleanup
-v : be more verbose (can be repeated)
-h, --help : print this help text
""" % sys.argv[0])
sys.exit(0)
if __name__ == '__main__':
started = datetime.datetime.now()
import getopt
# raise max number of file descriptors
hard = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard))
# bootstrap DB file if it does not exist
try:
os.stat('rss.db')
except:
import tembozapp.bootstrap
if os.getenv('DOCKER') == 'true':
tembozapp.bootstrap.docker_bootstrap()
else:
tembozapp.bootstrap.interactive_bootstrap()
# do not run if dependencies are insecure
import sanity
try:
import tembozapp.transform
except ImportError:
print('You must create a transform.py file, possibly using',
end=' ', file=sys.stderr)
print('transform.py.sample as an example', file=sys.stderr)
sys.exit(0)
import tembozapp.util
opts, args = getopt.getopt(
sys.argv[1:], 'vh',
['refresh', 'resync', 'server', 'import=', 'kill', 'help',
'clean', 'cleanup', 'sop'])
if opts == []:
# try to detect if we are being called as a CGI script
cgi_ver = os.getenv('GATEWAY_INTERFACE')
if cgi_ver and cgi_ver.startswith('CGI/'):
import tembozapp.server
tembozapp.server.do_cgi()
else:
usage()
for opt, val in opts:
if opt in ['-h', '--help']:
usage()
if opt == '--refresh':
import tembozapp.update
try:
tembozapp.update.update()
except:
tembozapp.util.print_stack()
sys.exit(1)
if opt == '--resync':
import tembozapp.update
try:
tembozapp.update.update('and feed_errors > 0')
except:
tembozapp.util.print_stack()
sys.exit(1)
elif opt == '--import':
import tembozapp.opml
tembozapp.opml.import_opml(val)
elif opt == '--daemon':
# close stdin file descriptor
try:
import posix
posix.close(0)
posix.open('/dev/null', posix.O_RDONLY)
except ImportError:
pass
elif opt == '--server':
import tembozapp.update, tembozapp.server
updater = tembozapp.update.PeriodicUpdater()
updater.start()
rater = tembozapp.update.RatingsWorker(tembozapp.update.ratings_q)
rater.start()
tembozapp.server.run()
elif opt == '--kill':
import os
pid = int(open('temboz.pid').readline().strip())
os.kill(pid, 9)
os.remove('temboz.pid')
elif opt in ['--clean', '--cleanup']:
import tembozapp.update
try:
tembozapp.update.cleanup()
except:
tembozapp.util.print_stack()
sys.exit(1)