'file'ı bir değişken ismi olarak kullanmayalım.. zira kendisi python'un built-in bir fonksiyonu.

ayrıca kalan değişkenlerin de isimlerini düzenledim..
This commit is contained in:
A. Murat Eren
2006-02-28 23:35:10 +00:00
parent 722cc4d4af
commit ff6a6acd81
+69 -69
View File
@@ -33,9 +33,9 @@ from pisi.actionsapi import error
from pisi.util import run_batch from pisi.util import run_batch
from pisi.util import join_path from pisi.util import join_path
def can_access_file(sourceFile): def can_access_file(filePath):
'''test the existence of file''' '''test the existence of file'''
return os.access(sourceFile, os.F_OK) return os.access(filePath, os.F_OK)
def can_access_directory(destinationDirectory): def can_access_directory(destinationDirectory):
'''test readability, writability and executablility of directory''' '''test readability, writability and executablility of directory'''
@@ -57,47 +57,47 @@ def echo(destionationFile, content):
except IOError: except IOError:
error(_('ActionsAPI [echo]: Can\'t append to file %s.') % (destionationFile)) error(_('ActionsAPI [echo]: Can\'t append to file %s.') % (destionationFile))
def chmod(sourceFile, mode = 0755): def chmod(filePath, mode = 0755):
'''change the mode of sourceFile to the mode''' '''change the mode of filePath to the mode'''
for file in glob.glob(sourceFile): for filePath in glob.glob(filePath):
if can_access_file(file): if can_access_file(filePath):
try: try:
os.chmod(file, mode) os.chmod(filePath, mode)
except OSError: except OSError:
ctx.ui.error(_('ActionsAPI [chmod]: Operation not permitted: %s (mode: %s)') \ ctx.ui.error(_('ActionsAPI [chmod]: Operation not permitted: %s (mode: %s)') \
% (file, mode)) % (filePath, mode))
else: else:
ctx.ui.error(_('ActionsAPI [chmod]: File %s doesn\'t exists.') % (file)) ctx.ui.error(_('ActionsAPI [chmod]: File %s doesn\'t exists.') % (filePath))
def chown(sourceFile, uid = "root", gid = "root"): def chown(filePath, uid = "root", gid = "root"):
'''change the owner and group id of sourceFile to uid and gid''' '''change the owner and group id of filePath to uid and gid'''
if can_access_file(sourceFile): if can_access_file(filePath):
try: try:
os.chown(sourceFile, pwd.getpwnam(uid)[2], grp.getgrnam(gid)[2]) os.chown(filePath, pwd.getpwnam(uid)[2], grp.getgrnam(gid)[2])
except OSError: except OSError:
ctx.ui.error(_('ActionsAPI [chown]: Operation not permitted: %s (uid: %s, gid: %s)') \ ctx.ui.error(_('ActionsAPI [chown]: Operation not permitted: %s (uid: %s, gid: %s)') \
% (sourceFile, uid, gid)) % (filePath, uid, gid))
else: else:
ctx.ui.error(_('ActionsAPI [chown]: File %s doesn\'t exists.') % sourceFile) ctx.ui.error(_('ActionsAPI [chown]: File %s doesn\'t exists.') % filePath)
def sym(sourceFile, destinationFile): def sym(source, destination):
'''creates symbolic link''' '''creates symbolic link'''
try: try:
os.symlink(sourceFile, destinationFile) os.symlink(source, destination)
except OSError: except OSError:
ctx.ui.error(_('ActionsAPI [sym]: Permission denied: %s to %s') % (file, destinationFile)) ctx.ui.error(_('ActionsAPI [sym]: Permission denied: %s to %s') % (source, destination))
def unlink(sourceFile): def unlink(filePath):
'''remove the file path''' '''remove the file path'''
if isFile(sourceFile) or isLink(sourceFile): if isFile(filePath) or isLink(filePath):
try: try:
os.unlink(sourceFile) os.unlink(filePath)
except OSError: except OSError:
ctx.ui.error(_('ActionsAPI [unlink]: Permission denied: %s.') % (sourceFile)) ctx.ui.error(_('ActionsAPI [unlink]: Permission denied: %s.') % (filePath))
elif isDirectory(sourceFile): elif isDirectory(filePath):
pass pass
else: else:
ctx.ui.error(_('ActionsAPI [unlink]: File %s doesn\'t exists.') % (sourceFile)) ctx.ui.error(_('ActionsAPI [unlink]: File %s doesn\'t exists.') % (filePath))
def unlinkDir(sourceDirectory): def unlinkDir(sourceDirectory):
'''delete an entire directory tree''' '''delete an entire directory tree'''
@@ -111,35 +111,35 @@ def unlinkDir(sourceDirectory):
else: else:
error(_('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory)) error(_('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory))
def move(sourceFile, destinationFile): def move(source, destination):
'''recursively move a sourceFile or directory to destinationFile''' '''recursively move a "source" file or directory to "destination"'''
for file in glob.glob(sourceFile): for filePath in glob.glob(source):
if isFile(file) or isLink(file) or isDirectory(file): if isFile(filePath) or isLink(filePath) or isDirectory(filePath):
try: try:
shutil.move(file, destinationFile) shutil.move(filePath, destination)
except OSError: except OSError:
error(_('ActionsAPI [move]: Permission denied: %s to %s') % (file, destinationFile)) error(_('ActionsAPI [move]: Permission denied: %s to %s') % (filePath, destination))
else: else:
error(_('ActionsAPI [move]: File %s doesn\'t exists.') % (file)) error(_('ActionsAPI [move]: File %s doesn\'t exists.') % (filePath))
def copy(sourceFile, destinationFile): def copy(source, destination):
'''recursively copy a sourceFile or directory to destinationFile''' '''recursively copy a "source" file or directory to "destination"'''
for file in glob.glob(sourceFile): for filePath in glob.glob(source):
if isFile(file) and not isLink(file): if isFile(filePath) and not isLink(filePath):
try: try:
shutil.copy(file, destinationFile) shutil.copy(filePath, destination)
except IOError: except IOError:
error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (file, destinationFile)) error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination))
elif isLink(file): elif isLink(filePath):
if isDirectory(destinationFile): if isDirectory(destination):
os.symlink(os.readlink(file), join_path(destinationFile, os.path.basename(file))) os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath)))
if isFile(destinationFile): if isFile(destination):
os.remove(destinationFile) os.remove(destination)
os.symlink(os.readlink(file), destinationFile) os.symlink(os.readlink(filePath), destination)
elif isDirectory(file): elif isDirectory(filePath):
copytree(file, destinationFile) copytree(filePath, destination)
else: else:
error(_('ActionsAPI [copy]: File %s does not exist.') % file) error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)
def copytree(source, destination, sym = False): def copytree(source, destination, sym = False):
'''recursively copy an entire directory tree rooted at source''' '''recursively copy an entire directory tree rooted at source'''
@@ -154,17 +154,17 @@ def copytree(source, destination, sym = False):
else: else:
error(_('ActionsAPI [copytree]: Directory %s doesn\'t exists.') % (source)) error(_('ActionsAPI [copytree]: Directory %s doesn\'t exists.') % (source))
def touch(sourceFile): def touch(filePath):
'''changes the access time of the 'sourceFile', 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(sourceFile): if glob.glob(filePath):
for file in glob.glob(sourceFile): for f in glob.glob(filePath):
os.utime(file, None) os.utime(f, None)
else: else:
try: try:
f = open(sourceFile, 'w') f = open(filePath, 'w')
f.close() f.close()
except IOError: except IOError:
error(_('ActionsAPI [touch]: Permission denied: %s') % (sourceFile)) error(_('ActionsAPI [touch]: Permission denied: %s') % (filePath))
def cd(directoryName = ''): def cd(directoryName = ''):
'''change directory''' '''change directory'''
@@ -185,29 +185,29 @@ def export(key, value):
'''export environ variable''' '''export environ variable'''
os.environ[key] = value os.environ[key] = value
def isLink(sourceFile): def isLink(filePath):
'''return True if sourceFile refers to a symbolic link''' '''return True if filePath refers to a symbolic link'''
return os.path.islink(sourceFile) return os.path.islink(filePath)
def isFile(sourceFile): def isFile(filePath):
'''return True if sourceFile is an existing regular file''' '''return True if filePath is an existing regular file'''
return os.path.isfile(sourceFile) return os.path.isfile(filePath)
def isDirectory(sourceDirectory): def isDirectory(filePath):
'''Return True if sourceFile is an existing directory''' '''Return True if filePath is an existing directory'''
return os.path.isdir(sourceDirectory) return os.path.isdir(filePath)
def realPath(sourceFile): def realPath(filePath):
'''return the canonical path of the specified filename, eliminating any symbolic links encountered in the path''' '''return the canonical path of the specified filename, eliminating any symbolic links encountered in the path'''
return os.path.realpath(sourceFile) return os.path.realpath(filePath)
def baseName(sourceFile): def baseName(filePath):
'''return the base name of pathname sourceFile''' '''return the base name of pathname filePath'''
return os.path.basename(sourceFile) return os.path.basename(filePath)
def dirName(sourceFile): def dirName(filePath):
'''return the directory name of pathname path''' '''return the directory name of pathname path'''
return os.path.dirname(sourceFile) return os.path.dirname(filePath)
def system(command): def system(command):
command = string.join(string.split(command)) command = string.join(string.split(command))