Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New method allows reading from string in addition to files.

Added a new method: OrgDataStructure.load_from_string(string)
      Similar to load_from_file except accepts a string as input. The string should be the contents of an org-mode file (complete with '\n') that is then passed to load_from_file and treated normally. This allows org-mode information to be saved in a database or other non-file storage.
  • Loading branch information...
commit b30328859f07186ee9a1bc79f1d7ae24e879732c 1 parent 59e1877
@m3wolf authored
Showing with 15 additions and 5 deletions.
  1. +15 −5 PyOrgMode.py
View
20 PyOrgMode.py
@@ -580,15 +580,20 @@ def add_todo_state(self, new_state):
for plugin in self.plugins:
if plugin.__class__ == OrgNode:
plugin.todo_list.append(new_state)
- def load_from_file(self,name):
+ def load_from_file(self,name,form="file"):
"""
Used to load an org-file inside this DataStructure
"""
current = self.root
- file = open(name,'r')
+ # Determine content type and put in appropriate form
+ if form == "file":
+ content = open(name,'r')
+ elif form == "string":
+ content = name.split("\n")
+ else:
+ raise ValueError
- for line in file:
-
+ for line in content:
for plugin in self.plugins:
current = plugin.treat(current,line)
if plugin.treated: # Plugin found something
@@ -601,7 +606,12 @@ def load_from_file(self,name):
for plugin in self.plugins:
current = plugin.close(current)
- file.close()
+
+ def load_from_string(self, string):
+ """
+ A wrapper calling load_from_file but with a string instead of reading from a file.
+ """
+ self.load_from_file(string, "string")
def save_to_file(self,name,node=None):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.