2014-09-28 18:03:08 +02:00
|
|
|
#!/usr/bin/python3
|
2014-09-27 09:19:46 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
if '__main__' == __name__:
|
2014-09-28 18:03:08 +02:00
|
|
|
print('''this is a library file, which is not meant to be executed''')
|
2014-09-27 09:19:46 +02:00
|
|
|
exit(-1)
|
|
|
|
|
|
2015-06-21 00:50:42 +02:00
|
|
|
import sys, time, pickle, os, logging
|
2014-09-27 16:06:26 +02:00
|
|
|
from local_config import conf
|
2014-09-27 09:19:46 +02:00
|
|
|
|
2014-12-02 17:01:40 +01:00
|
|
|
RATE_GLOBAL = 0x01
|
|
|
|
|
RATE_NO_SILENCE = 0x02
|
2014-09-27 09:19:46 +02:00
|
|
|
RATE_INTERACTIVE = 0x04
|
2014-12-02 17:01:40 +01:00
|
|
|
RATE_CHAT = 0x08
|
|
|
|
|
RATE_URL = 0x10
|
2014-09-27 09:19:46 +02:00
|
|
|
|
|
|
|
|
BUFSIZ = 8192
|
2015-08-21 23:35:28 +02:00
|
|
|
EVENTLOOP_DELAY = 0.100 # seconds
|
|
|
|
|
USER_AGENT = '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0'''
|
2014-09-27 09:19:46 +02:00
|
|
|
|
|
|
|
|
basedir = '.'
|
2014-12-02 17:01:40 +01:00
|
|
|
if 2 == len(sys.argv):
|
|
|
|
|
basedir = sys.argv[1]
|
2014-09-27 09:19:46 +02:00
|
|
|
|
2015-06-21 00:50:42 +02:00
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
2015-07-19 02:04:59 +02:00
|
|
|
format=sys.argv[0]+' %(asctime)s %(levelname).1s %(funcName)-15s %(message)s'
|
2015-06-21 00:50:42 +02:00
|
|
|
)
|
|
|
|
|
log = logging.getLogger()
|
|
|
|
|
log.plugin = log.info # ... probably fix this sometime (FIXME)
|
|
|
|
|
|
2014-09-27 09:19:46 +02:00
|
|
|
def debug_enabled():
|
|
|
|
|
# return True
|
|
|
|
|
return False
|
|
|
|
|
|
2014-09-27 16:06:26 +02:00
|
|
|
def conf_save(obj):
|
|
|
|
|
with open(conf('persistent_storage'), 'wb') as fd:
|
|
|
|
|
return pickle.dump(obj, fd)
|
|
|
|
|
|
|
|
|
|
def conf_load():
|
2015-02-05 18:38:28 +01:00
|
|
|
path = conf('persistent_storage')
|
|
|
|
|
if os.path.isfile(path):
|
|
|
|
|
with open(path, 'rb') as fd:
|
|
|
|
|
fd.seek(0)
|
|
|
|
|
return pickle.load(fd)
|
|
|
|
|
else:
|
|
|
|
|
return {}
|
2014-09-27 16:06:26 +02:00
|
|
|
|
2014-09-27 09:41:29 +02:00
|
|
|
def get_version_git():
|
|
|
|
|
import subprocess
|
|
|
|
|
|
2014-11-28 19:33:52 +01:00
|
|
|
cmd = ['git', 'log', '--oneline', '--abbrev-commit']
|
2014-09-27 09:41:29 +02:00
|
|
|
|
|
|
|
|
p = subprocess.Popen(cmd, bufsize=1, stdout=subprocess.PIPE)
|
|
|
|
|
first_line = p.stdout.readline()
|
2014-11-28 19:33:52 +01:00
|
|
|
line_count = len(p.stdout.readlines()) + 1
|
2014-09-27 09:41:29 +02:00
|
|
|
|
|
|
|
|
if 0 == p.wait():
|
2014-11-28 19:33:52 +01:00
|
|
|
# skip this 1st, 2nd, 3rd stuff and use always [0-9]th
|
|
|
|
|
return "version (Git, %dth rev) '%s'" % (
|
|
|
|
|
line_count, str(first_line.strip(), encoding='utf8')
|
|
|
|
|
)
|
2014-09-27 09:41:29 +02:00
|
|
|
else:
|
|
|
|
|
return "(unknown version)"
|
|
|
|
|
|
|
|
|
|
VERSION = get_version_git()
|