-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtm_sync.py
More file actions
96 lines (83 loc) · 2.92 KB
/
rtm_sync.py
File metadata and controls
96 lines (83 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
# Copyright (c) 2009 - Luca Invernizzi <invernizzi.l@gmail.com>
# - Paulo Cabido <paulo.cabido@gmail.com> (example file)
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#import os
#from threading import Thread
from syncEngine import SyncEngine
#import glob
import logging
import logging.handlers
LOG_FILENAME = 'rtm.log'
class RtmSync:
#worker_thread = None
sync_engine = None
status = None
def __init__(self, logger=None):
self.logger = logger
self.activate()
self.checkLogin(logger)
def activate(self):
self.sync_engine = SyncEngine(self, self.logger)
def lauchSynchronization(self):
self.logger.info("Synchronization started \n")
self.sync_engine.synchronize()
def checkLogin(self, firstime = True):
self.firstime = firstime
self.logger.info("Trying to access, please stand by...")
try:
self.sync_engine.rtmLogin()
except:
pass
if self.sync_engine.rtmLogin():
self.loginHasFailed()
else:
self.checkHasLogon()
def loginHasFailed(self):
self.logger.info("Couldn't connect to Remember The Milk \n")
def checkLoginThread(self):
try:
self.sync_engine.rtmLogin()
except:
pass
def checkHasLogon(self):
login = self.sync_engine.rtmHasLogon()
if login == False:
if not self.firstime:
self.logger.info("Authentication failed. Please retry. \n")
else:
self.logger.info("Please authenticate to Remember \
The Milk in the browser that is being opened now. \
When done, press OK")
else:
self.lauchSynchronization()
def onTaskOpened(self, plugin_api):
pass
def main():
"""init logging system, start rtmsync"""
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
fh = logging.FileHandler(LOG_FILENAME)
fh.setLevel(logging.INFO)
#ch = logging.StreamHandler()
#ch.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(module)s:%(funcName)s:%(lineno)d - %(message)s")
fh.setFormatter(formatter)
#ch.setFormatter(formatter)
logger.addHandler(fh)
#logger.addHandler(ch)
r = RtmSync(logger=logger)
if __name__ == "__main__":
main()