Ejemplo n.º 1
0
    def _do_cat(self, obj, attrs=[], add_full_paths=False):
        items = model_to_dict(obj).items()

        data = dict((key, value) for key, value in items
                    if obj and (key in attrs or not attrs))

        data['__name__'] = obj.__name__

        if 'owner' in attrs or not attrs:
            data['owner'] = obj.__owner__

        cls = type(removeSecurityProxy(obj))
        data['__classname__'] = cls.__name__
        data['__module__'] = cls.__module__

        if 'permissions' in attrs or not attrs:
            data['permissions'] = self._do_cat_acl(obj)

        if 'tags' in data:
            data['tags'] = list(data['tags'])

        if len(data.keys()) == 0:
            return

        if add_full_paths:
            data.update({'path': canonical_path(obj)})

        if not attrs and IIncomplete.providedBy(obj):
            data.update({'incomplete': True})

        return data
Ejemplo n.º 2
0
    def _do_cat(self, obj, attrs, filename=None):
        name = '%s: ' % filename if filename else ''

        data = [(key, value, name + title)
                for (key, value), title
                in zip(model_to_dict(obj).items(), model_to_dict(obj, use_titles=True).keys())
                if key in attrs or not attrs]

        log.msg('data: %s' % data, system='cat-cmd')

        if data:
            max_title_len = max(len(title) for key, _, title in data)
            for key, value, title in data:
                if isinstance(value, dict):
                    # security proxies don't mimic tuple() perfectly
                    # thus cannot be passed to "%" directly
                    pretty_value = ', '.join(['%s:%s' % tuple(i) for i in value.items()])
                elif hasattr(value, '__iter__'):
                    strings = [str(i) for i in value]
                    if not isinstance(value, tuple):
                        strings = sorted(strings)
                    pretty_value = ', '.join(strings)
                elif key in ('mtime', 'ctime'):
                    pretty_value = datetime.datetime.fromtimestamp(value).isoformat()
                else:
                    pretty_value = value
                self.write("%s\t%s\n" % ((title.encode('utf8') + ':').ljust(max_title_len),
                                         str(pretty_value).encode('utf8')))

        if not attrs and IIncomplete.providedBy(obj):
            self.write("-----------------\n")
            self.write("This %s is incomplete.\n" % (type(removeSecurityProxy(obj)).__name__))
Ejemplo n.º 3
0
    def _do_dbcat(self, obj, filename=None):
        data = list(self._get_data(obj))
        max_title_len = max(len(title) for title, _ in data)

        for title, value in data:
            if isinstance(value, dict):
                # security proxies don't mimic tuple() perfectly
                # thus cannot be passed to "%" directly
                pretty_value = ', '.join(['%s:%s' % tuple(i) for i in value.items()])
            elif hasattr(value, '__iter__'):
                strings = [str(i) for i in value]
                if not isinstance(value, tuple):
                    strings = sorted(strings)
                pretty_value = ', '.join(strings)
            elif title in ('mtime', 'ctime') and isinstance(value, float):
                pretty_value = datetime.datetime.fromtimestamp(value).isoformat()
            else:
                pretty_value = value

            self.write("%s\t%s\n" % ((title.encode('utf8') + ':').ljust(max_title_len),
                                     str(pretty_value).encode('utf8')))

        if IIncomplete.providedBy(obj):
            self.write("-----------------\n")
            self.write("This %s is incomplete.\n" % (type(removeSecurityProxy(obj)).__name__))
Ejemplo n.º 4
0
    def _do_cat(self, obj, attrs=[], add_full_paths=False):
        items = model_to_dict(obj).items()

        data = dict((key, value) for key, value in items if obj and (key in attrs or not attrs))

        data['__name__'] = obj.__name__

        if 'owner' in attrs or not attrs:
            data['owner'] = obj.__owner__

        cls = type(removeSecurityProxy(obj))
        data['__classname__'] = cls.__name__
        data['__module__'] = cls.__module__

        if 'permissions' in attrs or not attrs:
            data['permissions'] = self._do_cat_acl(obj)

        if 'tags' in data:
            data['tags'] = list(data['tags'])

        if len(data.keys()) == 0:
            return

        if add_full_paths:
            data.update({'path': canonical_path(obj)})

        if not attrs and IIncomplete.providedBy(obj):
            data.update({'incomplete': True})

        return data
Ejemplo n.º 5
0
    def _do_cat(self, obj, attrs, multiline, filename=None):
        name = '%s: ' % filename if filename else ''

        data = [(key, value, name + title) for (key, value), title in zip(
            model_to_dict(obj).items(),
            model_to_dict(obj, use_titles=True).keys())
                if key in attrs or not attrs]

        log.msg('data: %s' % data, system='cat-cmd')

        if data:
            max_title_len = max(len(title) for key, _, title in data) + 1
            for key, value, title in data:
                if isinstance(value, dict):
                    if multiline:
                        separator = '\n ' + ' ' * max_title_len
                    else:
                        separator = ', '
                    # security proxies don't mimic tuple() perfectly
                    # thus cannot be passed to "%" directly
                    pretty_value = separator.join(
                        ['%s: %s' % tuple(i) for i in value.items()])
                elif hasattr(value, '__iter__'):
                    strings = [str(i) for i in value]
                    if not isinstance(value, tuple):
                        strings = sorted(strings)
                    if multiline:
                        separator = '\n ' + ' ' * max_title_len
                    else:
                        separator = ', '
                    pretty_value = separator.join(strings)
                elif key in ('mtime', 'ctime'):
                    pretty_value = datetime.datetime.fromtimestamp(
                        value).isoformat()
                else:
                    pretty_value = value
                self.write("%s %s\n" %
                           ((title.encode('utf8') + ':').ljust(max_title_len),
                            str(pretty_value).encode('utf8')))

        if not attrs and IIncomplete.providedBy(obj):
            self.write("-----------------\n")
            self.write("This %s is incomplete.\n" %
                       (type(removeSecurityProxy(obj)).__name__))