Unix: Import external plugins from /opt/electrum_plugins
This commit is contained in:
@@ -12,7 +12,10 @@ if len(sys.argv) != 2:
|
||||
print(f"usage: {os.path.basename(__file__)} <plugin_directory>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
source_dir = sys.argv[1] # where the plugin source code is
|
||||
if source_dir.endswith('/'):
|
||||
source_dir = source_dir[:-1]
|
||||
|
||||
plugin_name = os.path.basename(source_dir)
|
||||
dest_dir = os.path.dirname(source_dir)
|
||||
@@ -31,39 +34,16 @@ with zipfile.ZipFile(zip_path, 'w') as zip_object:
|
||||
zip_object.write(file_path, dest_path)
|
||||
print('added', dest_path)
|
||||
|
||||
# read hash
|
||||
with open(zip_path, 'rb') as f:
|
||||
s = f.read()
|
||||
_hash = bytes(hashlib.sha256(s).digest()).hex()
|
||||
|
||||
# read metadata
|
||||
# read version
|
||||
zip_file = zipimport.zipimporter(zip_path)
|
||||
module = zip_file.load_module(plugin_name)
|
||||
plugin_metadata = {
|
||||
'hash': _hash,
|
||||
'description': module.description,
|
||||
'display_name': module.fullname,
|
||||
'available_for': module.available_for,
|
||||
'download_url': module.download_url,
|
||||
'author': module.author,
|
||||
'licence': module.licence,
|
||||
'version': module.version,
|
||||
}
|
||||
print(json.dumps(plugin_metadata, indent=4))
|
||||
|
||||
# update plugins.json file
|
||||
json_path = os.path.join(os.path.dirname(__file__), '..', 'electrum', 'plugins.json')
|
||||
with open(json_path, 'r') as f:
|
||||
s = f.read()
|
||||
try:
|
||||
metadata = json.loads(s)
|
||||
except:
|
||||
metadata = {}
|
||||
metadata[plugin_name] = plugin_metadata
|
||||
with open(json_path, 'w') as f:
|
||||
f.write(json.dumps(metadata, indent=4))
|
||||
if not module.version:
|
||||
raise Exception('version not set')
|
||||
|
||||
versioned_plugin_name = plugin_name + '-' + module.version + '.zip'
|
||||
zip_path_with_version = os.path.join(dest_dir, versioned_plugin_name)
|
||||
# rename zip file
|
||||
if module.version:
|
||||
zip_path_with_version = os.path.join(dest_dir, plugin_name + '-' + module.version + '.zip')
|
||||
os.rename(zip_path, zip_path_with_version)
|
||||
os.rename(zip_path, zip_path_with_version)
|
||||
|
||||
print(f'Created {zip_path_with_version}')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user