Commit 022090fdbcfc067c0054dc38dba6e4d35798a349

Added initial support for command line options
bin/gmail-sentinel.py
(48 / 5)
  
2727"""
2828
2929import locale, gettext
30import os
30import getopt, sys, os
3131import logging
3232from os.path import dirname, pardir
33from gsentinel import GmailSentinel
33#from gsentinel import GmailSentinel
3434from gettext import gettext as _
3535
3636APP_NAME = "Gmail-Sentinel"
4040APP_DESCRIPTION = _('GoogleMail Sentinel')
4141APP_WEBSITE = 'http://code.google.com/p/gmail-sentinel/'
4242
43def usage():
44 print """%s version %s
45Usage: %s [OPTION]
46Check your email account periodically and notify you for incoming mail
4347
48Options:
49 -h, --help \t\t show this message
50 -v, --verbose \t show extra logging information
51 -c, --config=FILE\t load an alternative config file
52 -u, --username=USER use USER as username, overrides config file
53 -p, --password \t prompt for the password, overrides config file
54
55Visit our website: %s""" % (APP_NAME, APP_VERSION, sys.argv[0],
56 APP_WEBSITE)
57
4458if __name__ == "__main__":
4559 # Path definition
4660 SHARE_PATH = os.path.abspath(os.path.join(dirname(__file__),
6666 gettext.textdomain('gmail-sentinel')
6767 gettext.bindtextdomain('gmail-sentinel', LOCALE_PATH)
6868
69 # Parse command-line options
70 try:
71 opts, args = getopt.getopt(sys.argv[1:], "hvc:u:p",
72 ["help", "verbose", "config=",
73 "username=","password"])
74 except getopt.GetoptError, err:
75 print str(err)
76 usage()
77 sys.exit(2)
78
79 username, password = None, None
80 log_level = logging.WARNING
81 cfg_paths = [os.path.expanduser("~/.gmail-sentinel.conf")]
82 for o, a in opts:
83 if o in ("-h", "--help"):
84 usage()
85 sys.exit()
86 elif o in ("-v", "--verbose"):
87 log_level = logging.INFO
88 elif o in ("-c", "--config"):
89 cfg_paths.insert(0, a)
90 elif o in ("-u", "--username"):
91 username = a
92 elif o in ("-p", "--password"):
93 import getpass
94 password = getpass.getpass()
95 else:
96 assert False, _("unknown option")
97
6998 # Loggging configuration
70 logging.basicConfig(level=logging.INFO,
99 logging.basicConfig(level=log_level,
71100 format='%(asctime)s %(levelname)s %(message)s')
72101
73102 # app itself
74 notifier = GmailSentinel()
75 notifier.main()
103# notifier = GmailSentinel()
104# notifier.main()

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment