From 5f6698c9970e416271e631c1b1700ea823c4823c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 2 Nov 2005 02:41:08 +0000 Subject: [PATCH] * a makepath function, opposite of splitpath * fix: path splitting in last tag, but encode is still wrong. u-uh! --- pisi/util.py | 10 +++++++++- pisi/xmlfile.py | 12 +++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pisi/util.py b/pisi/util.py index b39dc729..fab564ca 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -82,7 +82,7 @@ def unzip(seq): def concat(l): '''concatenate a list of lists''' - return reduce( lambda x,y: x+y, l ) + return reduce( operator.concat, l ) def strlist(l): """concatenate string reps of l's elements""" @@ -169,6 +169,14 @@ def splitpath(a): comps.pop() return comps +def makepath(comps, relative = False, sep = os.path.sep): + """reconstruct a path from components""" + path = reduce(lambda x,y: x + sep + y, comps, '') + if relative: + return path[len(sep):] + else: + return path + # I'm not sure how necessary this is. Ahem. def commonprefix(l): """an improved version of os.path.commonprefix, diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index b981f82b..bda2b646 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -591,11 +591,10 @@ class autoxml(oo.autosuper): def gen_list_tag(cls, tag, spec): """generate a list datatype. stores comps in tag/comp_tag""" name, tag_type, req, path = cls.parse_spec(tag, spec) - #head, last = cls.tagpath_head_last(path) + pathcomps = path.split('/') - list_tagpath = path[:path.rfind('/')] - comp_tag = pathcomps[len(pathcomps)-1] - #TODO: make default path ... tag + '/' + comp_tag when comp is class! + comp_tag = pathcomps.pop() + list_tagpath = util.makepath(pathcomps, sep='/', relative=True) if len(tag_type) != 1: raise Error(_('List type must contain only one element')) @@ -623,7 +622,10 @@ class autoxml(oo.autosuper): dom = node.ownerDocument if l and len(l) > 0: for item in l: - listnode = addNode(dom, node, list_tagpath) + if list_tagpath: + listnode = addNode(dom, node, list_tagpath) + else: + listnode = node encode_item(xml, listnode, item, errs) else: if req is mandatory: