Permalink
Browse files

added helper scripts

  • Loading branch information...
1 parent b8fd75c commit 4661d3b9e7b807b4e0fdd38d67ffdf250d1ab701 @forrestv forrestv committed Jun 22, 2014
Showing with 87 additions and 0 deletions.
  1. +27 −0 dev/convert_networks
  2. +60 −0 dev/convert_networks.py
View
@@ -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
@@ -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()))

0 comments on commit 4661d3b

Please sign in to comment.