#left_side = True # POSITION="right" # read otl file into memory filelines = codecs.open(fname, 'r', encoding='utf-8') # remove those that are too deep or body text and pesky end of line characters #filelines = [line.rstrip('\r\n') for line in filelines if otl.level(line) <= depth] #filelines = [line for line in filelines if otl.is_heading(line)] # first handle the body texts turn it into a list of headings with associated # body text for each one this is because the body text especially multi-line is # what makes it awkward. headings = [] bodytexts = [] for line in filelines: if otl.is_heading(line): headings.append(line) bodytexts.append([]) else: # TODO this ': ' removal should go in otl.py? bodytexts[-1].append(line.lstrip()[2:] + '\n') #import pdb; pdb.set_trace() oldheading = '' for heading, bodytext in zip(headings, bodytexts): if debug: print heading, bodytext level = otl.level(heading) oldlevel = otl.level(oldheading) if level == oldlevel:
def otl2mm(*arg, **kwarg): fname = arg[0][0] # node ID should be based on the line number of line in the # otl file for easier debugging # for lineno, line in enumerate(open(fname)): # enumerate starts at 0 I want to start at 1 mapnode = et.Element('map') mapnode.set('version', '0.9.0') topnode = et.SubElement(mapnode, 'node') topnode.set('TEXT', fname) parents = [mapnode, topnode] # left_side = True # POSITION="right" # read otl file into memory filelines = codecs.open(fname, 'r', encoding='utf-8') # first handle the body texts turn it into a list of headings # with associated body text for each one this is because the # body text especially multi-line is what makes it awkward. headings = [] bodytexts = [] for line in filelines: if otl.is_heading(line): headings.append(line) bodytexts.append([]) else: # TODO this ': ' removal should go in otl.py? bodytexts[-1].append(line.lstrip()[2:] + '\n') oldheading = '' for heading, bodytext in zip(headings, bodytexts): if debug: print("%s\t%s" % (heading, bodytext)) level = otl.level(heading) oldlevel = otl.level(oldheading) if level == oldlevel: pass elif level > oldlevel: # about to go down in the hierarchy so add this line # as a parent to the stack # FIXME freemind.py|149| W802 undefined name 'node' parents.append(node) elif level < oldlevel: # about to go up in the hierarchy so remove parents from the stack leveldiff = oldlevel - level parents = parents[:-leveldiff] node = et.SubElement(parents[-1], 'node') node.set('TEXT', heading.lstrip().rstrip('\r\n')) attach_note(node, bodytext) oldheading = heading xmltree = et.ElementTree(mapnode) xmltree.write(sys.stdout, 'utf-8') print
def otl2mm(*arg, **kwarg): fname = arg[0][0] # node ID should be based on the line number of line in the # otl file for easier debugging #for lineno, line in enumerate(open(fname)): # enumerate starts at 0 I want to start at 1 # FIXME freemind.py|107| W806 local variable 'lineno' is assigned to but never used lineno = 0 mapnode = et.Element('map') mapnode.set('version', '0.9.0') topnode = et.SubElement(mapnode, 'node') topnode.set('TEXT', fname) parents = [mapnode, topnode] #left_side = True # POSITION="right" # read otl file into memory filelines = codecs.open(fname, 'r', encoding='utf-8') # first handle the body texts turn it into a list of headings # with associated body text for each one this is because the # body text especially multi-line is what makes it awkward. headings = [] bodytexts = [] for line in filelines: if otl.is_heading(line): headings.append(line) bodytexts.append([]) else: # TODO this ': ' removal should go in otl.py? bodytexts[-1].append(line.lstrip()[2:] + '\n') #import pdb; pdb.set_trace() oldheading = '' for heading, bodytext in zip(headings, bodytexts): if debug: print heading, bodytext level = otl.level(heading) oldlevel = otl.level(oldheading) if level == oldlevel: pass elif level > oldlevel: # about to go down in the hierarchy so add this line # as a parent to the stack # FIXME freemind.py|149| W802 undefined name 'node' parents.append(node) elif level < oldlevel: # about to go up in the hierarchy so remove parents from the stack leveldiff = oldlevel - level parents = parents[:-leveldiff] node = et.SubElement(parents[-1], 'node') node.set('TEXT', heading.lstrip().rstrip('\r\n')) #if len(bodytext) > 0: attach_note(node, bodytext) oldheading = heading xmltree = et.ElementTree(mapnode) xmltree.write(sys.stdout, 'utf-8') print
#left_side = True # POSITION="right" # read otl file into memory filelines = open(fname).readlines() # remove those that are too deep or body text and pesky end of line characters #filelines = [line.rstrip('\r\n') for line in filelines if otl.level(line) <= depth] #filelines = [line for line in filelines if otl.is_heading(line)] # first handle the body texts turn it into a list of headings with associated # body text for each one this is because the body text especially multi-line is # what makes it awkward. headings = [] bodytexts = [] for line in filelines: if otl.is_heading(line): headings.append(line) bodytexts.append([]) else: # TODO this ': ' removal should go in otl.py? bodytexts[-1].append(line.lstrip()[2:] + '\n') #import pdb; pdb.set_trace() oldheading = '' for heading, bodytext in zip(headings, bodytexts): if debug: print heading, bodytext level = otl.level(heading) oldlevel = otl.level(oldheading) if level == oldlevel: