Exemplo n.º 1
0
Arquivo: set.py Projeto: yaccz/cpk
    def _run(self,args):
        filters = self.tokens_2_filters(self.tokenize_nodes())

        n = Node.get(filters)

        n.value = self.encrypt(self.input())
        session.commit()
Exemplo n.º 2
0
Arquivo: new.py Projeto: 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?")
Exemplo n.º 3
0
Arquivo: rm.py Projeto: yaccz/cpk
    def _run(self,args):
        filters = self.tokens_2_filters(self.tokenize_nodes())

        # do not modify filters here
        # in this command the path must be specified exactly

        goal = Node.get(filters)

        if not goal.lower() == []:
            raise Exception('node is not leaf')
            # ^ FIXME add -r option

        map(session.delete,goal.higher_edges)
        # ^ FIXME: there may be better solution via sqlalchemy
        session.delete(goal)
        session.commit()
Exemplo n.º 4
0
Arquivo: new.py Projeto: 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)