compensate for overhead in storing remembered_txs by adding 100 bytes to each transaction
[p2pool.git] / p2pool / __init__.py
1 import os
2 import sys
3 import traceback
4 import subprocess
5
6 def check_output(*popenargs, **kwargs):
7     process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
8     output, unused_err = process.communicate()
9     retcode = process.poll()
10     if retcode:
11         raise ValueError((retcode, output))
12     return output
13
14 def _get_version():
15     try:
16         try:
17             return check_output(['git', 'describe', '--always', '--dirty'], cwd=os.path.dirname(os.path.abspath(sys.argv[0]))).strip()
18         except:
19             pass
20         try:
21             return check_output(['git.cmd', 'describe', '--always', '--dirty'], cwd=os.path.dirname(os.path.abspath(sys.argv[0]))).strip()
22         except:
23             pass
24         root_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
25         git_dir = os.path.join(root_dir, '.git')
26         if os.path.exists(git_dir):
27             head = open(os.path.join(git_dir, 'HEAD')).read().strip()
28             prefix = 'ref: '
29             if head.startswith(prefix):
30                 path = head[len(prefix):].split('/')
31                 return open(os.path.join(git_dir, *path)).read().strip()[:7]
32             else:
33                 return head[:7]
34         dir_name = os.path.split(root_dir)[1]
35         chars = '0123456789abcdef'
36         if len(dir_name) >= 7 and (len(dir_name) == 7 or dir_name[-8] not in chars) and all(c in chars for c in dir_name[-7:]):
37             return dir_name[-7:]
38         return 'unknown'
39     except Exception, e:
40         traceback.print_exc()
41         return 'unknown %s' % (str(e).encode('hex'),)
42
43 __version__ = _get_version()
44
45 DEBUG = False