Commit b3d9bf03 authored by Sébastien Luttringer's avatar Sébastien Luttringer
Browse files

Rename installsystems.tools.isfile to islocal

This avoid conflict with os.path.isfile.

Also add must_exists parameter to check local file existance
parent 8c4bc60b
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -30,15 +30,12 @@ from installsystems.printer import arrow, arrowlevel, setmode
from installsystems.printer import out, warn, error, debug, confirm
from installsystems.repository import Repository, RepositoryManager, RepositoryConfig
from installsystems.tools import chroot, prepare_chroot, unprepare_chroot
from installsystems.tools import isfile, smd5sum, argv
from installsystems.tools import islocal, smd5sum, argv
from os import getpid, getcwdu, chdir
from psutil import IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE
from psutil import Process, IOPRIO_CLASS_NONE
from socket import setdefaulttimeout

# used by os.path.isfile
import os

################################################################################
# Common functions
################################################################################
@@ -79,7 +76,7 @@ def get_images(patterns, repoman, local=True, min=None, max=None):
    ans = []
    for pattern in patterns:
        # check if image is a local file
        if local and isfile(pattern) and os.path.isfile(pattern):
        if local and islocal(pattern, True):
            ans.append((pattern, None))
        else: # we need to find image in a repository
            ans += sorted(repoman.select_images([pattern]).items())
+3 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ from installsystems.image.image import Image
from installsystems.image.payload import Payload
from installsystems.image.tarball import Tarball, REGTYPE
from installsystems.printer import arrow, arrowlevel, warn, error
from installsystems.tools import PipeFile, isfile, get_compressor_path, chrights
from installsystems.tools import PipeFile, islocal, get_compressor_path, chrights
from json import dumps
from locale import getpreferredencoding
from os import stat, listdir, mkdir, umask, access, unlink, symlink, R_OK, X_OK
@@ -63,7 +63,7 @@ class SourceImage(Image):
        Create an empty source image
        '''
        # check local repository
        if not isfile(path):
        if not islocal(path):
            raise NotImplementedError("SourceImage must be local")
        # main path
        build_path = join(path, "build")
@@ -132,7 +132,7 @@ class SourceImage(Image):
        '''
        Image.__init__(self)
        # check local repository
        if not isfile(path):
        if not islocal(path):
            raise NotImplementedError("SourceImage must be local")
        self.base_path = abspath(path)
        for pathtype in ("build", "parser", "setup", "payload", "lib"):
+3 −2
Original line number Diff line number Diff line
@@ -378,11 +378,12 @@ def pathsearch(name, path=None):
            return join(abspath(d), name)
    return None

def isfile(path):
def islocal(path, must_exists=False):
    '''
    Return True if path is of type file
    if must_exists is True, also check is file exists
    '''
    return pathtype(path) == "file"
    return pathtype(path) == "file" and (not must_exists or exists(path))

def abspath(path):
    '''