Example #1
0
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))
Example #2
0
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)
Example #3
0
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)
Example #4
0
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))
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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))
Example #9
0
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)
Example #10
0
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))
Example #11
0
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))
Example #12
0
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
Example #13
0
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))
Example #14
0
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))
Example #15
0
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))
Example #16
0
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))
Example #17
0
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))
Example #18
0
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
Example #19
0
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))
Example #20
0
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))
Example #21
0
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))
Example #22
0
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)
Example #23
0
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))
Example #24
0
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))
Example #25
0
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))
Example #26
0
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))
Example #27
0
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))
Example #28
0
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))
Example #29
0
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))
Example #30
0
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))
Example #31
0
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))
Example #32
0
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)))
Example #33
0
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))
Example #34
0
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)))
Example #35
0
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)
Example #36
0
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))
Example #37
0
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))
Example #38
0
                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))

Example #39
0
                    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))
Example #40
0
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()