[27697] in Source-Commits
get_message commit: Include a main method for get_message
daemon@ATHENA.MIT.EDU (Alexander Chernyakhovsky)
Mon Feb 10 20:50:03 2014
Date: Mon, 10 Feb 2014 20:49:56 -0500
From: Alexander Chernyakhovsky <achernya@MIT.EDU>
Message-Id: <201402110149.s1B1nu4E001983@drugstore.mit.edu>
To: source-commits@MIT.EDU
https://github.com/mit-athena/get_message/commit/393f476d319b986d94392e6144985e635fd6c0b7
commit 393f476d319b986d94392e6144985e635fd6c0b7
Author: Ming Yang <mingy@mit.edu>
Date: Wed Sep 11 15:41:27 2013 -0400
Include a main method for get_message
gms.py | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/gms.py b/gms.py
index 9ff8e05..c468a0c 100644
--- a/gms.py
+++ b/gms.py
@@ -4,6 +4,7 @@ import hesiod
import select
import socket
import os
+from optparse import OptionParser
MESSAGE_VERS = 'GMS:0'
MESSAGE_SIZE = 2048
@@ -84,3 +85,22 @@ def get_message():
msg = read_message_from_cache()
return parse(msg)
+
+def main():
+ # Make flags
+ parser = OptionParser()
+ parser.add_option("-n", action="store_true", dest="new", default=False)
+ parser.add_option("-l", action="store_true", dest="login", default=False)
+ (options, args) = parser.parse_args()
+ msg = get_message()
+ # Check flags
+ if options.login and not has_seen(msg[1]):
+ # If the user has not seen the message, return the message. However, cannot assume user will see this message so don't write times.
+ print msg[2]
+ elif options.new and not has_seen(msg[1]) or (not options.login and not options.new):
+ # If the user has not seen the message, write message times and return the message
+ write_message_times(msg[1])
+ print msg[2]
+
+if __name__ == "__main__":
+ main()