Commit 1685b529 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

added taskinfo.properties handle

parent 90f5fb41
...@@ -28,6 +28,27 @@ def storetree(): ...@@ -28,6 +28,27 @@ def storetree():
with open('resources/strtree.pickle', 'wb') as handle: with open('resources/strtree.pickle', 'wb') as handle:
pickle.dump(sections, handle, protocol=pickle.HIGHEST_PROTOCOL) pickle.dump(sections, handle, protocol=pickle.HIGHEST_PROTOCOL)
def read_properties(filepath, sep='=', comment_char='#'):
props = {}
try:
with open(filepath, "rt") as f:
for line in f:
l = line.strip()
if l and not l.startswith(comment_char):
key_value = l.split(sep)
key = key_value[0].strip()
value = sep.join(key_value[1:]).strip().strip('"')
props[key] = value
except IOError:
return props
return props
def write_properties(filepath, props):
with open(filepath, "wt") as f:
for key, value in props.iteritems():
f.write(key+"="+value+"\n")
def run(): def run():
try: try:
strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle'))))) strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
...@@ -55,12 +76,17 @@ def run(): ...@@ -55,12 +76,17 @@ def run():
with open('output.json',"w") as outputfile: with open('output.json',"w") as outputfile:
json.dump(output, outputfile) json.dump(output, outputfile)
props = read_properties('taskinfo.properties')
if props.has_key("status"):
props['status'] = "COMPLETE"
write_properties('taskinfo.properties', props)
sys.exit(0) sys.exit(0)
except Exception as error: except Exception as error:
print_exc() print_exc()
sys.exit(1) sys.exit(1)
''' '''
To run in terminal call with python exercise.py To run in terminal call with python __init__.py
''' '''
if __name__ == "__main__": if __name__ == "__main__":
storetree() storetree()
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment