Skip to content

Commit

Permalink
removing unused code, refs #12
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/behr_mi/git/sumo_synched/trunk@15427 afbd958f-9f77-42d5-a016-97a22340ccf4
  • Loading branch information
behrisch committed Jan 17, 2014
1 parent 5633842 commit 453b590
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions sumo/tools/bin/csv2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,6 @@

from collections import defaultdict
from optparse import OptionParser
import xml.sax

class LevelHandler(xml.sax.handler.ContentHandler):
"""A handler which knows the current nesting level"""
def __init__(self):
self.lvl = -1

def startElement(self, name, attrs):
self.lvl += 1

def endElement(self, name):
self.lvl -= 1

class AttrFinder(LevelHandler):
def __init__(self):
LevelHandler.__init__(self)
self.lvlmax = self.lvl
self.attrs = []
self.knownAttrs = set()
self.tagAttrs = defaultdict(set) # tag -> set of attrs
self.renamedAttrs = {} # (name, attr) -> renamedAttr

def startElement(self, name, attrs):
LevelHandler.startElement(self, name, attrs)
self.lvlmax = max(self.lvl, self.lvlmax)
if self.lvl > 0:
for a in attrs.keys():
if not a in self.tagAttrs[name]:
self.tagAttrs[name].add(a)
if a in self.knownAttrs:
if not (name, a) in self.renamedAttrs:
anew = "%s_%s" % (name, a)
print("warning: renaming attribute %s of tag %s to %s" % (
a, name, anew))
self.renamedAttrs[(name, a)] = anew
self.knownAttrs.add(anew)
self.attrs.append(anew)
else:
self.knownAttrs.add(a)
self.attrs.append(a)


class CSVWriter(LevelHandler):
def __init__(self, attrs, renamedAttrs, output_level, outfile, options):
LevelHandler.__init__(self)
self.attrs = attrs
self.renamedAttrs = renamedAttrs
self.output_level = output_level
self.outfile = outfile
self.options = options
self.currentValues = defaultdict(lambda : "")

def startElement(self, name, attrs):
LevelHandler.startElement(self, name, attrs)
if self.lvl > 0:
for a, v in attrs.items():
a = self.renamedAttrs.get((name, a), a)
self.currentValues[a] = v
if self.lvl == self.output_level:
self.outfile.write(self.options.separator.join(
[self.currentValues[a] for a in self.attrs]) + "\n")


def get_options():
optParser = OptionParser(usage="Usage: " + sys.argv[0])
Expand Down

0 comments on commit 453b590

Please sign in to comment.