diff --git a/pisi/actionsapi/pisitools.py b/pisi/actionsapi/pisitools.py index 1ec78b7f..3e9d8880 100644 --- a/pisi/actionsapi/pisitools.py +++ b/pisi/actionsapi/pisitools.py @@ -67,7 +67,11 @@ def dohtml(*sourceFiles): disallowed_directories = ['CVS'] for sourceFile in sourceFiles: - for source in glob.glob(sourceFile): + sourceFileGlob = glob.glob(sourceFile) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\"" % sourceFile)) + + for source in sourceFileGlob: if os.path.isfile(source) and os.path.splitext(source)[1] in allowed_extensions: system('install -m0644 "%s" %s' % (source, destionationDirectory)) if os.path.isdir(source) and os.path.basename(source) not in disallowed_directories: @@ -120,7 +124,11 @@ def doman(*sourceFiles): makedirs(manDIR) for sourceFile in sourceFiles: - for source in glob.glob(sourceFile): + sourceFileGlob = glob.glob(sourceFile) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\"" % sourceFile)) + + for source in sourceFileGlob: compressed = source.endswith("gz") and source if compressed: source = source[:-3] @@ -153,7 +161,11 @@ def domove(sourceFile, destination, destinationFile = ''): ''' example call: pisitools.domove("/usr/bin/", "/usr/sbin")''' makedirs(join_path(get.installDIR(), destination)) - for filePath in glob.glob(join_path(get.installDIR(), sourceFile)): + sourceFileGlob = glob.glob(join_path(get.installDIR(), sourceFile)) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\". 'domove' operation failed." % sourceFile)) + + for filePath in sourceFileGlob: if not destinationFile: move(filePath, join_path(get.installDIR(), join_path(destination, os.path.basename(filePath)))) else: @@ -184,7 +196,7 @@ def dosed(sourceFiles, findPattern, replacePattern = ''): #if there is no match, raise exception if len(sourceFilesGlob) == 0: - raise FileError(_('No such file matching pattern: "%s"') % sourceFiles) + raise FileError(_('No such file matching pattern: "%s". \'dosed\' operation failed.') % sourceFiles) for sourceFile in sourceFilesGlob: if can_access_file(sourceFile): @@ -217,7 +229,11 @@ def insinto(destinationDirectory, sourceFile, destinationFile = '', sym = True) makedirs(join_path(get.installDIR(), destinationDirectory)) if not destinationFile: - for filePath in glob.glob(sourceFile): + sourceFileGlob = glob.glob(sourceFile) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\"." % sourceFile)) + + for filePath in sourceFileGlob: if can_access_file(filePath): copy(filePath, join_path(get.installDIR(), join_path(destinationDirectory, os.path.basename(filePath))), sym) else: @@ -240,10 +256,18 @@ def newman(sourceFile, destinationFile): def remove(sourceFile): '''removes sourceFile''' - for filePath in glob.glob(join_path(get.installDIR(), sourceFile)): + sourceFileGlob = glob.glob(join_path(get.installDIR(), sourceFile)) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\". Remove operation failed." % sourceFile)) + + for filePath in sourceFileGlob: unlink(filePath) def removeDir(destinationDirectory): '''removes destinationDirectory and its subtrees''' - for directory in glob.glob(join_path(get.installDIR(), destinationDirectory)): + destdirGlob = glob.glob(join_path(get.installDIR(), destinationDirectory)) + if len(destdirGlob) == 0: + raise FileError(_("No directory matched pattern \"%s\". Remove directory operation failed." % destinationDirectory)) + + for directory in destdirGlob: unlinkDir(directory) diff --git a/pisi/actionsapi/pisitoolsfunctions.py b/pisi/actionsapi/pisitoolsfunctions.py index d378d866..43d23fbc 100644 --- a/pisi/actionsapi/pisitoolsfunctions.py +++ b/pisi/actionsapi/pisitoolsfunctions.py @@ -48,7 +48,11 @@ def executable_insinto(destinationDirectory, *sourceFiles): makedirs(destinationDirectory) for sourceFile in sourceFiles: - for source in glob.glob(sourceFile): + sourceFileGlob = glob.glob(sourceFile) + if len(sourceFileGlob) == 0: + raise FileError(_("No executable file matched pattern \"%s\"." % sourceFile)) + + for source in sourceFileGlob: # FIXME: use an internal install routine for these system('install -m0755 -o root -g root %s %s' % (source, destinationDirectory)) @@ -62,7 +66,11 @@ def readable_insinto(destinationDirectory, *sourceFiles): makedirs(destinationDirectory) for sourceFile in sourceFiles: - for source in glob.glob(sourceFile): + sourceFileGlob = glob.glob(sourceFile) + if len(sourceFileGlob) == 0: + raise FileError(_("No file matched pattern \"%s\"." % sourceFile)) + + for source in sourceFileGlob: system('install -m0644 "%s" %s' % (source, destinationDirectory)) def lib_insinto(sourceFile, destinationDirectory, permission = 0644): diff --git a/pisi/actionsapi/shelltools.py b/pisi/actionsapi/shelltools.py index 20af4d81..e9641774 100644 --- a/pisi/actionsapi/shelltools.py +++ b/pisi/actionsapi/shelltools.py @@ -58,7 +58,11 @@ def echo(destionationFile, content): def chmod(filePath, mode = 0755): '''change the mode of filePath to the mode''' - for fileName in glob.glob(filePath): + filePathGlob = glob.glob(filePath) + if len(filePathGlob) == 0: + error(_("ActionsAPI [chmod]: No file matched pattern \"%s\"." % filePath)) + + for fileName in filePathGlob: if can_access_file(fileName): try: os.chmod(fileName, mode) @@ -112,7 +116,11 @@ def unlinkDir(sourceDirectory): def move(source, destination): '''recursively move a "source" file or directory to "destination"''' - for filePath in glob.glob(source): + sourceGlob = glob.glob(source) + if len(sourceGlob) == 0: + error(_("ActionsAPI [move]: No file matched pattern \"%s\"." % source)) + + for filePath in sourceGlob: if isFile(filePath) or isLink(filePath) or isDirectory(filePath): try: shutil.move(filePath, destination) @@ -124,7 +132,11 @@ def move(source, destination): # FIXME: instead of passing a sym parameter, split copy and copytree into 4 different function def copy(source, destination, sym = True): '''recursively copy a "source" file or directory to "destination"''' - for filePath in glob.glob(source): + sourceGlob = glob.glob(source) + if len(sourceGlob) == 0: + error(_("ActionsAPI [copy]: No file matched pattern \"%s\"." % source)) + + for filePath in sourceGlob: if isFile(filePath) and not isLink(filePath): try: shutil.copy(filePath, destination) @@ -166,8 +178,13 @@ def copytree(source, destination, sym = True): def touch(filePath): '''changes the access time of the 'filePath', or creates it if it is not exist''' - if glob.glob(filePath): - for f in glob.glob(filePath): + filePathGlob = glob.glob(filePath) + + if filePathGlob: + if len(filePathGlob) == 0: + error(_("ActionsAPI [touch]: No file matched pattern \"%s\"." % filePath)) + + for f in filePathGlob: os.utime(f, None) else: try: