From 26e8f22f791af32b0b8b2c075b38df312e445aef Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Thu, 26 May 2011 17:03:36 +0200 Subject: [PATCH] Better detection of image name type --- bin/isinstall | 7 +++++-- installsystems/image.py | 11 +++++++++++ installsystems/repository.py | 2 +- installsystems/tools.py | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/isinstall b/bin/isinstall index 0b8b13b..c6df9f8 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 e8d47dc..8c6eb04 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 8498ab6..faec6bd 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 294a7b0..879a619 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): -- GitLab