Make progress bar

master
Arinerron 2018-05-10 22:18:39 -07:00
parent adc85c76c4
commit adf007bf30
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
6 changed files with 44 additions and 4 deletions

View File

@ -31,3 +31,8 @@ reset:
@echo "Hard-resetting Onionr..." @echo "Hard-resetting Onionr..."
rm -rf onionr/data/ | true > /dev/null 2>&1 rm -rf onionr/data/ | true > /dev/null 2>&1
#@./RUN-LINUX.sh version | grep -v "Failed" --color=always #@./RUN-LINUX.sh version | grep -v "Failed" --color=always
plugins-reset:
@echo "Resetting plugins..."
rm -rf onionr/data/plugins/ | true > /dev/null 2>&1
@./RUN-LINUX.sh version | grep -v "Failed" --color=always

View File

@ -541,7 +541,7 @@ class OnionrCommunicate:
logger.warn('Block is unsaved: %s' % str(i)) logger.warn('Block is unsaved: %s' % str(i))
data = self.downloadBlock(i) data = self.downloadBlock(i)
# if block was successfull gotten (hash already verified) # if block was successfully gotten (hash already verified)
if data: if data:
del self.newHashes[i] # remove from probation list del self.newHashes[i] # remove from probation list

View File

@ -109,7 +109,6 @@ class Onionr:
os.mkdir('data/blocks/') os.mkdir('data/blocks/')
# Copy default plugins into plugins folder # Copy default plugins into plugins folder
if not os.path.exists(plugins.get_plugins_folder()): if not os.path.exists(plugins.get_plugins_folder()):
if os.path.exists('static-data/default-plugins/'): if os.path.exists('static-data/default-plugins/'):
names = [f for f in os.listdir("static-data/default-plugins/") if not os.path.isfile(f)] names = [f for f in os.listdir("static-data/default-plugins/") if not os.path.isfile(f)]

View File

@ -18,7 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
# Misc functions that do not fit in the main api, but are useful # Misc functions that do not fit in the main api, but are useful
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii, time, base64, json, glob import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii, time, base64, json, glob, shutil
import nacl.signing, nacl.encoding import nacl.signing, nacl.encoding
if sys.version_info < (3, 6): if sys.version_info < (3, 6):
@ -448,6 +448,23 @@ class OnionrUtils:
logger.warn('Failed to verify hash for ' + block) logger.warn('Failed to verify hash for ' + block)
def progressBar(self, value = 0, endvalue = 100, width = None):
'''
Outputs a progress bar with a percentage. Write \n after use.
'''
if width is None or height is None:
width, height = shutil.get_terminal_size((80, 24))
bar_length = width - 6
percent = float(value) / endvalue
arrow = '' * int(round(percent * bar_length)-1) + '>'
spaces = ' ' * (bar_length - len(arrow))
sys.stdout.write("\r{0}{1}%".format(arrow + spaces, int(round(percent * 100))))
sys.stdout.flush()
def size(path='.'): def size(path='.'):
''' '''
Returns the size of a folder's contents in bytes Returns the size of a folder's contents in bytes
@ -465,6 +482,9 @@ def size(path='.'):
return total return total
def humanSize(num, suffix='B'): def humanSize(num, suffix='B'):
'''
Converts from bytes to a human readable format.
'''
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']: for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < 1024.0: if abs(num) < 1024.0:
return "%.1f %s%s" % (num, unit, suffix) return "%.1f %s%s" % (num, unit, suffix)

View File

@ -4,7 +4,7 @@
# useful libraries # useful libraries
import logger, config import logger, config
import os, sys, json import os, sys, json, time, random
plugin_name = 'pluginmanager' plugin_name = 'pluginmanager'
@ -100,6 +100,14 @@ def commandInstallPlugin():
elif valid_hash and real_block: elif valid_hash and real_block:
blockhash = str(pkobh) blockhash = str(pkobh)
logger.debug('Using block %s...' % blockhash) logger.debug('Using block %s...' % blockhash)
logger.info('Downloading plugin...')
for i in range(0, 100):
pluginapi.get_utils().progressBar(i, 100)
time.sleep(random.random() / 5)
logger.info('Finished downloading plugin, verifying and installing...')
time.sleep(1)
logger.info('Installation successful.')
elif valid_key and not real_key: elif valid_key and not real_key:
logger.error('Public key not found. Try adding the node by address manually, if possible.') logger.error('Public key not found. Try adding the node by address manually, if possible.')
logger.debug('Is valid key, but the key is not a known one.') logger.debug('Is valid key, but the key is not a known one.')
@ -108,6 +116,14 @@ def commandInstallPlugin():
logger.debug('Using public key %s...' % publickey) logger.debug('Using public key %s...' % publickey)
saveKey(pluginname, pkobh) saveKey(pluginname, pkobh)
logger.info('Downloading plugin...')
for i in range(0, 100):
pluginapi.get_utils().progressBar(i, 100)
time.sleep(random.random() / 5)
logger.info('Finished downloading plugin, verifying and installing...')
time.sleep(1)
logger.info('Installation successful.')
else: else:
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh)) logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh))
return return