From 24292ca269ef591da6448f8b1dd92045d29e68ac Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Wed, 23 Mar 2016 03:34:50 +0300 Subject: [PATCH] Create setup.py for getseeds script. --- contrib/seeds/getseeds.py | 100 ------------------------------------ contrib/seeds/getseeds/getseeds.py | 100 ++++++++++++++++++++++++++++++++++++ contrib/seeds/getseeds/setup.py | 10 ++++ 3 files changed, 110 insertions(+), 100 deletions(-) delete mode 100755 contrib/seeds/getseeds.py create mode 100755 contrib/seeds/getseeds/getseeds.py create mode 100644 contrib/seeds/getseeds/setup.py diff --git a/contrib/seeds/getseeds.py b/contrib/seeds/getseeds.py deleted file mode 100755 index 7a208e8..0000000 --- a/contrib/seeds/getseeds.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/python3 - -### -### Automatic seeding over HTTP -### (C) 2016 Alex D. -### -### http://www.gnu.org/licenses/agpl-3.0.en.html -### - -import os -import sys -import json -import random -import platform -import urllib.request - -sources = ['http://dalexhz1.cloudapp.net', 'http://dalexhz2.cloudapp.net', 'http://dalexhz4.cloudapp.net', 'http://dalexhz5.cloudapp.net'] -data = urllib.request.urlopen(random.choice(sources)).readall(); - -if 'norpc' in sys.argv: - for node in json.loads(data.decode()): - print (node) - sys.exit() - -### This module is required to function properly: -### https://github.com/jgarzik/python-bitcoinrpc - -import errno -from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException -from socket import error as socket_error - -def confFile(): - folder = '' - if platform.system() == 'Windows': - folder = os.path.join(os.path.join(os.environ['APPDATA'], 'NovaCoin')) - else: - if platform.system() == 'Darwin': - folder = os.path.expanduser('~/Library/Application Support/NovaCoin/') - else: - folder = os.path.expanduser('~/.novacoin') - - return os.path.join(folder, 'novacoin.conf') - -conf_path = confFile() -if not os.path.exists(conf_path): - parser.error('''Novacoin configuration file not found. Manually enter your RPC password.\r\n''' - '''If you actually haven't created a configuration file, you should create one at %s with the text like this:\r\n''' - '''\r\n''' - '''server=1\r\n''' - '''rpcuser=yourname\r\n''' - '''rpcpassword=%x\r\n''' - '''\r\n''' - '''Keep that password secret! After creating the file, restart Novacoin.''' % (conf_path, random.randrange(2**128))) - -conf = open(conf_path, 'rb').read() -contents = {} - -for line in conf.splitlines(True): - if line.startswith(b'#'): - line = line[:line.index('#')] - if not line.__contains__(b'='): - continue - k, v = line.split(b'=', 1) - contents[k.strip()] = v.strip() - -print(contents) - -if b'rpcpassword' not in contents.keys(): - print('''RPC password is not found in the %s file.''' % (conf_path)) - sys.exit() - -if b'rpcuser' not in contents.keys(): - print('''RPC user is not found in the %s file.''' % (conf_path)) - sys.exit() - -rpcuser = contents[b'rpcuser'].decode() -rpcpassword = contents[b'rpcpassword'].decode() -rpcport = 8344 -rpclisten = '127.0.0.1' - -if b'rpcport' in contents.keys(): - rpcport = contents[b'rpcport'].decode() -if b'rpclisten' in contents.keys(): - rpclisten = contents[b'rpclisten'].decode() - -access = AuthServiceProxy("http://"+rpcuser+":"+rpcpassword+"@"+rpclisten+":"+rpcport+"/") - -for node in json.loads(data.decode()): - print ('Adding', node) - try: - access.addnode(node, 'add') - except socket_error as e: - if e.errno == errno.ECONNREFUSED: - print ('Unable to communicate with Novacoin RPC') - break - except JSONRPCException as e: - if e.code == -23: - print ('Already added') - continue - break diff --git a/contrib/seeds/getseeds/getseeds.py b/contrib/seeds/getseeds/getseeds.py new file mode 100755 index 0000000..7a208e8 --- /dev/null +++ b/contrib/seeds/getseeds/getseeds.py @@ -0,0 +1,100 @@ +#!/usr/bin/python3 + +### +### Automatic seeding over HTTP +### (C) 2016 Alex D. +### +### http://www.gnu.org/licenses/agpl-3.0.en.html +### + +import os +import sys +import json +import random +import platform +import urllib.request + +sources = ['http://dalexhz1.cloudapp.net', 'http://dalexhz2.cloudapp.net', 'http://dalexhz4.cloudapp.net', 'http://dalexhz5.cloudapp.net'] +data = urllib.request.urlopen(random.choice(sources)).readall(); + +if 'norpc' in sys.argv: + for node in json.loads(data.decode()): + print (node) + sys.exit() + +### This module is required to function properly: +### https://github.com/jgarzik/python-bitcoinrpc + +import errno +from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException +from socket import error as socket_error + +def confFile(): + folder = '' + if platform.system() == 'Windows': + folder = os.path.join(os.path.join(os.environ['APPDATA'], 'NovaCoin')) + else: + if platform.system() == 'Darwin': + folder = os.path.expanduser('~/Library/Application Support/NovaCoin/') + else: + folder = os.path.expanduser('~/.novacoin') + + return os.path.join(folder, 'novacoin.conf') + +conf_path = confFile() +if not os.path.exists(conf_path): + parser.error('''Novacoin configuration file not found. Manually enter your RPC password.\r\n''' + '''If you actually haven't created a configuration file, you should create one at %s with the text like this:\r\n''' + '''\r\n''' + '''server=1\r\n''' + '''rpcuser=yourname\r\n''' + '''rpcpassword=%x\r\n''' + '''\r\n''' + '''Keep that password secret! After creating the file, restart Novacoin.''' % (conf_path, random.randrange(2**128))) + +conf = open(conf_path, 'rb').read() +contents = {} + +for line in conf.splitlines(True): + if line.startswith(b'#'): + line = line[:line.index('#')] + if not line.__contains__(b'='): + continue + k, v = line.split(b'=', 1) + contents[k.strip()] = v.strip() + +print(contents) + +if b'rpcpassword' not in contents.keys(): + print('''RPC password is not found in the %s file.''' % (conf_path)) + sys.exit() + +if b'rpcuser' not in contents.keys(): + print('''RPC user is not found in the %s file.''' % (conf_path)) + sys.exit() + +rpcuser = contents[b'rpcuser'].decode() +rpcpassword = contents[b'rpcpassword'].decode() +rpcport = 8344 +rpclisten = '127.0.0.1' + +if b'rpcport' in contents.keys(): + rpcport = contents[b'rpcport'].decode() +if b'rpclisten' in contents.keys(): + rpclisten = contents[b'rpclisten'].decode() + +access = AuthServiceProxy("http://"+rpcuser+":"+rpcpassword+"@"+rpclisten+":"+rpcport+"/") + +for node in json.loads(data.decode()): + print ('Adding', node) + try: + access.addnode(node, 'add') + except socket_error as e: + if e.errno == errno.ECONNREFUSED: + print ('Unable to communicate with Novacoin RPC') + break + except JSONRPCException as e: + if e.code == -23: + print ('Already added') + continue + break diff --git a/contrib/seeds/getseeds/setup.py b/contrib/seeds/getseeds/setup.py new file mode 100644 index 0000000..0a79775 --- /dev/null +++ b/contrib/seeds/getseeds/setup.py @@ -0,0 +1,10 @@ +from distutils.core import setup +import py2exe, sys, os + +sys.argv.append('py2exe') + +setup( + options = {'py2exe': {'bundle_files': 1, 'compressed': True}}, + windows = [{'script': "getseeds.py"}], + zipfile = None, +) -- 1.7.1