6 |
|
# $Id$ |
7 |
|
|
8 |
|
from ConfigParser import NoOptionError, SafeConfigParser |
9 |
+ |
import gdata.calendar.service |
10 |
|
import getpass |
11 |
+ |
import imaplib |
12 |
|
import keyring |
13 |
|
import optparse |
14 |
|
import os |
15 |
|
import sys |
14 |
– |
import warnings |
16 |
|
|
17 |
< |
with warnings.catch_warnings(): |
17 |
< |
warnings.filterwarnings('ignore', r'the sha module is deprecated', DeprecationWarning) |
18 |
< |
|
19 |
< |
import gdata.calendar.service |
20 |
< |
|
21 |
< |
MODULES = frozenset(('creditcards', 'facebook', 'wesabe')) |
22 |
< |
NOT_BANKS = MODULES | frozenset(('google',)) |
23 |
< |
|
24 |
< |
class Bank(object): |
25 |
< |
def __init__(self, module, config, debug): |
26 |
< |
self.module = module |
27 |
< |
self.bank = None |
28 |
< |
self.config = config |
29 |
< |
self.debug = debug |
30 |
< |
|
31 |
< |
def __call__(self): |
32 |
< |
if self.bank is None: |
33 |
< |
exec 'import %s' % self.module |
34 |
< |
exec "self.bank = %s.Bank(Config(self.config, self.module), self.debug)" % self.module |
35 |
< |
|
36 |
< |
return self.bank |
37 |
< |
|
38 |
< |
class Banks(object): |
39 |
< |
def __init__(self, config, debug): |
40 |
< |
self.banks = {} |
41 |
< |
self.config = config |
42 |
< |
self.debug = debug |
43 |
< |
|
44 |
< |
def bank(self, module): |
45 |
< |
if module not in NOT_BANKS: |
46 |
< |
return self.banks.setdefault(module, Bank(module, self.config, self.debug))() |
17 |
> |
MODULES = frozenset(('creditcards', 'facebook')) |
18 |
|
|
19 |
|
class Config(object): |
20 |
|
def __init__(self, config, module): |
80 |
|
|
81 |
|
config.read([os.path.expanduser('~/.reminder')]) |
82 |
|
|
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 |
– |
|
83 |
|
if options.dbus: |
84 |
|
dbus = os.environ['DBUS_SESSION_BUS_ADDRESS'] |
85 |
|
|
94 |
|
with open(os.path.expanduser('~/.reminder.dbus'), 'rb') as file: |
95 |
|
os.environ['DBUS_SESSION_BUS_ADDRESS'] = file.readline().rstrip() |
96 |
|
|
97 |
+ |
if options.passwords: |
98 |
+ |
for section in options.passwords: |
99 |
+ |
try: |
100 |
+ |
username = config.getusername(section) |
101 |
+ |
password = getpass.getpass('%s password for %s: ' % (section, username)) |
102 |
+ |
|
103 |
+ |
keyring.set_password('reminder_%s' % section, username, password) |
104 |
+ |
except NoOptionError: |
105 |
+ |
pass |
106 |
+ |
|
107 |
+ |
sys.exit(0) |
108 |
+ |
|
109 |
|
if not options.all and not options.modules: |
110 |
|
parser.error('-A or -m not specified') |
111 |
|
|
116 |
|
|
117 |
|
calendar.ProgrammaticLogin() |
118 |
|
|
119 |
< |
banks = Banks(config, options.debug) |
119 |
> |
if options.debug: |
120 |
> |
imaplib.Debug = 4 |
121 |
> |
|
122 |
> |
imap = imaplib.IMAP4_SSL(config.get('imap', 'server')) |
123 |
> |
|
124 |
> |
imap.login(config.getusername('imap'), config.getpassword('imap')) |
125 |
|
|
126 |
|
for module in options.modules if not options.all else sorted(MODULES): |
127 |
|
exec 'import %s' % module |
128 |
< |
exec '%s.main(%s)' % (module, ', '.join(['calendar', 'Config(config, module)'] + (['banks', 'options.debug'] if module in ('creditcards', 'wesabe') else ['options.debug']))) |
128 |
> |
exec '%s.main(calendar, imap, Config(config, module), options.debug)' % module |
129 |
> |
|
130 |
> |
imap.logout() |