示例#1
0
文件: new.py 项目: yaccz/cpk
    def attribute(self):
        """ Creates new attribute """
        a = Attribute()
        a.name = self.args.nodes.pop()

        if self.args.nodes:
            a.descrption = args.nodes.pop()

        session.add(a)
        from sqlalchemy.exc import IntegrityError

        try:
            session.commit()
        except IntegrityError:
            self.die("IntegrityError, attribute name not unique?")
示例#2
0
文件: new.py 项目: yaccz/cpk
    def node(self):
        """ Creates a new node """
        filters = self.tokens_2_filters(self.tokenize_nodes())

        if not filters[-1]['node'] and filters[-1]['attr']:
            new_type = Attribute.get(filters.pop()['attr'])
        else:
            new_type = Attribute.password()

        #if new_type and new_type.one_per_higher_node:
        if new_type:
            filters.append({'attr': new_type})


        getLogger("%s_%s" % (__name__, self.__class__.__name__,)).debug("filters: %s" % filters)
        try:
            node = Node.get(filters,create=True)
        except MatchedMultiple as e:
            self.die("Multiple values %s " % (",".join([i.name for i in e.matched]),e.last.name))

        getLogger("%s_%s" % (__name__, self.__class__.__name__,)).debug("node.value: %s" % node.value)

        if node.value and not self.args.force:
            raise ResourceExists()

        # node.attribute.new_value()
        #   could return new value based on the type so it could be more generic
        #   however a new_type would have to not be None

        value = self.get_value(new_type)

        node.value = self.encrypt(value)
        session.commit()

        if self.__generated:
            self.output(value)
示例#3
0
文件: get.py 项目: yaccz/cpk
    def _run(self,args):
        filters = self.tokens_2_filters(self.tokenize_nodes())

        if filters[-1]['node']:
            try:
                a = Attribute.password()
                filters.append({'attr':a.name})
                # append filter for goal we want to retrieve
                # unless it has been specified by the user as the last node
                # or there is no configured password attribute

            except NoResultFound:
                filters.append({})
                # append empty filter so we'll get the "one more" node

        goal = Node.get(filters)

        self.output(self.decrypt(goal.value))