Commit 26e8f22f authored by Seblu's avatar Seblu
Browse files

Better detection of image name type

parent 0f241165
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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
+11 −0
Original line number Diff line number Diff line
@@ -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

+1 −1
Original line number Diff line number Diff line
@@ -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):
+3 −0
Original line number Diff line number Diff line
@@ -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):