mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-24 00:24:19 +01:00
summary: fix flake8 nits
This commit is contained in:
committed by
Christian Decker
parent
258c0e647a
commit
2034c29214
@@ -4,7 +4,6 @@ from packaging import version
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from summary_avail import *
|
from summary_avail import *
|
||||||
import pyln.client
|
import pyln.client
|
||||||
from math import floor, log10
|
|
||||||
import requests
|
import requests
|
||||||
import shelve
|
import shelve
|
||||||
import threading
|
import threading
|
||||||
@@ -73,7 +72,7 @@ class PriceThread(threading.Thread):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
plugin.log("[PriceThread] " + str(ex), 'warn')
|
plugin.log("[PriceThread] " + str(ex), 'warn')
|
||||||
# Six hours is more than often enough for polling
|
# Six hours is more than often enough for polling
|
||||||
time.sleep(6*3600)
|
time.sleep(6 * 3600)
|
||||||
|
|
||||||
|
|
||||||
def to_fiatstr(msat: Millisatoshi):
|
def to_fiatstr(msat: Millisatoshi):
|
||||||
@@ -174,7 +173,6 @@ def summary(plugin, exclude=''):
|
|||||||
# Create simple line graph, 47 chars wide.
|
# Create simple line graph, 47 chars wide.
|
||||||
our_len = int(round(int(c.ours) / biggest * 23))
|
our_len = int(round(int(c.ours) / biggest * 23))
|
||||||
their_len = int(round(int(c.theirs) / biggest * 23))
|
their_len = int(round(int(c.theirs) / biggest * 23))
|
||||||
divided = False
|
|
||||||
|
|
||||||
# We put midpoint in the middle.
|
# We put midpoint in the middle.
|
||||||
mid = draw.mid
|
mid = draw.mid
|
||||||
@@ -235,7 +233,7 @@ def init(options, configuration, plugin):
|
|||||||
plugin.avail_interval = float(options['summary-availability-interval'])
|
plugin.avail_interval = float(options['summary-availability-interval'])
|
||||||
plugin.avail_window = 60 * 60 * int(options['summary-availability-window'])
|
plugin.avail_window = 60 * 60 * int(options['summary-availability-window'])
|
||||||
plugin.persist = shelve.open('summary.dat', writeback=True)
|
plugin.persist = shelve.open('summary.dat', writeback=True)
|
||||||
if not 'peerstate' in plugin.persist:
|
if 'peerstate' not in plugin.persist:
|
||||||
plugin.persist['peerstate'] = {}
|
plugin.persist['peerstate'] = {}
|
||||||
plugin.persist['availcount'] = 0
|
plugin.persist['availcount'] = 0
|
||||||
|
|
||||||
@@ -246,8 +244,8 @@ def init(options, configuration, plugin):
|
|||||||
# Default port in 9050
|
# Default port in 9050
|
||||||
if ':' not in paddr:
|
if ':' not in paddr:
|
||||||
paddr += ':9050'
|
paddr += ':9050'
|
||||||
proxies = { 'https': 'socks5h://' + paddr,
|
proxies = {'https': 'socks5h://' + paddr,
|
||||||
'http': 'socks5h://' + paddr }
|
'http': 'socks5h://' + paddr}
|
||||||
else:
|
else:
|
||||||
proxies = None
|
proxies = None
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# ensure an rpc peer is added
|
# ensure an rpc peer is added
|
||||||
|
|
||||||
|
|
||||||
def addpeer(p, rpcpeer):
|
def addpeer(p, rpcpeer):
|
||||||
pid = rpcpeer['id']
|
pid = rpcpeer['id']
|
||||||
if not pid in p.persist['peerstate']:
|
if pid not in p.persist['peerstate']:
|
||||||
p.persist['peerstate'][pid] = {
|
p.persist['peerstate'][pid] = {
|
||||||
'connected' : rpcpeer['connected'],
|
'connected': rpcpeer['connected'],
|
||||||
'last_seen' : datetime.now() if rpcpeer['connected'] else None,
|
'last_seen': datetime.now() if rpcpeer['connected'] else None,
|
||||||
'avail' : 1.0 if rpcpeer['connected'] else 0.0
|
'avail': 1.0 if rpcpeer['connected'] else 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import subprocess
|
|||||||
import unittest
|
import unittest
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
from pyln.client import Plugin
|
from pyln.client import Plugin
|
||||||
from pyln.testing.fixtures import * # noqa: F401,F403
|
from pyln.testing.fixtures import * # noqa: F401,F403
|
||||||
@@ -26,7 +27,7 @@ def get_stub():
|
|||||||
def test_summary_peer_thread(node_factory):
|
def test_summary_peer_thread(node_factory):
|
||||||
# in order to give the PeerThread a chance in a unit test
|
# in order to give the PeerThread a chance in a unit test
|
||||||
# we need to give it a low interval
|
# we need to give it a low interval
|
||||||
opts = {'summary-availability-interval' : 0.1}
|
opts = {'summary-availability-interval': 0.1}
|
||||||
opts.update(pluginopt)
|
opts.update(pluginopt)
|
||||||
l1, l2 = node_factory.line_graph(2, opts=opts)
|
l1, l2 = node_factory.line_graph(2, opts=opts)
|
||||||
|
|
||||||
@@ -49,10 +50,10 @@ def test_summary_avail_101():
|
|||||||
# given
|
# given
|
||||||
plugin = get_stub()
|
plugin = get_stub()
|
||||||
rpcpeers = {
|
rpcpeers = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : True },
|
{'id': '1', 'connected': True},
|
||||||
{ 'id' : '2', 'connected' : False },
|
{'id': '2', 'connected': False},
|
||||||
{ 'id' : '3', 'connected' : True },
|
{'id': '3', 'connected': True},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,9 +65,9 @@ def test_summary_avail_101():
|
|||||||
assert(plugin.persist['peerstate']['1']['avail'] == 1.0)
|
assert(plugin.persist['peerstate']['1']['avail'] == 1.0)
|
||||||
assert(plugin.persist['peerstate']['2']['avail'] == 0.0)
|
assert(plugin.persist['peerstate']['2']['avail'] == 0.0)
|
||||||
assert(plugin.persist['peerstate']['3']['avail'] == 1.0)
|
assert(plugin.persist['peerstate']['3']['avail'] == 1.0)
|
||||||
assert(plugin.persist['peerstate']['1']['connected'] == True)
|
assert(plugin.persist['peerstate']['1']['connected'] is True)
|
||||||
assert(plugin.persist['peerstate']['2']['connected'] == False)
|
assert(plugin.persist['peerstate']['2']['connected'] is False)
|
||||||
assert(plugin.persist['peerstate']['3']['connected'] == True)
|
assert(plugin.persist['peerstate']['3']['connected'] is True)
|
||||||
|
|
||||||
|
|
||||||
# tests for 50% downtime
|
# tests for 50% downtime
|
||||||
@@ -74,13 +75,13 @@ def test_summary_avail_50():
|
|||||||
# given
|
# given
|
||||||
plugin = get_stub()
|
plugin = get_stub()
|
||||||
rpcpeers_on = {
|
rpcpeers_on = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : True },
|
{'id': '1', 'connected': True},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
rpcpeers_off = {
|
rpcpeers_off = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : False },
|
{'id': '1', 'connected': False},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,13 +100,13 @@ def test_summary_avail_33():
|
|||||||
# given
|
# given
|
||||||
plugin = get_stub()
|
plugin = get_stub()
|
||||||
rpcpeers_on = {
|
rpcpeers_on = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : True },
|
{'id': '1', 'connected': True},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
rpcpeers_off = {
|
rpcpeers_off = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : False },
|
{'id': '1', 'connected': False},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,13 +125,13 @@ def test_summary_avail_66():
|
|||||||
# given
|
# given
|
||||||
plugin = get_stub()
|
plugin = get_stub()
|
||||||
rpcpeers_on = {
|
rpcpeers_on = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : True },
|
{'id': '1', 'connected': True},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
rpcpeers_off = {
|
rpcpeers_off = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : False },
|
{'id': '1', 'connected': False},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,13 +151,13 @@ def test_summary_avail_leadwin():
|
|||||||
# given
|
# given
|
||||||
plugin = get_stub()
|
plugin = get_stub()
|
||||||
rpcpeers_on = {
|
rpcpeers_on = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : True },
|
{'id': '1', 'connected': True},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
rpcpeers_off = {
|
rpcpeers_off = {
|
||||||
'peers' : [
|
'peers': [
|
||||||
{ 'id' : '1', 'connected' : False },
|
{'id': '1', 'connected': False},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user