def echo(destionationFile, content): try: f = open(destionationFile, "a") f.write("%s\n" % content) f.close() except IOError: error(_("ActionsAPI [echo]: Can't append to file %s.") % (destionationFile))
def makedirs(destinationDirectory): """recursive directory creation function""" try: if not os.access(destinationDirectory, os.F_OK): os.makedirs(destinationDirectory) except OSError: error(_("Cannot create directory %s") % destinationDirectory)
def makedirs(destinationDirectory): '''recursive directory creation function''' try: if not os.access(destinationDirectory, os.F_OK): os.makedirs(destinationDirectory) except OSError: error(_('Cannot create directory %s') % destinationDirectory)
def echo(destionationFile, content): try: f = open(destionationFile, 'a') f.write('%s\n' % content) f.close() except IOError: error(_('ActionsAPI [echo]: Can\'t append to file %s.') % (destionationFile))
def doman(*sourceFiles): '''inserts the man pages in the list of files into /usr/share/man/''' '''example call: pisitools.doman("man.1", "pardus.*")''' manDIR = join_path(get.installDIR(), get.manDIR()) if not can_access_directory(manDIR): makedirs(manDIR) for sourceFile in sourceFiles: 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] try: pageName, pageDirectory = source[:source.rindex('.')], \ source[source.rindex('.')+1:] except ValueError: error( _('ActionsAPI [doman]: Wrong man page file: %s') % (source)) manPDIR = join_path(manDIR, '/man%s' % pageDirectory) makedirs(manPDIR) if not compressed: system('install -m0644 %s %s' % (source, manPDIR)) else: uncompress(compressed, targetDir=manPDIR)
def doman(*sourceFiles): """inserts the man pages in the list of files into /usr/share/man/""" """example call: pisitools.doman("man.1", "pardus.*")""" manDIR = join_path(get.installDIR(), get.manDIR()) if not can_access_directory(manDIR): makedirs(manDIR) for sourceFile in sourceFiles: 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] try: pageName, pageDirectory = source[: source.rindex(".")], source[source.rindex(".") + 1 :] except ValueError: error(_("ActionsAPI [doman]: Wrong man page file: %s") % (source)) manPDIR = join_path(manDIR, "/man%s" % pageDirectory) makedirs(manPDIR) if not compressed: system("install -m0644 %s %s" % (source, manPDIR)) else: uncompress(compressed, targetDir=manPDIR)
def copytree(source, destination, sym = False): '''recursively copy an entire directory tree rooted at source''' if isDirectory(source) or isLink(source): try: shutil.copytree(source, destination, sym) except OSError, e: error(_('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e))
def copy(source, destination, sym=True): '''recursively copy a "source" file or directory to "destination"''' for filePath in glob.glob(source): if isFile(filePath) and not isLink(filePath): try: shutil.copy(filePath, destination) except IOError: error( _('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination)) elif isLink(filePath) and sym: if isDirectory(destination): os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath))) else: if isFile(destination): os.remove(destination) os.symlink(os.readlink(filePath), destination) elif isLink(filePath) and not sym: if isDirectory(filePath): copytree(filePath, destination) else: shutil.copy(filePath, destination) elif isDirectory(filePath): copytree(filePath, destination, sym) else: error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)
def echo(destionationFile, content): try: f = open(destionationFile, 'a') f.write('%s\n' % content) f.close() except IOError: error( _('ActionsAPI [echo]: Can\'t append to file %s.') % (destionationFile))
def dosym(sourceFile, destinationFile): '''creates soft link between sourceFile and destinationFile''' ''' example call: pisitools.dosym("/usr/bin/bash", "/bin/bash")''' makedirs(join_path(get.installDIR(), os.path.dirname(destinationFile))) try: os.symlink(sourceFile, join_path(get.installDIR(), destinationFile)) except OSError: error(_('ActionsAPI [dosym]: File exists: %s') % (sourceFile))
def system(command): command = string.join(string.split(command)) retValue = run_logged(command) #if return value is different than 0, it means error, raise exception if retValue != 0: error(_("Command \"%s\" failed, return value was %d.") % (command, retValue)) return retValue
def dosym(sourceFile, destinationFile): '''creates soft link between sourceFile and destinationFile''' ''' example call: pisitools.dosym("/usr/bin/bash", "/bin/bash")''' makedirs(join_path(get.installDIR(), os.path.dirname(destinationFile))) try: os.symlink(sourceFile, join_path(get.installDIR() ,destinationFile)) except OSError: error(_('ActionsAPI [dosym]: File exists: %s') % (sourceFile))
def move(sourceFile, destinationFile): '''recursively move a sourceFile or directory to destinationFile''' for file in glob.glob(sourceFile): if isFile(file) or isLink(file) or isDirectory(file): try: shutil.move(file, destinationFile) except OSError: error(_('ActionsAPI [move]: Permission denied: %s to %s') % (file, destinationFile)) else: error(_('ActionsAPI [move]: File %s doesn\'t exists.') % (file))
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): os.utime(f, None) else: try: f = open(filePath, 'w') f.close() except IOError: error(_('ActionsAPI [touch]: Permission denied: %s') % (filePath))
def touch(sourceFile): '''changes the access time of the 'sourceFile', or creates it if it is not exist''' if glob.glob(sourceFile): for file in glob.glob(sourceFile): os.utime(file, None) else: try: f = open(sourceFile, 'w') f.close() except IOError: error(_('ActionsAPI [touch]: Permission denied: %s') % (sourceFile))
def unlinkDir(sourceDirectory): '''delete an entire directory tree''' if isDirectory(sourceDirectory) or isLink(sourceDirectory): try: shutil.rmtree(sourceDirectory) except OSError: error(_('ActionsAPI [unlinkDir]: Operation not permitted: %s') % (sourceDirectory)) elif isFile(sourceDirectory): pass else: error(_('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory))
def system(command): command = string.join(string.split(command)) retValue = run_logged(command) #if return value is different than 0, it means error, raise exception if retValue != 0: error( _("Command \"%s\" failed, return value was %d.") % (command, retValue)) return retValue
def unlinkDir(sourceDirectory): '''delete an entire directory tree''' if isDirectory(sourceDirectory) or isLink(sourceDirectory): try: shutil.rmtree(sourceDirectory) except OSError: error(_('ActionsAPI [unlinkDir]: Operation not permitted: %s') % (sourceDirectory)) elif isFile(sourceDirectory): ctx.ui.warning(_('ActionsAPI [unlinkDir]: %s is not a directory, use \'unlink\' or \'remove\' to remove files.') % sourceDirectory) else: error(_('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory))
def rename(sourceFile, destinationFile): ''' renames sourceFile as destinationFile''' ''' example call: pisitools.rename("/usr/bin/bash", "bash.old") ''' ''' the result of the previous example would be "/usr/bin/bash.old" ''' baseDir = os.path.dirname(sourceFile) try: os.rename(join_path(get.installDIR(), sourceFile), join_path(get.installDIR(), baseDir, destinationFile)) except OSError, e: error(_('ActionsAPI [rename]: %s: %s') % (e, sourceFile))
def rename(sourceFile, destinationFile): """ renames sourceFile as destinationFile""" """ example call: pisitools.rename("/usr/bin/bash", "bash.old") """ """ the result of the previous example would be "/usr/bin/bash.old" """ baseDir = os.path.dirname(sourceFile) try: os.rename(join_path(get.installDIR(), sourceFile), join_path(get.installDIR(), baseDir, destinationFile)) except OSError, e: error(_("ActionsAPI [rename]: %s: %s") % (e, sourceFile))
def copy(sourceFile, destinationFile): '''recursively copy a sourceFile or directory to destinationFile''' for file in glob.glob(sourceFile): if isFile(file) or isLink(file): try: shutil.copy(file, destinationFile) except IOError: error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (file, destinationFile)) elif isDirectory(file): copytree(file, destinationFile) else: error(_('ActionsAPI [copy]: File %s does not exist.') % file)
def rename(sourceFile, destinationFile): ''' renames sourceFile as destinationFile''' ''' example call: pisitools.rename("/usr/bin/bash", "bash.old") ''' ''' the result of the previous example would be "/usr/bin/bash.old" ''' baseDir = os.path.dirname(sourceFile) try: os.rename(join_path(get.installDIR(), sourceFile), join_path(get.installDIR(), baseDir, destinationFile)) except OSError: error(_('ActionsAPI [rename]: No such file or directory: %s') % (sourceFile))
def move(source, destination): '''recursively move a "source" file or directory to "destination"''' for filePath in glob.glob(source): if isFile(filePath) or isLink(filePath) or isDirectory(filePath): try: shutil.move(filePath, destination) except OSError: error( _('ActionsAPI [move]: Permission denied: %s to %s') % (filePath, destination)) else: error( _('ActionsAPI [move]: File %s doesn\'t exists.') % (filePath))
def copytree(source, destination, sym = True): '''recursively copy an entire directory tree rooted at source''' if isDirectory(source): if os.path.exists(destination): if isDirectory(destination): copytree(source, join_path(destination, os.path.basename(source.strip('/')))) return else: copytree(source, join_path(destination, os.path.basename(source))) return try: shutil.copytree(source, destination, sym) except OSError, e: error(_('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e))
def unlinkDir(sourceDirectory): '''delete an entire directory tree''' if isDirectory(sourceDirectory) or isLink(sourceDirectory): try: shutil.rmtree(sourceDirectory) except OSError: error( _('ActionsAPI [unlinkDir]: Operation not permitted: %s') % (sourceDirectory)) elif isFile(sourceDirectory): pass else: error( _('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory))
def chmod(filePath, mode = 0755): '''change the mode of filePath to the mode''' 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) except OSError: ctx.ui.error(_('ActionsAPI [chmod]: Operation not permitted: %s (mode: 0%o)') \ % (fileName, mode)) else: ctx.ui.error(_('ActionsAPI [chmod]: File %s doesn\'t exists.') % (fileName))
def touch(filePath): '''changes the access time of the 'filePath', or creates it if it does not exist''' 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: f = open(filePath, 'w') f.close() except IOError: error(_('ActionsAPI [touch]: Permission denied: %s') % (filePath))
def unlinkDir(sourceDirectory): '''delete an entire directory tree''' if isDirectory(sourceDirectory) or isLink(sourceDirectory): try: shutil.rmtree(sourceDirectory) except OSError: error( _('ActionsAPI [unlinkDir]: Operation not permitted: %s') % (sourceDirectory)) elif isFile(sourceDirectory): ctx.ui.warning( _('ActionsAPI [unlinkDir]: %s is not a directory, use \'unlink\' or \'remove\' to remove files.' ) % sourceDirectory) else: error( _('ActionsAPI [unlinkDir]: Directory %s doesn\'t exists.') % (sourceDirectory))
def touch(filePath): '''changes the access time of the 'filePath', or creates it if it is not exist''' 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: f = open(filePath, 'w') f.close() except IOError: error(_('ActionsAPI [touch]: Permission denied: %s') % (filePath))
def chmod(filePath, mode=0755): '''change the mode of filePath to the mode''' 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) except OSError: ctx.ui.error(_('ActionsAPI [chmod]: Operation not permitted: %s (mode: 0%o)') \ % (fileName, mode)) else: ctx.ui.error( _('ActionsAPI [chmod]: File %s doesn\'t exists.') % (fileName))
def doman(*sourceFiles): '''inserts the man pages in the list of files into /usr/share/man/''' '''example call: pisitools.doman("man.1", "pardus.*")''' manDIR = join_path(get.installDIR(), get.manDIR()) if not can_access_directory(manDIR): makedirs(manDIR) for sourceFile in sourceFiles: for source in glob.glob(sourceFile): try: pageName, pageDirectory = source[:source.rindex('.')], \ source[source.rindex('.')+1:] except ValueError: error(_('ActionsAPI [doman]: Wrong man page file: %s') % (source)) makedirs(join_path(manDIR, '/man%s' % pageDirectory)) system('install -m0644 %s %s' % (source, join_path(manDIR, '/man%s' % pageDirectory)))
def copytree(source, destination, sym=True): '''recursively copy an entire directory tree rooted at source''' if isDirectory(source): if os.path.exists(destination): if isDirectory(destination): copytree( source, join_path(destination, os.path.basename(source.strip('/')))) return else: copytree(source, join_path(destination, os.path.basename(source))) return try: shutil.copytree(source, destination, sym) except OSError, e: error( _('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e))
def doman(*sourceFiles): '''inserts the man pages in the list of files into /usr/share/man/''' '''example call: pisitools.doman("man.1", "pardus.*")''' manDIR = join_path(get.installDIR(), get.manDIR()) if not can_access_directory(manDIR): makedirs(manDIR) for sourceFile in sourceFiles: for source in glob.glob(sourceFile): try: pageName, pageDirectory = source[:source.rindex('.')], \ source[source.rindex('.')+1:] except ValueError: error( _('ActionsAPI [doman]: Wrong man page file: %s') % (source)) makedirs(join_path(manDIR, '/man%s' % pageDirectory)) system('install -m0644 %s %s' % (source, join_path(manDIR, '/man%s' % pageDirectory)))
def copy(source, destination, sym = True): '''recursively copy a "source" file or directory to "destination"''' 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) except IOError: error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination)) elif isLink(filePath) and sym: if isDirectory(destination): os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath))) else: if isFile(destination): os.remove(destination) os.symlink(os.readlink(filePath), destination) elif isLink(filePath) and not sym: if isDirectory(filePath): copytree(filePath, destination) else: shutil.copy(filePath, destination) elif isDirectory(filePath): copytree(filePath, destination, sym) else: error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)
def move(source, destination): '''recursively move a "source" file or directory to "destination"''' 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) except OSError: error(_('ActionsAPI [move]: Permission denied: %s to %s') % (filePath, destination)) else: error(_('ActionsAPI [move]: File %s doesn\'t exists.') % (filePath))
def move(source, destination): '''recursively move a "source" file or directory to "destination"''' 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) except OSError: error( _('ActionsAPI [move]: Permission denied: %s to %s') % (filePath, destination)) else: error( _('ActionsAPI [move]: File %s doesn\'t exists.') % (filePath))
error(_("ActionsAPI [copy]: Permission denied: %s to %s") % (file, destinationFile)) elif isDirectory(file): copytree(file, destinationFile) else: error(_("ActionsAPI [copy]: File %s does not exist.") % file) def copytree(source, destination, sym=False): """recursively copy an entire directory tree rooted at source""" if isDirectory(source) or isLink(source): try: shutil.copytree(source, destination, sym) except OSError, e: error(_("ActionsAPI [copytree] %s to %s: %s") % (source, destination, e)) else: error(_("ActionsAPI [copytree]: Directory %s doesn't exists.") % (source)) def touch(sourceFile): """changes the access time of the 'sourceFile', or creates it if it is not exist""" if glob.glob(sourceFile): for file in glob.glob(sourceFile): os.utime(file, None) else: try: f = open(sourceFile, "w") f.close() except IOError: error(_("ActionsAPI [touch]: Permission denied: %s") % (sourceFile))
join_path(destination, os.path.basename(source.strip('/')))) return else: copytree(source, join_path(destination, os.path.basename(source))) return try: shutil.copytree(source, destination, sym) except OSError, e: error( _('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e)) else: error( _('ActionsAPI [copytree]: Directory %s doesn\'t exists.') % (source)) 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): os.utime(f, None) else: try: f = open(filePath, 'w') f.close() except IOError: error(_('ActionsAPI [touch]: Permission denied: %s') % (filePath))
def copytree(source, destination, sym = True): '''recursively copy an entire directory tree rooted at source''' if isDirectory(source): if os.path.exists(destination): if isDirectory(destination): copytree(source, join_path(destination, os.path.basename(source.strip('/')))) return else: copytree(source, join_path(destination, os.path.basename(source))) return try: shutil.copytree(source, destination, sym) except OSError, e: error(_('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e)) else: error(_('ActionsAPI [copytree]: Directory %s doesn\'t exists.') % (source)) def touch(filePath): '''changes the access time of the 'filePath', or creates it if it does not exist''' 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: f = open(filePath, 'w') f.close()