diff --git a/bin/isinstall b/bin/isinstall index 0b8b13bda6a873432295326d0f7a379ba04ad3b9..c6df9f8afdbf53452651ddcf8e0124acb88c142e 100755 --- a/bin/isinstall +++ b/bin/isinstall @@ -49,9 +49,10 @@ try: # Partial parse args = p_main.parse_known_args()[0] # looks if arguments is a file or image name - if istools.get_path_type(args.image_name) == "file": + image_name_type = istools.get_path_type(args.image_name) + if image_name_type == "file": pkg = PackageImage(istools.complete_path(args.image_name)) - else: + elif image_name_type == "name": # init repo cache object repocache = RepositoryCache(args.cache_path, verbose=args.verbose) # register command ligne repo @@ -62,6 +63,8 @@ try: repocache.update() # get image package pkg = repocache.get(args.image_name, args.image_version) + else: + raise Exception("Invalid image name") # run parser scripts pkg.run_parser({ "parser": p_main }) # call parser again, with extended attributes diff --git a/installsystems/image.py b/installsystems/image.py index e8d47dc01140bda3c1bff6a0252bfef1e8eac75f..8c6eb040624792273f575fea4c20fbc599cd7982 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -17,6 +17,7 @@ import ConfigParser import subprocess import json import tarfile +import re import installsystems.template from installsystems.printer import * from installsystems.tarball import Tarball @@ -29,6 +30,16 @@ class Image(object): image_payload = ".isdata" image_format = "1" + @staticmethod + def check_image_name(buf): + '''Check if @name is a valid image name''' + return re.match("\w+", buf) is not None + + @staticmethod + def check_image_version(buf): + '''Check if @name is a valid image version''' + return re.match("\d+", buf) is not None + def __init__(self, pbzip2=True): self.pbzip2_path = self.path_search("pbzip2") if pbzip2 else None diff --git a/installsystems/repository.py b/installsystems/repository.py index 8498ab64a2c81826a28ef6ce1c63a01c98634a6d..faec6bd2c1ebc3d32374ed6be66f7bbb09e9e1e0 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -129,7 +129,7 @@ class RepositoryCache(object): def register(self, name, image, data): '''Register a repository to track''' self.repos[name] = Repository(istools.complete_path(image), - istools.complete_pathh(data), + istools.complete_path(data), verbose=self.verbose) def update(self): diff --git a/installsystems/tools.py b/installsystems/tools.py index 294a7b03db8c82419d6ae2dcc42acad67954958d..879a619bd0e5f879c5c30d779143fa046e8e9511 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -7,6 +7,7 @@ InstallSystems Generic Tools Library ''' import os +from installsystems.image import Image def cp(self, source, destination): '''Copy a source to destination. Take care of path type''' @@ -25,6 +26,8 @@ def get_path_type(path): return "ssh" elif path.startswith("file://") or os.path.exists(path): return "file" + elif Image.check_image_name(path): + return "name" return None def complete_path(path):