Skip to content

Commit

Permalink
Add support for archiving raw-delta object
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathas-Conceicao <jonathas.conceicao@ossystems.com.br>
  • Loading branch information
Jonathas-Conceicao committed Jun 9, 2021
1 parent 7309199 commit 876055e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions uhu/core/_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ._options import Options
from .compression import compression_to_metadata
from .delta import validate_delta
from .install_condition import InstallCondition
from .validators import validate_options

Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(cls, classname, bases, methods):

class BaseObject(metaclass=ObjectType):
mode = None
using_delta = False
allow_compression = False
allow_install_condition = False
options = []
Expand Down Expand Up @@ -93,6 +95,7 @@ def to_metadata(self, callback=None):
metadata['mode'] = self.mode
metadata.update(self._metadata_install_condition(metadata))
metadata.update(self._metadata_compression())
metadata.update(self._metadata_delta())
return metadata

def _metadata_install_condition(self, metadata):
Expand All @@ -105,6 +108,11 @@ def _metadata_compression(self):
return {}
return compression_to_metadata(self.filename)

def _metadata_delta(self):
if not self.using_delta:
return {}
return validate_delta(self.filename)

def to_upload(self):
return {
'filename': self['filename'],
Expand Down
33 changes: 33 additions & 0 deletions uhu/core/delta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2021 O.S. Systems Software LTDA.
# SPDX-License-Identifier: GPL-2.0

ARCHIVERS = {
# Bita format: https://github.com/oll3/bita
'bita': {
'signature': b'BITA1\0',
},
}


MAX_ARCHIVER_SIGNATURE_SIZE = max(
[len(archiver['signature']) for archiver in ARCHIVERS.values()]
)


def get_archiver_format(fn):
"""Returns the delta archiver backend for a given file.
"""
with open(fn, 'rb') as fp:
header = fp.read(MAX_ARCHIVER_SIGNATURE_SIZE)
for fmt, archiver in ARCHIVERS.items():
signature = archiver['signature']
if signature == header[:len(signature)]:
return fmt
return None


def validate_delta(filename):
if get_archiver_format(filename) is None:
err = '"{}" doesn\'t match a known format type'
raise ValueError(err.format(filename))
return {}
20 changes: 20 additions & 0 deletions uhu/core/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,23 @@ class ZephyrObject(BaseObject):
required_options = [
'filename',
]


class RawDeltaObject(BaseObject):
mode = 'raw-delta'
using_delta = True
allow_compression = False
allow_install_condition = False
target_types = ['device']
options = [
'filename',
'sha256sum',
'size',
'target-type',
'target',
]
required_options = [
'filename',
'target-type',
'target',
]

0 comments on commit 876055e

Please sign in to comment.