mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
Backups: Make Manifest a dict instead of a list
So it's possible to add more information like metadata etc. Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
7aed74a9bd
commit
e2584be45d
@ -27,6 +27,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
|
from plinth.errors import ActionError
|
||||||
from plinth.modules.backups import MANIFESTS_FOLDER, REPOSITORY
|
from plinth.modules.backups import MANIFESTS_FOLDER, REPOSITORY
|
||||||
|
|
||||||
|
|
||||||
@ -174,10 +175,24 @@ def subcommand_get_archive_apps(arguments):
|
|||||||
manifest_path)
|
manifest_path)
|
||||||
manifest = json.loads(manifest_data)
|
manifest = json.loads(manifest_data)
|
||||||
if manifest:
|
if manifest:
|
||||||
for app in manifest:
|
for app in _get_apps_of_manifest(manifest):
|
||||||
print(app['name'])
|
print(app['name'])
|
||||||
|
|
||||||
|
|
||||||
|
def _get_apps_of_manifest(manifest):
|
||||||
|
"""
|
||||||
|
Get apps of a manifest.
|
||||||
|
Supports both dict format as well as list format of plinth <=0.42
|
||||||
|
"""
|
||||||
|
if type(manifest) is list:
|
||||||
|
apps = manifest
|
||||||
|
elif type(manifest) is dict and 'apps' in manifest:
|
||||||
|
apps = manifest['apps']
|
||||||
|
else:
|
||||||
|
raise ActionError('Unknown manifest format')
|
||||||
|
return apps
|
||||||
|
|
||||||
|
|
||||||
def subcommand_get_exported_archive_apps(arguments):
|
def subcommand_get_exported_archive_apps(arguments):
|
||||||
"""Get list of apps included in an exported archive file."""
|
"""Get list of apps included in an exported archive file."""
|
||||||
manifest = None
|
manifest = None
|
||||||
@ -191,7 +206,7 @@ def subcommand_get_exported_archive_apps(arguments):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if manifest:
|
if manifest:
|
||||||
for app in manifest:
|
for app in _get_apps_of_manifest(manifest):
|
||||||
print(app['name'])
|
print(app['name'])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -84,11 +84,13 @@ def _backup_handler(packet):
|
|||||||
|
|
||||||
manifest_path = os.path.join(MANIFESTS_FOLDER,
|
manifest_path = os.path.join(MANIFESTS_FOLDER,
|
||||||
get_valid_filename(packet.label) + '.json')
|
get_valid_filename(packet.label) + '.json')
|
||||||
manifests = [{
|
manifests = {
|
||||||
'name': app.name,
|
'apps': [{
|
||||||
'version': app.app.version,
|
'name': app.name,
|
||||||
'backup': app.manifest
|
'version': app.app.version,
|
||||||
} for app in packet.apps]
|
'backup': app.manifest
|
||||||
|
} for app in packet.apps]
|
||||||
|
}
|
||||||
with open(manifest_path, 'w') as manifest_file:
|
with open(manifest_path, 'w') as manifest_file:
|
||||||
json.dump(manifests, manifest_file)
|
json.dump(manifests, manifest_file)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user