Exemplo n.º 1
0
    def _printItem(self, item, args, level):
        """
        Print the item depending on the command line options.
        """
        itemType = item.getType()

        filePath = ''
        detailed = ''
        detailedSequence = ''

        # sam-ls --explode-sequences
        sequenceExploded = False
        if args.explodeSequences and itemType == sequenceParser.eTypeSequence:
            sequence = item.getSequence()
            for frameRange in sequence.getFrameRanges():
                # for each frame range, print a new item as sequence
                subSequence = sequenceParser.Sequence(sequence.getPrefix(), sequence.getPadding(), sequence.getSuffix(), frameRange.first, frameRange.last, frameRange.step)
                if subSequence.__str__() not in self._sequenceExploded:
                    self._sequenceExploded.append(subSequence.__str__())
                    sequenceExploded = True
                    self._printItem(sequenceParser.Item(subSequence, item.getFolder()), args, level)
            # to skip recursivity
            if sequenceExploded:
                return

        # sam-ls -l
        if args.longListing:
            # type - date - size
            characterFromType = 'a'
            if itemType == sequenceParser.eTypeUndefined:
                characterFromType = '?'
            elif itemType == sequenceParser.eTypeFolder:
                characterFromType = 'd'
            elif itemType == sequenceParser.eTypeFile:
                characterFromType = 'f'
            elif itemType == sequenceParser.eTypeSequence:
                characterFromType = 's'
            elif itemType == sequenceParser.eTypeLink:
                characterFromType = 'l'

            # type - permissions - user - group - lastUpdate - size
            itemStat = sequenceParser.ItemStat(item)

            permissions = ''
            permissions += 'r' if itemStat.ownerCanRead else '-'
            permissions += 'w' if itemStat.ownerCanWrite else '-'
            permissions += 'x' if itemStat.ownerCanExecute else '-'
            permissions += 'r' if itemStat.groupCanRead else '-'
            permissions += 'w' if itemStat.groupCanWrite else '-'
            permissions += 'x' if itemStat.groupCanExecute else '-'
            permissions += 'r' if itemStat.otherCanRead else '-'
            permissions += 'w' if itemStat.otherCanWrite else '-'
            permissions += 'x' if itemStat.otherCanExecute else '-'

            lastUpdate = date.fromtimestamp(itemStat.modificationTime).strftime('%d/%m/%y')

            minSize = samUtils.getReadableSize(itemStat.minSize) if itemStat.minSize != itemStat.size else '-'
            maxSize = samUtils.getReadableSize(itemStat.maxSize) if itemStat.maxSize != itemStat.size else '-'

            detailed = '{:1}{:9}'.format(characterFromType, permissions)
            detailed += ' {:8} {:8} {:8}'.format(itemStat.getUserName(), itemStat.getGroupName(), lastUpdate)
            detailed += ' {:6} {:6} {:6}'.format(minSize, maxSize, samUtils.getReadableSize(itemStat.size))
            detailed += '\t'

        # only for sequences: [ begin : end ] nbFiles - nbMissingFiles
        if itemType == sequenceParser.eTypeSequence:
            sequence = item.getSequence()
            detailedSequence = '[{first}:{last}] {nbFiles} files'.format(first=sequence.getFirstTime(), last=sequence.getLastTime(), nbFiles=sequence.getNbFiles())
            nbHoles = (sequence.getLastTime() - sequence.getFirstTime() + 1) - sequence.getNbFiles()
            if nbHoles:
                detailedSequence += ' - {nbHoles} missing files'.format(nbHoles=nbHoles)

        # sam-ls --absolute-path
        if args.absolutePath:
            filePath += os.path.abspath(item.getFolder())

        # sam-ls --relative-path
        if args.relativePath:
            filePath += (item.getFolder() if item.getFolder()[0] != '/' else '.')
            filePath += ('/' if filePath[-1] != '/' else '')

        # filename
        filename = item.getFilename()
        # sam-ls --format
        if itemType == sequenceParser.eTypeSequence:
            filename = samUtils.getSequenceNameWithFormatting(item.getSequence(), args.format)
        # sam-ls --no-color
        if args.noColor:
            filePath = os.path.join(filePath, filename)
        else:
            if itemType == sequenceParser.eTypeFolder:
                # blue is not visible without bold
                filePath = colored.blue(os.path.join(filePath, filename), bold=True)
            elif itemType == sequenceParser.eTypeFile:
                filePath = colored.green(os.path.join(filePath, filename))
            elif itemType == sequenceParser.eTypeSequence:
                # magenta is not visible without bold
                filePath = colored.magenta(os.path.join(filePath, filename), bold=True)
            elif itemType == sequenceParser.eTypeLink:
                filePath = colored.cyan(os.path.join(filePath, filename))
            else:
                filePath = colored.red(os.path.join(filePath, filename))
        filePath += ' \t'

        # sam-ls -R / sam-ls -L
        indentTree = ''
        if args.recursive and args.level != 0:
            indentTree += '|  ' * (level - 1)
            indentTree += '|__ '

        # display
        toPrint = detailed + filePath + detailedSequence
        # if first level or no tree formatting
        if level == 0 or args.level == 0:
            puts(toPrint.format())
        else:
            with indent(level, quote=indentTree):
                puts(toPrint.format())

        if itemType == sequenceParser.eTypeSequence:
            self._itemPrinted.append(item.getSequence().__str__())
        else:
            self._itemPrinted.append(item.getFilename())
Exemplo n.º 2
0
    def printItem(self, item, args, level):
        """
        Print the item depending on the command line options.
        """
        itemType = item.getType()

        filePath = ''
        detailed = ''
        detailedSequence = ''

        # sam-ls -l
        if args.longListing:
            # type - date - size
            characterFromType = 'a'
            if itemType == sequenceParser.eTypeUndefined:
                characterFromType = '?'
            elif itemType == sequenceParser.eTypeFolder:
                characterFromType = 'd'
            elif itemType == sequenceParser.eTypeFile:
                characterFromType = 'f'
            elif itemType == sequenceParser.eTypeSequence:
                characterFromType = 's'

                # [ begin : end ] nbFiles - nbMissingFiles
                sequence = item.getSequence()
                detailedSequence = '[{first}:{last}] {nbFiles} files'.format(first=sequence.getFirstTime(), last=sequence.getLastTime(), nbFiles=sequence.getNbFiles())

            elif itemType == sequenceParser.eTypeLink:
                characterFromType = 'l'

            # type - permissions - user - group - lastUpdate - size
            itemStat = sequenceParser.ItemStat(item)

            permissions = ''
            permissions += 'r' if itemStat.ownerCanRead else '-'
            permissions += 'w' if itemStat.ownerCanWrite else '-'
            permissions += 'x' if itemStat.ownerCanExecute else '-'
            permissions += 'r' if itemStat.groupCanRead else '-'
            permissions += 'w' if itemStat.groupCanWrite else '-'
            permissions += 'x' if itemStat.groupCanExecute else '-'
            permissions += 'r' if itemStat.otherCanRead else '-'
            permissions += 'w' if itemStat.otherCanWrite else '-'
            permissions += 'x' if itemStat.otherCanExecute else '-'

            lastUpdate = date.fromtimestamp(itemStat.modificationTime).strftime('%d/%m/%y')

            minSize = samUtils.getReadableSize(itemStat.minSize) if itemStat.minSize != itemStat.size else '-'
            maxSize = samUtils.getReadableSize(itemStat.maxSize) if itemStat.maxSize != itemStat.size else '-'

            detailed = '{:1}{:9}'.format(characterFromType, permissions)
            detailed += ' {:} {:} {:8}'.format(itemStat.getUserName(), itemStat.getGroupName(), lastUpdate)
            detailed += ' {:6} {:6} {:6}'.format(minSize, maxSize, samUtils.getReadableSize(itemStat.size))
            detailed += '\t'

        # sam-ls --absolute-path
        if args.absolutePath:
            filePath += os.path.abspath(item.getFolder())

        # sam-ls --relative-path
        if args.relativePath:
            filePath += (item.getFolder() if item.getFolder()[0] != '/' else '.')
            filePath += ('/' if filePath[-1] != '/' else '')

        # filename
        filename = item.getFilename()
        # sam-ls --format
        if itemType == sequenceParser.eTypeSequence:
            filename = samUtils.getSequenceNameWithFormatting(item.getSequence(), args.format)
        # sam-ls --color
        if args.color:
            if itemType == sequenceParser.eTypeFolder:
                # blue is not visible without bold
                filePath = colored.blue(os.path.join(filePath, filename), bold=True)
            elif itemType == sequenceParser.eTypeFile:
                filePath = colored.green(os.path.join(filePath, filename))
            elif itemType == sequenceParser.eTypeSequence:
                # magenta is not visible without bold
                filePath = colored.magenta(os.path.join(filePath, filename), bold=True)
            elif itemType == sequenceParser.eTypeLink:
                filePath = colored.cyan(os.path.join(filePath, filename))
            else:
                filePath = colored.red(os.path.join(filePath, filename))
        else:
            filePath = os.path.join(filePath, filename)
        filePath += ' \t'

        # sam-ls -R / sam-ls -L
        indentTree = ''
        if args.recursive and args.level != 0:
            indentTree += '|  ' * (level - 1)
            indentTree += '|__ '

        # display
        toPrint = detailed + filePath + detailedSequence
        # if first level or no tree formatting
        if level == 0 or args.level == 0:
            puts(toPrint.format())
        else:
            with indent(level, quote=indentTree):
                puts(toPrint.format())
Exemplo n.º 3
0
    def _printItem(self, item, args, level):
        """
        Print the item depending on the command line options.
        """
        itemType = item.getType()

        filePath = ''
        detailed = ''
        detailedSequence = ''

        # sam-ls --explode-sequences
        sequenceExploded = False
        if args.explodeSequences and itemType == sequenceParser.eTypeSequence:
            sequence = item.getSequence()
            for frameRange in sequence.getFrameRanges():
                # for each frame range, print a new item as sequence
                subSequence = sequenceParser.Sequence(sequence.getPrefix(),
                                                      sequence.getPadding(),
                                                      sequence.getSuffix(),
                                                      frameRange.first,
                                                      frameRange.last,
                                                      frameRange.step)
                if subSequence.__str__() not in self._sequenceExploded:
                    self._sequenceExploded.append(subSequence.__str__())
                    sequenceExploded = True
                    self._printItem(
                        sequenceParser.Item(subSequence, item.getFolder()),
                        args, level)
            # to skip recursivity
            if sequenceExploded:
                return

        # sam-ls -l
        if args.longListing:
            # type - date - size
            characterFromType = 'a'
            if itemType == sequenceParser.eTypeUndefined:
                characterFromType = '?'
            elif itemType == sequenceParser.eTypeFolder:
                characterFromType = 'd'
            elif itemType == sequenceParser.eTypeFile:
                characterFromType = 'f'
            elif itemType == sequenceParser.eTypeSequence:
                characterFromType = 's'
            elif itemType == sequenceParser.eTypeLink:
                characterFromType = 'l'

            # type - permissions - user - group - lastUpdate - size
            itemStat = sequenceParser.ItemStat(item)

            permissions = ''
            permissions += 'r' if itemStat.ownerCanRead else '-'
            permissions += 'w' if itemStat.ownerCanWrite else '-'
            permissions += 'x' if itemStat.ownerCanExecute else '-'
            permissions += 'r' if itemStat.groupCanRead else '-'
            permissions += 'w' if itemStat.groupCanWrite else '-'
            permissions += 'x' if itemStat.groupCanExecute else '-'
            permissions += 'r' if itemStat.otherCanRead else '-'
            permissions += 'w' if itemStat.otherCanWrite else '-'
            permissions += 'x' if itemStat.otherCanExecute else '-'

            lastUpdate = date.fromtimestamp(
                itemStat.modificationTime).strftime('%d/%m/%y')

            minSize = samUtils.getReadableSize(
                itemStat.minSize) if itemStat.minSize != itemStat.size else '-'
            maxSize = samUtils.getReadableSize(
                itemStat.maxSize) if itemStat.maxSize != itemStat.size else '-'

            detailed = '{:1}{:9}'.format(characterFromType, permissions)
            detailed += ' {:8} {:8} {:8}'.format(itemStat.getUserName(),
                                                 itemStat.getGroupName(),
                                                 lastUpdate)
            detailed += ' {:6} {:6} {:6}'.format(
                minSize, maxSize, samUtils.getReadableSize(itemStat.size))
            detailed += '\t'

        # only for sequences: [ begin : end ] nbFiles - nbMissingFiles
        if itemType == sequenceParser.eTypeSequence:
            sequence = item.getSequence()
            detailedSequence = '[{first}:{last}] {nbFiles} files'.format(
                first=sequence.getFirstTime(),
                last=sequence.getLastTime(),
                nbFiles=sequence.getNbFiles())
            nbHoles = (sequence.getLastTime() - sequence.getFirstTime() +
                       1) - sequence.getNbFiles()
            if nbHoles:
                detailedSequence += ' - {nbHoles} missing files'.format(
                    nbHoles=nbHoles)

        # sam-ls --absolute-path
        if args.absolutePath:
            filePath += os.path.abspath(item.getFolder())

        # sam-ls --relative-path
        if args.relativePath:
            filePath += (item.getFolder()
                         if item.getFolder()[0] != '/' else '.')
            filePath += ('/' if filePath[-1] != '/' else '')

        # filename
        filename = item.getFilename()
        # sam-ls --format
        if itemType == sequenceParser.eTypeSequence:
            filename = samUtils.getSequenceNameWithFormatting(
                item.getSequence(), args.format)
        # sam-ls --no-color
        if args.noColor:
            filePath = os.path.join(filePath, filename)
        else:
            if itemType == sequenceParser.eTypeFolder:
                # blue is not visible without bold
                filePath = colored.blue(os.path.join(filePath, filename),
                                        bold=True)
            elif itemType == sequenceParser.eTypeFile:
                filePath = colored.green(os.path.join(filePath, filename))
            elif itemType == sequenceParser.eTypeSequence:
                # magenta is not visible without bold
                filePath = colored.magenta(os.path.join(filePath, filename),
                                           bold=True)
            elif itemType == sequenceParser.eTypeLink:
                filePath = colored.cyan(os.path.join(filePath, filename))
            else:
                filePath = colored.red(os.path.join(filePath, filename))
        filePath += ' \t'

        # sam-ls -R / sam-ls -L
        indentTree = ''
        if args.recursive and args.level != 0:
            indentTree += '|  ' * (level - 1)
            indentTree += '|__ '

        # display
        toPrint = detailed + filePath + detailedSequence
        # if first level or no tree formatting
        if level == 0 or args.level == 0:
            puts(toPrint.format())
        else:
            with indent(level, quote=indentTree):
                puts(toPrint.format())

        if itemType == sequenceParser.eTypeSequence:
            self._itemPrinted.append(item.getSequence().__str__())
        else:
            self._itemPrinted.append(item.getFilename())