Skip to content

Instantly share code, notes, and snippets.

@tecoholic
Last active January 31, 2017 19:24
Show Gist options
  • Save tecoholic/7cdc620bfe8ec805df14f359acdee7ad to your computer and use it in GitHub Desktop.
Save tecoholic/7cdc620bfe8ec805df14f359acdee7ad to your computer and use it in GitHub Desktop.
macroset = {
"oxObjectClass": "oxPublished:4",
"oxReserved": "oxOrgOID:0",
"oxSyntax": "oxPublished:1",
"oxOrgOID": "1.3.6.1.4.1.48710",
"oxSomething": "oxAttribute:0",
"oxThird": "oxSomething:3",
"oxMatchRules": "oxPublished:2",
"oxPublished": "oxOrgOID:1",
"oxAttribute": "oxPublished:3",
}
def __compare_defs(m1, m2):
try:
n1 = int(m1[1].split(':')[1])
n2 = int(m2[1].split(':')[1])
return n1 - n2
except IndexError:
print "Index error"
print m1, m2
return 0
def sorter(macros, parent):
#print "calling with parent {0}".format(parent)
children = [(k, v) for k, v in macros.items() if parent in v]
items = [parent]
for k, v in sorted(children, cmp=__compare_defs):
items.extend(sorter(macros, k))
return items
print sorter(macroset, 'oxOrgOID')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment