mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
reckless: fix CLI redirect, minor cleanup
This commit is contained in:
committed by
ShahanaFarooqui
parent
cc7d9f39be
commit
b59b6b9cec
@@ -43,7 +43,7 @@ class InstInfo:
|
|||||||
self.commit = None
|
self.commit = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return (f'InstInfo({self.name}, {self.repo}, {self.git_url}'
|
return (f'InstInfo({self.name}, {self.repo}, {self.git_url}, '
|
||||||
f'{self.entry}, {self.deps})')
|
f'{self.entry}, {self.deps})')
|
||||||
|
|
||||||
def get_inst_details(self):
|
def get_inst_details(self):
|
||||||
@@ -53,7 +53,8 @@ class InstInfo:
|
|||||||
"""
|
"""
|
||||||
if "api.github.com" in self.git_url:
|
if "api.github.com" in self.git_url:
|
||||||
# This lets us redirect to handle blackbox testing
|
# This lets us redirect to handle blackbox testing
|
||||||
redir_addr = API_GITHUB_COM + self.git_url.split("api.github.com")[-1]
|
redir_addr = (API_GITHUB_COM +
|
||||||
|
self.git_url.split("api.github.com")[-1])
|
||||||
r = urlopen(redir_addr, timeout=5)
|
r = urlopen(redir_addr, timeout=5)
|
||||||
else:
|
else:
|
||||||
r = urlopen(self.git_url, timeout=5)
|
r = urlopen(self.git_url, timeout=5)
|
||||||
@@ -104,6 +105,7 @@ def create_dir(r: int, directory: PosixPath) -> bool:
|
|||||||
print(f'created directory {directory}')
|
print(f'created directory {directory}')
|
||||||
assert directory.exists()
|
assert directory.exists()
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def remove_dir(target: str) -> bool:
|
def remove_dir(target: str) -> bool:
|
||||||
@@ -148,7 +150,8 @@ class Config():
|
|||||||
# FIXME: Handle write failure
|
# FIXME: Handle write failure
|
||||||
return default_text
|
return default_text
|
||||||
else:
|
else:
|
||||||
logging.debug(f'could not create the parent directory {parent_path}')
|
logging.debug('could not create the parent directory ' +
|
||||||
|
parent_path)
|
||||||
raise FileNotFoundError('invalid parent directory')
|
raise FileNotFoundError('invalid parent directory')
|
||||||
|
|
||||||
def editConfigFile(self, addline: str, removeline: str):
|
def editConfigFile(self, addline: str, removeline: str):
|
||||||
@@ -287,7 +290,7 @@ def _search_repo(name: str, url: str) -> InstInfo:
|
|||||||
plugins_cont = api_url
|
plugins_cont = api_url
|
||||||
r = urlopen(plugins_cont, timeout=5)
|
r = urlopen(plugins_cont, timeout=5)
|
||||||
if r.status != 200:
|
if r.status != 200:
|
||||||
print("Plugin repository unavailable")
|
print(f"Plugin repository {api_url} unavailable")
|
||||||
return False
|
return False
|
||||||
# Repo is for this plugin
|
# Repo is for this plugin
|
||||||
if repo_name == name:
|
if repo_name == name:
|
||||||
@@ -316,7 +319,8 @@ def _search_repo(name: str, url: str) -> InstInfo:
|
|||||||
MyPlugin.repo = MyPlugin.repo.split('/tree/')[0]
|
MyPlugin.repo = MyPlugin.repo.split('/tree/')[0]
|
||||||
logging.debug(f'repo using commit: {MyPlugin.commit}')
|
logging.debug(f'repo using commit: {MyPlugin.commit}')
|
||||||
if not MyPlugin.get_inst_details():
|
if not MyPlugin.get_inst_details():
|
||||||
logging.debug(f"Found plugin in {url}, but missing install details")
|
logging.debug((f'Found plugin in {url}, but missing install '
|
||||||
|
'details'))
|
||||||
return False
|
return False
|
||||||
return MyPlugin
|
return MyPlugin
|
||||||
return False
|
return False
|
||||||
@@ -399,7 +403,7 @@ def _install_plugin(src: InstInfo) -> bool:
|
|||||||
logging.debug(pip.stdout.read())
|
logging.debug(pip.stdout.read())
|
||||||
return False
|
return False
|
||||||
test = Popen([Path(plugin_path).joinpath(src.entry)], cwd=str(plugin_path),
|
test = Popen([Path(plugin_path).joinpath(src.entry)], cwd=str(plugin_path),
|
||||||
stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
stdout=PIPE, stderr=PIPE, text=True)
|
||||||
test_log = []
|
test_log = []
|
||||||
with test.stderr:
|
with test.stderr:
|
||||||
for line in test.stderr:
|
for line in test.stderr:
|
||||||
@@ -526,7 +530,8 @@ def enable(plugin_name: str):
|
|||||||
print(f'reckless: {inst.name} failed to start!')
|
print(f'reckless: {inst.name} failed to start!')
|
||||||
raise err
|
raise err
|
||||||
except RPCError:
|
except RPCError:
|
||||||
logging.debug('lightningd rpc unavailable. Skipping dynamic activation.')
|
logging.debug(('lightningd rpc unavailable. '
|
||||||
|
'Skipping dynamic activation.'))
|
||||||
RECKLESS_CONFIG.enable_plugin(path)
|
RECKLESS_CONFIG.enable_plugin(path)
|
||||||
print(f'{plugin_name} enabled')
|
print(f'{plugin_name} enabled')
|
||||||
|
|
||||||
@@ -550,7 +555,8 @@ def disable(plugin_name: str):
|
|||||||
print('lightning-cli plugin stop failed')
|
print('lightning-cli plugin stop failed')
|
||||||
raise err
|
raise err
|
||||||
except RPCError:
|
except RPCError:
|
||||||
logging.debug('lightningd rpc unavailable. Skipping dynamic deactivation.')
|
logging.debug(('lightningd rpc unavailable. '
|
||||||
|
'Skipping dynamic deactivation.'))
|
||||||
RECKLESS_CONFIG.disable_plugin(path)
|
RECKLESS_CONFIG.disable_plugin(path)
|
||||||
print(f'{plugin_name} disabled')
|
print(f'{plugin_name} disabled')
|
||||||
|
|
||||||
@@ -674,10 +680,12 @@ if __name__ == '__main__':
|
|||||||
type=str,
|
type=str,
|
||||||
default=None)
|
default=None)
|
||||||
parser.add_argument('-r', '--regtest', action='store_true')
|
parser.add_argument('-r', '--regtest', action='store_true')
|
||||||
parser.add_argument('--network', help="specify a network to use (default: bitcoin)",
|
parser.add_argument('--network',
|
||||||
|
help="specify a network to use (default: bitcoin)",
|
||||||
type=str)
|
type=str)
|
||||||
parser.add_argument('-v', '--verbose', action="store_const",
|
parser.add_argument('-v', '--verbose', action="store_const",
|
||||||
dest="loglevel", const=logging.DEBUG, default=logging.WARNING)
|
dest="loglevel", const=logging.DEBUG,
|
||||||
|
default=logging.WARNING)
|
||||||
cmd1 = parser.add_subparsers(dest='cmd1', help='command',
|
cmd1 = parser.add_subparsers(dest='cmd1', help='command',
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
@@ -737,7 +745,7 @@ if __name__ == '__main__':
|
|||||||
LIGHTNING_DIR = Path(args.lightning)
|
LIGHTNING_DIR = Path(args.lightning)
|
||||||
# This env variable is set under CI testing
|
# This env variable is set under CI testing
|
||||||
LIGHTNING_CLI_CALL = [os.environ.get('LIGHTNING_CLI')]
|
LIGHTNING_CLI_CALL = [os.environ.get('LIGHTNING_CLI')]
|
||||||
if LIGHTNING_CLI_CALL is None:
|
if LIGHTNING_CLI_CALL == [None]:
|
||||||
LIGHTNING_CLI_CALL = ['lightning-cli']
|
LIGHTNING_CLI_CALL = ['lightning-cli']
|
||||||
if NETWORK != 'bitcoin':
|
if NETWORK != 'bitcoin':
|
||||||
LIGHTNING_CLI_CALL.append(f'--network={NETWORK}')
|
LIGHTNING_CLI_CALL.append(f'--network={NETWORK}')
|
||||||
|
|||||||
Reference in New Issue
Block a user