ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Reminder/reminder.py
(Generate patch)

Comparing FreeBSDAdmin/Reminder/reminder.py (file contents):
Revision 1179 by douglas, 2009-05-19T16:53:29-07:00 vs.
Revision 1229 by douglas, 2009-10-03T22:58:25-07:00

# Line 5 | Line 5
5   #
6   # $Id$
7  
8 < import base64
9 < from ConfigParser import SafeConfigParser
8 > from ConfigParser import NoOptionError, SafeConfigParser
9 > import getpass
10 > import keyring
11   import optparse
12 < import os.path
12 > import os
13 > import sys
14   import warnings
15  
16   with warnings.catch_warnings():
# Line 63 | Line 65 | class Config(object):
65          def getlist(self, *args, **kwargs):
66                  return self.config.getlist(self.module, *args, **kwargs)
67  
68 <        def getpassword(self, *args, **kwargs):
69 <                return self.config.getpassword(self.module, *args, **kwargs)
68 >        def getpassword(self):
69 >                return self.config.getpassword(self.module)
70 >
71 >        def getusername(self):
72 >                return self.config.getusername(self.module)
73  
74   class ConfigParser(SafeConfigParser):
75          def __init__(self, *args, **kwargs):
# Line 73 | Line 78 | class ConfigParser(SafeConfigParser):
78          def getlist(self, *args, **kwargs):
79                  return self.get(*args, **kwargs).split(',')
80  
81 <        def getpassword(self, *args, **kwargs):
82 <                return base64.b64decode(self.get(*args, **kwargs).decode('rot13'))
81 >        def getpassword(self, section):
82 >                return keyring.get_password('reminder_%s' % section, self.getusername(section))
83 >
84 >        def getusername(self, section):
85 >                return self.get(section, 'username')
86  
87   class OptionParser(optparse.OptionParser):
88          def __init__(self, *args, **kwargs):
89                  optparse.OptionParser.__init__(self, *args, **kwargs)
90                  self.add_option('-A', '--all', action = 'store_true', dest = 'all')
91 +                self.add_option('-d', '--dbus', action = 'store_true', dest = 'dbus')
92                  self.add_option('-m', '--module', action = 'callback', callback = self.__module, dest = 'modules', type = 'string')
93 +                self.add_option('-p', '--password', action = 'callback', callback = self.__password, dest = 'passwords', type = 'string')
94                  self.add_option('-D', '--debug', action = 'store_true', dest = 'debug')
95  
96          def __module(self, option, opt_str, value, parser):
# Line 89 | Line 99 | class OptionParser(optparse.OptionParser
99  
100                  parser.values.ensure_value(option.dest, []).append(value)
101  
102 +        def __password(self, option, opt_str, value, parser):
103 +                parser.values.ensure_value(option.dest, []).append(value)
104 +
105   if __name__ == '__main__':
106          parser = OptionParser()
107          options = parser.parse_args()[0]
95
96        if not options.all and not options.modules:
97                parser.error('-A or -m not specified')
98
108          config = ConfigParser()
109  
110          config.read([os.path.expanduser('~/.reminder')])
111  
112 +        if options.passwords:
113 +                for section in options.passwords:
114 +                        try:
115 +                                username = config.getusername(section)
116 +                                password = getpass.getpass('%s password for %s: ' % (section, username))
117 +
118 +                                keyring.set_password('reminder_%s' % section, username, password)
119 +                        except NoOptionError:
120 +                                pass
121 +
122 +                sys.exit(0)
123 +
124 +        if options.dbus:
125 +                dbus = os.environ['DBUS_SESSION_BUS_ADDRESS']
126 +
127 +                with open(os.path.expanduser('~/.reminder.dbus'), 'wb') as file:
128 +                        file.write(dbus + '\n')
129 +
130 +                sys.exit(0)
131 +
132 +        try:
133 +                os.environ['DBUS_SESSION_BUS_ADDRESS']
134 +        except KeyError:
135 +                with open(os.path.expanduser('~/.reminder.dbus'), 'rb') as file:
136 +                        os.environ['DBUS_SESSION_BUS_ADDRESS'] = file.readline().rstrip()
137 +
138 +        if not options.all and not options.modules:
139 +                parser.error('-A or -m not specified')
140 +
141          calendar = gdata.calendar.service.CalendarService()
142 <        calendar.email = config.get('google', 'username')
143 <        calendar.password = config.getpassword('google', 'password')
142 >        calendar.email = config.getusername('google')
143 >        calendar.password = config.getpassword('google')
144          calendar.source = 'Reminder-0.9'
145  
146          calendar.ProgrammaticLogin()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines