Commit 022090fdbcfc067c0054dc38dba6e4d35798a349
- Diff rendering mode:
- inline
- side by side
bin/gmail-sentinel.py
(48 / 5)
|   | |||
| 27 | 27 | """ | |
| 28 | 28 | ||
| 29 | 29 | import locale, gettext | |
| 30 | import os | ||
| 30 | import getopt, sys, os | ||
| 31 | 31 | import logging | |
| 32 | 32 | from os.path import dirname, pardir | |
| 33 | from gsentinel import GmailSentinel | ||
| 33 | #from gsentinel import GmailSentinel | ||
| 34 | 34 | from gettext import gettext as _ | |
| 35 | 35 | ||
| 36 | 36 | APP_NAME = "Gmail-Sentinel" | |
| … | … | ||
| 40 | 40 | APP_DESCRIPTION = _('GoogleMail Sentinel') | |
| 41 | 41 | APP_WEBSITE = 'http://code.google.com/p/gmail-sentinel/' | |
| 42 | 42 | ||
| 43 | def usage(): | ||
| 44 | print """%s version %s | ||
| 45 | Usage: %s [OPTION] | ||
| 46 | Check your email account periodically and notify you for incoming mail | ||
| 43 | 47 | ||
| 48 | Options: | ||
| 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 | |||
| 55 | Visit our website: %s""" % (APP_NAME, APP_VERSION, sys.argv[0], | ||
| 56 | APP_WEBSITE) | ||
| 57 | |||
| 44 | 58 | if __name__ == "__main__": | |
| 45 | 59 | # Path definition | |
| 46 | 60 | SHARE_PATH = os.path.abspath(os.path.join(dirname(__file__), | |
| … | … | ||
| 66 | 66 | gettext.textdomain('gmail-sentinel') | |
| 67 | 67 | gettext.bindtextdomain('gmail-sentinel', LOCALE_PATH) | |
| 68 | 68 | ||
| 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 | |||
| 69 | 98 | # Loggging configuration | |
| 70 | logging.basicConfig(level=logging.INFO, | ||
| 99 | logging.basicConfig(level=log_level, | ||
| 71 | 100 | format='%(asctime)s %(levelname)s %(message)s') | |
| 72 | 101 | ||
| 73 | 102 | # 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
Please log in to comment

