Ejemplo n.º 1
0
def execute_tags_command(objs, db, options):
    for obj in objs:
        description = describe_by_mode(obj)
        db.Print(u'Object %s:' % description)
        if obj.about:
            tags = db.get_object_tags_by_about(obj.about)
        else:
            tags = db.get_object_tags_by_id(obj.id)
        tags = sort_tags(tags)
        for tag in tags:
            fulltag = u'/%s' % tag
            outtag = u'/%s' % tag if db.unixStyle else tag
            if obj.about:
                status, (v, t) = db.get_tag_value_by_about(obj.about, fulltag,
                                                           getMime=True)
            else:
                status, (v, t) = db.get_tag_value_by_id(obj.id, fulltag,
                                                        getMime=True)

            if status == STATUS.OK:
                db.Print(formatted_tag_value(outtag, v, mime=t))
            elif status == STATUS.NOT_FOUND:
                db.Print(u'  %s' % cli_bracket(u'tag %s not present' % outtag))
            else:
                db.Print(cli_bracket(u'error code %s attempting to read tag %s'
                                     % (error_code(status), uttag)))
Ejemplo n.º 2
0
def execute_tag_command(objs, db, tags, options, action):
    if options.force and db.webapp:
        raise CommandError(u'No file system available for the web.')
    tags = form_tag_value_pairs(tags, options)
    for obj in objs:
        description = describe_by_mode(obj)
        for tag in tags:
            if obj.about:
                o = db.tag_object_by_about(obj.about, tag.name, tag.value,
                                           value_type=tag.mime,
                                           inPref=True)
            else:
                o = db.tag_object_by_id(obj.id, tag.name, tag.value,
                                        value_type=tag.mime,
                                        inPref=True)
            if o == 0:
                if options.verbose or options.anon:
                    db.Print(u'Tagged object %s with %s'
                             % (description,
                                formatted_tag_value(tag.name, tag.value,
                                                    prefix=u'')))
                    o = obj
            else:
                db.warning(u'Failed to tag object %s with %s'
                        % (description, tag.name))
                db.warning(u'Error code %s' % error_code(o))

    return o  # 0 if OK
Ejemplo n.º 3
0
def execute_show_command(objs, db, tags, options, action):
    actions = {
        u'id': db.get_tag_value_by_id,
        u'about': db.get_tag_value_by_about,
    }
    terse = (action == u'get')
    for obj in objs:
        description = describe_by_mode(obj)
        if not terse:
            db.Print(u'Object %s:' % description)
#            tags = sort_tags(tags)
        for tag in tags:
            fulltag = db.abs_tag_path(tag, inPref=True)
            outtag = db.abs_tag_path(tag, inPref=True, outPref=True)
            if tag == u'/id':
                t = None
                if obj.about:
                    o = db.query(u'fluiddb/about = "%s"' % obj.about)
                    if type(o) == types.IntType:  # error
                        status, v = o, None
                    else:
                        status, v = STATUS.OK, o[0]
                else:
                    status, v = STATUS.OK, obj.id
            else:
                if obj.about:
                    status, (v, t) = db.get_tag_value_by_about(obj.about, tag,
                                                               inPref=True,
                                                               getMime=True)
                else:
                    status, (v, t)  = db.get_tag_value_by_id(obj.id, tag,
                                                             inPref=True,
                                                             getMime=True)

            saveForNow = True   # while getting ready to move to objects
            if status == STATUS.OK:
                db.Print(formatted_tag_value(outtag, v, terse, mime=t),
                         allowSave=saveForNow)
                obj.tags[outtag] = v
            elif status == STATUS.NOT_FOUND:
                db.Print(u'  %s' % cli_bracket(u'tag %s not present' % outtag),
                         allowSave=saveForNow)
                obj.tags[outtag] = O     # Object class; signifies missing
            else:
                db.Print(cli_bracket(u'error code %s attempting to read tag %s'
                                     % (error_code(status), outtag)),
                                        allowSave=saveForNowe)