forked from jtoomim/p2pool
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash -xe | ||
|
||
mkdir -p p2pool/networks/ | ||
cat > p2pool/networks/__init__.py << END | ||
import pkgutil | ||
nets = dict((name, __import__(name, globals(), fromlist="dummy")) | ||
for module_loader, name, ispkg in pkgutil.iter_modules(__path__)) | ||
for net_name, net in nets.iteritems(): | ||
net.NAME = net_name | ||
END | ||
python dev/convert_networks.py p2pool/networks.py p2pool/networks/ p2pool | ||
git add p2pool/networks/*.py | ||
git rm p2pool/networks.py | ||
|
||
mkdir -p p2pool/bitcoin/networks/ | ||
cat > p2pool/bitcoin/networks/__init__.py << END | ||
import pkgutil | ||
nets = dict((name, __import__(name, globals(), fromlist="dummy")) | ||
for module_loader, name, ispkg in pkgutil.iter_modules(__path__)) | ||
for net_name, net in nets.iteritems(): | ||
net.NAME = net_name | ||
END | ||
python dev/convert_networks.py p2pool/bitcoin/networks.py p2pool/bitcoin/networks/ bitcoin | ||
git add p2pool/bitcoin/networks/*.py | ||
git rm p2pool/bitcoin/networks.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import sys | ||
|
||
f = open(sys.argv[1]) | ||
|
||
while True: | ||
if f.readline().strip() == 'nets = dict(': break | ||
|
||
def nesting(l): | ||
res = 0 | ||
for c in l: | ||
if c == '(': res += 1 | ||
if c == ')': res -= 1 | ||
return res | ||
|
||
def write_header(f, name): | ||
if sys.argv[3] == 'p2pool': | ||
f2.write('from p2pool.bitcoin import networks\n\n') | ||
if name == 'bitcoin': | ||
f2.write('''# CHAIN_LENGTH = number of shares back client keeps | ||
# REAL_CHAIN_LENGTH = maximum number of shares back client uses to compute payout | ||
# REAL_CHAIN_LENGTH must always be <= CHAIN_LENGTH | ||
# REAL_CHAIN_LENGTH must be changed in sync with all other clients | ||
# changes can be done by changing one, then the other | ||
''') | ||
elif sys.argv[3] == 'bitcoin': | ||
f2.write('''import os | ||
import platform | ||
from twisted.internet import defer | ||
from .. import data, helper | ||
from p2pool.util import pack | ||
''') | ||
else: assert False, 'invalid type argument' | ||
|
||
while True: | ||
l = f.readline() | ||
if not l.strip(): continue | ||
if l.strip() == ')': break | ||
|
||
name = l.strip().split('=')[0] | ||
|
||
lines = [] | ||
while True: | ||
l = f.readline() | ||
if not l.strip(): continue | ||
if l.strip() == '),': break | ||
while nesting(l) != 0: | ||
l += f.readline() | ||
lines.append(l.split('=', 1)) | ||
with open(sys.argv[2] + name + '.py', 'wb') as f2: | ||
write_header(f2, name) | ||
for a, b in lines: | ||
if ', #' in b: b = b.replace(', #', ' #') | ||
elif b.strip().endswith(','): b = b.strip()[:-1] | ||
else: assert False, b | ||
f2.write('%s = %s\n' % (a.strip(), b.strip())) |