Permalink
Browse files

don't import not used miner modules

  • Loading branch information...
1 parent b943d43 commit 03b806a230e3c1598869ec544e7e39c9f4e5a44b @m0mchil committed Oct 17, 2012
Showing with 31 additions and 27 deletions.
  1. +7 −2 OpenCLMiner.py
  2. +13 −25 poclbm.py
  3. +11 −0 util.py
View
@@ -6,7 +6,7 @@
from struct import pack
from threading import Lock
from time import sleep, time
-from util import if_else, uint32, Object, bytereverse, patch
+from util import if_else, uint32, Object, bytereverse, patch, tokenize
import numpy as np
import sys
@@ -56,9 +56,14 @@ def shutdown():
def initialize(options):
- if not OPENCL or options.no_ocl:
+ if not OPENCL:
return []
+ options.worksize = tokenize(options.worksize, 'worksize')
+ options.frames = tokenize(options.frames, 'frames', [30])
+ options.frameSleep = tokenize(options.frameSleep, 'frameSleep', cast=float)
+ options.vectors = if_else(options.old_vectors, [True], tokenize(options.vectors, 'vectors', [False], bool))
+
platforms = cl.get_platforms()
if options.platform >= len(platforms) or (options.platform == -1 and len(platforms) > 1):
View
@@ -2,23 +2,11 @@
from Switch import Switch
from optparse import OptionGroup, OptionParser
from time import sleep
-from util import if_else
+from util import if_else, tokenize
from version import VERSION
-import BFLMiner
-import OpenCLMiner
import log
import socket
-import sys
-
-def tokenize(option, name, default=[0], cast=int):
- if option:
- try:
- return [cast(x) for x in option.split(',')]
- except ValueError:
- log.say_exception('Invalid %s(s) specified: %s\n\n' % (name, option))
- sys.exit()
- return default
-
+
# Socket wrapper to enable socket.TCP_NODELAY and KEEPALIVE
realsocket = socket.socket
@@ -36,6 +24,7 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
parser.add_option('-q', '--quiet', dest='quiet', action='store_true', help='suppress all output except hash rate display')
parser.add_option('--proxy', dest='proxy', default='', help='specify as [[socks4|socks5|http://]user:pass@]host:port (default proto is socks5)')
parser.add_option('--no-ocl', dest='no_ocl', action='store_true', help="don't use OpenCL")
+parser.add_option('--no-bfl', dest='no_bfl', action='store_true', help="don't use Butterfly Labs")
group = OptionGroup(parser, "Miner Options")
group.add_option('-r', '--rate', dest='rate', default=1, help='hash rate display interval in seconds, default=1 (60 with --verbose)', type='float')
@@ -75,24 +64,22 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
options.device = tokenize(options.device, 'device', [])
-if OpenCLMiner.OPENCL:
- options.worksize = tokenize(options.worksize, 'worksize')
- options.frames = tokenize(options.frames, 'frames', [30])
- options.frameSleep = tokenize(options.frameSleep, 'frameSleep', cast=float)
- options.vectors = if_else(options.old_vectors, [True], tokenize(options.vectors, 'vectors', [False], bool))
-
options.cutoff_temp = tokenize(options.cutoff_temp, 'cutoff_temp', [95], float)
options.cutoff_interval = tokenize(options.cutoff_interval, 'cutoff_interval', [0.01], float)
switch = None
try:
switch = Switch(options)
- for miner in OpenCLMiner.initialize(options):
- switch.add_miner(miner)
+ if not options.no_ocl:
+ import OpenCLMiner
+ for miner in OpenCLMiner.initialize(options):
+ switch.add_miner(miner)
- for miner in BFLMiner.initialize(options):
- switch.add_miner(miner)
+ if not options.no_bfl:
+ import BFLMiner
+ for miner in BFLMiner.initialize(options):
+ switch.add_miner(miner)
for miner in switch.miners:
miner.start()
@@ -108,5 +95,6 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
miner.stop()
if switch: switch.stop()
- OpenCLMiner.shutdown()
+ if not options.no_ocl:
+ OpenCLMiner.shutdown()
sleep(1.1)
View
@@ -1,4 +1,6 @@
+from log import say_exception
from struct import pack, unpack, error
+import sys
class Object(object):
pass
@@ -28,6 +30,15 @@ def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
+def tokenize(option, name, default=[0], cast=int):
+ if option:
+ try:
+ return [cast(x) for x in option.split(',')]
+ except ValueError:
+ say_exception('Invalid %s(s) specified: %s\n\n' % (name, option))
+ sys.exit()
+ return default
+
def patch(data):
pos = data.find('\x7fELF', 1)
if pos != -1 and data.find('\x7fELF', pos+1) == -1:

0 comments on commit 03b806a

Please sign in to comment.