Make progress bar
This commit is contained in:
parent
adc85c76c4
commit
adf007bf30
5
Makefile
5
Makefile
@ -31,3 +31,8 @@ reset:
|
||||
@echo "Hard-resetting Onionr..."
|
||||
rm -rf onionr/data/ | true > /dev/null 2>&1
|
||||
#@./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
|
||||
|
@ -541,7 +541,7 @@ class OnionrCommunicate:
|
||||
logger.warn('Block is unsaved: %s' % str(i))
|
||||
data = self.downloadBlock(i)
|
||||
|
||||
# if block was successfull gotten (hash already verified)
|
||||
# if block was successfully gotten (hash already verified)
|
||||
if data:
|
||||
del self.newHashes[i] # remove from probation list
|
||||
|
||||
|
@ -109,7 +109,6 @@ class Onionr:
|
||||
os.mkdir('data/blocks/')
|
||||
|
||||
# Copy default plugins into plugins folder
|
||||
|
||||
if not os.path.exists(plugins.get_plugins_folder()):
|
||||
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)]
|
||||
|
@ -18,7 +18,7 @@
|
||||
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
|
||||
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
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
@ -448,6 +448,23 @@ class OnionrUtils:
|
||||
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='.'):
|
||||
'''
|
||||
Returns the size of a folder's contents in bytes
|
||||
@ -465,6 +482,9 @@ def size(path='.'):
|
||||
return total
|
||||
|
||||
def humanSize(num, suffix='B'):
|
||||
'''
|
||||
Converts from bytes to a human readable format.
|
||||
'''
|
||||
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
|
||||
if abs(num) < 1024.0:
|
||||
return "%.1f %s%s" % (num, unit, suffix)
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
# useful libraries
|
||||
import logger, config
|
||||
import os, sys, json
|
||||
import os, sys, json, time, random
|
||||
|
||||
plugin_name = 'pluginmanager'
|
||||
|
||||
@ -100,6 +100,14 @@ def commandInstallPlugin():
|
||||
elif valid_hash and real_block:
|
||||
blockhash = str(pkobh)
|
||||
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:
|
||||
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.')
|
||||
@ -108,6 +116,14 @@ def commandInstallPlugin():
|
||||
logger.debug('Using public key %s...' % publickey)
|
||||
|
||||
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:
|
||||
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh))
|
||||
return
|
Loading…
Reference in New Issue
Block a user