-
Notifications
You must be signed in to change notification settings - Fork 35
/
pm-server
70 lines (60 loc) · 2.5 KB
/
pm-server
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
#!/usr/bin/env python3
import argparse
from tornado import httpserver
from tornado import ioloop as io
import functools
import tornado_crontab
import os
import configparser
from playmaker.server import createServer
from playmaker.service import Play
def auto_update(service):
if service.loggedIn:
print('Executing auto update cron task')
apps = service.check_local_apks().get('message')
if len(apps) > 0:
service.download_selection(apps)
service.fdroid_update()
# tornado setup
if __name__ == '__main__':
# arguments parsing
ap = argparse.ArgumentParser(description='Apk and fdroid repository ' +
'manager with a web interface.')
ap.add_argument('-f', '--fdroid', dest='fdroid',
action='store_true', default=False,
help='Enable fdroid integration')
ap.add_argument('-d', '--debug', dest='debug',
action='store_true', default=False,
help='Enable debug output')
args = ap.parse_args()
service = Play(debug=args.debug, fdroid=args.fdroid)
app = createServer(service)
# server setup
certfile = os.environ.get('HTTPS_CERTFILE')
keyfile = os.environ.get('HTTPS_KEYFILE')
server = (httpserver.HTTPServer(app)
if certfile is None or keyfile is None else
httpserver.HTTPServer(app,
ssl_options={'certfile': certfile,
'keyfile': keyfile}))
server.listen(5000, address='0.0.0.0')
# credentials setup
auth_file_parser = configparser.ConfigParser()
auth_file_parser.read('credentials.conf')
if 'google' in auth_file_parser:
google_section = auth_file_parser['google']
if 'email' in google_section and 'password' in google_section:
service.set_credentials(google_section['email'], google_section['password'])
elif 'gsfId' in google_section and 'token' in google_section:
service.set_token_credentials(google_section['gsfId'], google_section['token'])
if service.has_credentials():
service.login()
service.update_state()
# cron task settings
cron_string = os.environ.get('CRONTAB_STRING')
if cron_string is None:
# default is every night at 2AM
cron_string = '0 2 * * *'
_func = functools.partial(auto_update, *[service])
tornado_crontab.CronTabCallback(_func, cron_string).start()
io.IOLoop.instance().start()