Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
python: provide more high-level APIs #2584
I have some common helpers which are often needed and should be directly added to our binding (so that they are always available, well tested and well documented)
def make_set (ks, where): s = set () for k in ks: if k.isDirectBelow (where): s.add (k) return s; def unpack_names (ks): s = set () for k in ks: s.add (k.name) return s def unpack_basenames (ks): s = set () for k in ks: s.add (k.basename) return s def is_array_entry (k, arrayname): if k.basename != '#': return False x = copy.copy(k) x.delBaseName() if x.basename == arrayname: return True def append (ks, name, p): n = kdb.Key(name) n.string = str(p) ks.append (n) print n # this is only a workaround, ideally this would be directly in kdb.KeySet: class GetKeySet(kdb.KeySet): def get(self, n): k = ks.lookup(n) if not k: raise KeyError(n+" not found") return k.string def set(self, n, s): k = ks.lookup(n) if not k: # TODO: call append here raise KeyError(n+" not found") k.string = str(s)
The binding already has
And if someone has the python skills for it, a constructor for creating a Key from two strings (name and value) and a dictionary of strings (for metadata) would be much nicer than the C like vararg constructor as well.
Thank you for the feedback! Yes, then
You are completely right! If we pull in the libease dependency, however, we should fully add all these functions to the python binding. This would be a separate task, though. It would be interesting if elektraKsFilter is faster than a python loop.
Yes, in Java we already have this.