Skip to content

Commit c7a9df6

Browse files
committed
Made possible to update modules added by url
Ticket: CFE-3847 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 8b5a963 commit c7a9df6

1 file changed

Lines changed: 62 additions & 38 deletions

File tree

cfbs/commands.py

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cfbs.analyze import analyze_policyset
1414
from cfbs.args import get_args
1515

16+
from cfbs.cfbs_json import CFBSJson
1617
from cfbs.utils import (
1718
cfbs_dir,
1819
cfbs_filename,
@@ -43,6 +44,7 @@
4344
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
4445
from cfbs.validate import validate_config
4546
from cfbs.internal_file_management import (
47+
clone_url_repo,
4648
fetch_archive,
4749
get_download_path,
4850
local_module_copy,
@@ -757,13 +759,19 @@ def update_module(old_module, new_module, module_updates, update):
757759
{item: old_module["name"] for item in extra}
758760
)
759761

760-
if not update.version:
761-
update.version = new_module["version"]
762-
module_updates.msg += "\n - Updated module '%s' from version %s to version %s" % (
763-
update.name,
764-
old_module["version"],
765-
update.version,
766-
)
762+
if new_module.get("version"):
763+
if not update.version:
764+
update.version = new_module["version"]
765+
module_updates.msg += (
766+
"\n - Updated module '%s' from version %s to version %s"
767+
% (
768+
update.name,
769+
old_module["version"],
770+
update.version,
771+
)
772+
)
773+
else:
774+
module_updates.msg += "\n - Updated module '%s' from url" % (update.name)
767775

768776

769777
@cfbs_command("update")
@@ -810,41 +818,57 @@ def update_command(to_update):
810818
log.warning("Module '%s' not in build. Skipping its update." % update.name)
811819
continue
812820

813-
if "version" not in old_module:
814-
log.warning(
815-
"Module '%s' not updatable. Skipping its update." % old_module["name"]
821+
if "url" in old_module:
822+
path, commit = clone_url_repo(old_module["url"])
823+
remote_config = CFBSJson(
824+
path=path, url=old_module["url"], url_commit=commit
816825
)
817-
log.debug("Module '%s' has no version attribute." % old_module["name"])
818-
continue
819826

820-
index_info = index.get_module_object(update.name)
821-
if not index_info:
822-
log.warning(
823-
"Module '%s' not present in the index, cannot update it."
824-
% old_module["name"]
825-
)
826-
continue
827+
module_name = old_module["name"]
828+
provides = remote_config.get_provides()
827829

828-
local_ver = [
829-
int(version_number)
830-
for version_number in re.split(r"[-\.]", old_module["version"])
831-
]
832-
index_ver = [
833-
int(version_number)
834-
for version_number in re.split(r"[-\.]", index_info["version"])
835-
]
836-
if local_ver == index_ver:
837-
print("Module '%s' already up to date" % old_module["name"])
838-
continue
839-
elif local_ver > index_ver:
840-
log.warning(
841-
"The requested version of module '%s' is older than current version (%s < %s)."
842-
" Skipping its update."
843-
% (old_module["name"], index_info["version"], old_module["version"])
844-
)
845-
continue
830+
if not module_name or module_name not in provides:
831+
continue
832+
833+
new_module = provides[module_name]
834+
else:
835+
836+
if "version" not in old_module:
837+
log.warning(
838+
"Module '%s' not updatable. Skipping its update."
839+
% old_module["name"]
840+
)
841+
log.debug("Module '%s' has no version attribute." % old_module["name"])
842+
continue
843+
844+
index_info = index.get_module_object(update.name)
845+
if not index_info:
846+
log.warning(
847+
"Module '%s' not present in the index, cannot update it."
848+
% old_module["name"]
849+
)
850+
continue
851+
852+
local_ver = [
853+
int(version_number)
854+
for version_number in re.split(r"[-\.]", old_module["version"])
855+
]
856+
index_ver = [
857+
int(version_number)
858+
for version_number in re.split(r"[-\.]", index_info["version"])
859+
]
860+
if local_ver == index_ver:
861+
print("Module '%s' already up to date" % old_module["name"])
862+
continue
863+
elif local_ver > index_ver:
864+
log.warning(
865+
"The requested version of module '%s' is older than current version (%s < %s)."
866+
" Skipping its update."
867+
% (old_module["name"], index_info["version"], old_module["version"])
868+
)
869+
continue
846870

847-
new_module = index_info
871+
new_module = index_info
848872

849873
update_module(old_module, new_module, module_updates, update)
850874

0 commit comments

Comments
 (0)