Check glob methods. This means, if any action in actions.py, operates on files that do not exist, pisi raises an exception about that.

This commit is contained in:
Gökçen Eraslan
2009-01-04 10:37:24 +00:00
parent 973200bf08
commit 779760f1af
3 changed files with 63 additions and 14 deletions
+31 -7
View File
@@ -67,7 +67,11 @@ def dohtml(*sourceFiles):
disallowed_directories = ['CVS'] disallowed_directories = ['CVS']
for sourceFile in sourceFiles: 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: if os.path.isfile(source) and os.path.splitext(source)[1] in allowed_extensions:
system('install -m0644 "%s" %s' % (source, destionationDirectory)) system('install -m0644 "%s" %s' % (source, destionationDirectory))
if os.path.isdir(source) and os.path.basename(source) not in disallowed_directories: if os.path.isdir(source) and os.path.basename(source) not in disallowed_directories:
@@ -120,7 +124,11 @@ def doman(*sourceFiles):
makedirs(manDIR) makedirs(manDIR)
for sourceFile in sourceFiles: 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 compressed = source.endswith("gz") and source
if compressed: if compressed:
source = source[:-3] source = source[:-3]
@@ -153,7 +161,11 @@ def domove(sourceFile, destination, destinationFile = ''):
''' example call: pisitools.domove("/usr/bin/", "/usr/sbin")''' ''' example call: pisitools.domove("/usr/bin/", "/usr/sbin")'''
makedirs(join_path(get.installDIR(), destination)) 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: if not destinationFile:
move(filePath, join_path(get.installDIR(), join_path(destination, os.path.basename(filePath)))) move(filePath, join_path(get.installDIR(), join_path(destination, os.path.basename(filePath))))
else: else:
@@ -184,7 +196,7 @@ def dosed(sourceFiles, findPattern, replacePattern = ''):
#if there is no match, raise exception #if there is no match, raise exception
if len(sourceFilesGlob) == 0: 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: for sourceFile in sourceFilesGlob:
if can_access_file(sourceFile): if can_access_file(sourceFile):
@@ -217,7 +229,11 @@ def insinto(destinationDirectory, sourceFile, destinationFile = '', sym = True)
makedirs(join_path(get.installDIR(), destinationDirectory)) makedirs(join_path(get.installDIR(), destinationDirectory))
if not destinationFile: 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): if can_access_file(filePath):
copy(filePath, join_path(get.installDIR(), join_path(destinationDirectory, os.path.basename(filePath))), sym) copy(filePath, join_path(get.installDIR(), join_path(destinationDirectory, os.path.basename(filePath))), sym)
else: else:
@@ -240,10 +256,18 @@ def newman(sourceFile, destinationFile):
def remove(sourceFile): def remove(sourceFile):
'''removes 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) unlink(filePath)
def removeDir(destinationDirectory): def removeDir(destinationDirectory):
'''removes destinationDirectory and its subtrees''' '''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) unlinkDir(directory)
+10 -2
View File
@@ -48,7 +48,11 @@ def executable_insinto(destinationDirectory, *sourceFiles):
makedirs(destinationDirectory) makedirs(destinationDirectory)
for sourceFile in sourceFiles: 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 # FIXME: use an internal install routine for these
system('install -m0755 -o root -g root %s %s' % (source, destinationDirectory)) system('install -m0755 -o root -g root %s %s' % (source, destinationDirectory))
@@ -62,7 +66,11 @@ def readable_insinto(destinationDirectory, *sourceFiles):
makedirs(destinationDirectory) makedirs(destinationDirectory)
for sourceFile in sourceFiles: 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)) system('install -m0644 "%s" %s' % (source, destinationDirectory))
def lib_insinto(sourceFile, destinationDirectory, permission = 0644): def lib_insinto(sourceFile, destinationDirectory, permission = 0644):
+22 -5
View File
@@ -58,7 +58,11 @@ def echo(destionationFile, content):
def chmod(filePath, mode = 0755): def chmod(filePath, mode = 0755):
'''change the mode of filePath to the mode''' '''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): if can_access_file(fileName):
try: try:
os.chmod(fileName, mode) os.chmod(fileName, mode)
@@ -112,7 +116,11 @@ def unlinkDir(sourceDirectory):
def move(source, destination): def move(source, destination):
'''recursively move a "source" file or directory to "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): if isFile(filePath) or isLink(filePath) or isDirectory(filePath):
try: try:
shutil.move(filePath, destination) 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 # FIXME: instead of passing a sym parameter, split copy and copytree into 4 different function
def copy(source, destination, sym = True): def copy(source, destination, sym = True):
'''recursively copy a "source" file or directory to "destination"''' '''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): if isFile(filePath) and not isLink(filePath):
try: try:
shutil.copy(filePath, destination) shutil.copy(filePath, destination)
@@ -166,8 +178,13 @@ def copytree(source, destination, sym = True):
def touch(filePath): def touch(filePath):
'''changes the access time of the 'filePath', or creates it if it is not exist''' '''changes the access time of the 'filePath', or creates it if it is not exist'''
if glob.glob(filePath): filePathGlob = glob.glob(filePath)
for f in 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) os.utime(f, None)
else: else:
try: try: