comparison multimerge.py @ 125:76e49e34b40a python3

Changes required for Python 3.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 07 Nov 2016 09:15:50 +0200
parents 977ecff4bd7d
children afdef805e9b7
comparison
equal deleted inserted replaced
124:977ecff4bd7d 125:76e49e34b40a
1 #!/usr/bin/python 1 #!/usr/bin/python3
2 # coding=utf-8 2 # coding=utf-8
3 ### 3 ###
4 ### Google Calendar MultiMerge 4 ### Google Calendar MultiMerge
5 ### Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> 5 ### Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
6 ### (C) Copyright 2016 Tecnic Software productions (TNSP) 6 ### (C) Copyright 2016 Tecnic Software productions (TNSP)
21 21
22 import smtplib 22 import smtplib
23 from email.mime.text import MIMEText 23 from email.mime.text import MIMEText
24 24
25 import httplib2 25 import httplib2
26 import ConfigParser 26 import configparser as ConfigParser
27 27
28 import oauth2client 28 import oauth2client
29 from oauth2client import client 29 from oauth2client import client
30 from oauth2client import tools 30 from oauth2client import tools
31 from oauth2client import file 31 from oauth2client import file
53 ## Wrapper for print() that does not break when redirecting stdin/out 53 ## Wrapper for print() that does not break when redirecting stdin/out
54 ## because of piped output not having a defined encoding. We default 54 ## because of piped output not having a defined encoding. We default
55 ## to UTF-8 encoding in output here. 55 ## to UTF-8 encoding in output here.
56 def gcm_print(smsg): 56 def gcm_print(smsg):
57 gcm_msgbuf.append(smsg) 57 gcm_msgbuf.append(smsg)
58 if sys.stdout.encoding != None: 58 print(smsg)
59 print(smsg.encode(sys.stdout.encoding))
60 else:
61 print(smsg.encode("UTF-8"))
62 59
63 60
64 ## Fatal error handler 61 ## Fatal error handler
65 def gcm_fatal(smsg): 62 def gcm_fatal(smsg):
66 gcm_print(u"ERROR: "+ smsg) 63 gcm_print(u"ERROR: "+ smsg)
200 ### 197 ###
201 class GCMColor(): 198 class GCMColor():
202 def __init__(self, src = None): 199 def __init__(self, src = None):
203 if src == None: 200 if src == None:
204 self.r = self.g = self.b = 0 201 self.r = self.g = self.b = 0
205 elif isinstance(src, basestring): 202 elif isinstance(src, str):
206 if len(src) == 6: 203 if len(src) == 6:
207 self.r = int(src[0:2], 16) 204 self.r = int(src[0:2], 16)
208 self.g = int(src[2:4], 16) 205 self.g = int(src[2:4], 16)
209 self.b = int(src[4:6], 16) 206 self.b = int(src[4:6], 16)
210 elif len(src) == 7 and src[0] == "#": 207 elif len(src) == 7 and src[0] == "#":
243 c_bg = GCMColor(cfind["background"]) 240 c_bg = GCMColor(cfind["background"])
244 241
245 bdist_fg = 99999999999 242 bdist_fg = 99999999999
246 bdist_bg = 99999999999 243 bdist_bg = 99999999999
247 best_fit = None 244 best_fit = None
248 for id, col in colors.iteritems(): 245 for id, col in colors.items():
249 dist_fg = GCMColor(col["foreground"]).dist(c_fg) 246 dist_fg = GCMColor(col["foreground"]).dist(c_fg)
250 dist_bg = GCMColor(col["background"]).dist(c_bg) 247 dist_bg = GCMColor(col["background"]).dist(c_bg)
251 if dist_fg <= bdist_fg and dist_bg <= bdist_bg: 248 if dist_fg <= bdist_fg and dist_bg <= bdist_bg:
252 best_fit = id 249 best_fit = id
253 bdist_fg = dist_fg 250 bdist_fg = dist_fg
312 value = cfg_parser.get(sect, name) 309 value = cfg_parser.get(sect, name)
313 self.mset(name, value) 310 self.mset(name, value)
314 gcm_debug(4, u"{0} -> '{1}' == {2}".format(name, value, self.mget(name))) 311 gcm_debug(4, u"{0} -> '{1}' == {2}".format(name, value, self.mget(name)))
315 312
316 def is_str(self, mvalue): 313 def is_str(self, mvalue):
317 return isinstance(mvalue, basestring) 314 return isinstance(mvalue, str)
318 315
319 def is_string(self, mvalue): 316 def is_string(self, mvalue):
320 return mvalue == None or self.is_str(mvalue) 317 return mvalue == None or self.is_str(mvalue)
321 318
322 def is_log_level(self, mvalue): 319 def is_log_level(self, mvalue):