comparison multimerge.py @ 134:afdef805e9b7

Merge Python 3 branch.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 15 Sep 2020 23:39:49 +0300
parents 3a3958edc813 76e49e34b40a
children d3135eff1bab
comparison
equal deleted inserted replaced
133:3a3958edc813 134:afdef805e9b7
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-2017 Tecnic Software productions (TNSP) 6 ### (C) Copyright 2016-2020 Tecnic Software productions (TNSP)
7 ### 7 ###
8 ### For license information, see file "COPYING". 8 ### For license information, see file "COPYING".
9 ### 9 ###
10 ### Python 2.7 <= x < 3 required! Please refer to 10 ### Python 3.7 required! Please refer to
11 ### README.txt for information on other depencies. 11 ### README.txt for information on other depencies.
12 ### 12 ###
13 import os 13 import os
14 import sys 14 import sys
15 import signal 15 import signal
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
32 from googleapiclient import discovery 32 from googleapiclient import discovery
33
34
35 assert sys.version_info >= (3, 7)
33 36
34 37
35 ### 38 ###
36 ### Misc. helper functions, etc 39 ### Misc. helper functions, etc
37 ### 40 ###
60 ## Wrapper for print() that does not break when redirecting stdin/out 63 ## Wrapper for print() that does not break when redirecting stdin/out
61 ## because of piped output not having a defined encoding. We default 64 ## because of piped output not having a defined encoding. We default
62 ## to UTF-8 encoding in output here. 65 ## to UTF-8 encoding in output here.
63 def gcm_print(smsg): 66 def gcm_print(smsg):
64 gcm_msgbuf.append(smsg) 67 gcm_msgbuf.append(smsg)
65 if sys.stdout.encoding != None: 68 print("{0} | {1}".format(gcm_timestamp(time.localtime()), smsg))
66 rsmsg = smsg.encode(sys.stdout.encoding)
67 else:
68 rsmsg = smsg.encode("UTF-8")
69
70 print("{0} | {1}".format(gcm_timestamp(time.localtime()), rsmsg))
71 69
72 70
73 ## Fatal error handler 71 ## Fatal error handler
74 def gcm_fatal(smsg): 72 def gcm_fatal(smsg):
75 gcm_print(u"ERROR: "+ smsg) 73 gcm_print(u"ERROR: "+ smsg)
211 ### 209 ###
212 class GCMColor(): 210 class GCMColor():
213 def __init__(self, src = None): 211 def __init__(self, src = None):
214 if src == None: 212 if src == None:
215 self.r = self.g = self.b = 0 213 self.r = self.g = self.b = 0
216 elif isinstance(src, basestring): 214 elif isinstance(src, str):
217 if len(src) == 6: 215 if len(src) == 6:
218 self.r = int(src[0:2], 16) 216 self.r = int(src[0:2], 16)
219 self.g = int(src[2:4], 16) 217 self.g = int(src[2:4], 16)
220 self.b = int(src[4:6], 16) 218 self.b = int(src[4:6], 16)
221 elif len(src) == 7 and src[0] == "#": 219 elif len(src) == 7 and src[0] == "#":
254 c_bg = GCMColor(cfind["background"]) 252 c_bg = GCMColor(cfind["background"])
255 253
256 bdist_fg = 99999999999 254 bdist_fg = 99999999999
257 bdist_bg = 99999999999 255 bdist_bg = 99999999999
258 best_fit = None 256 best_fit = None
259 for id, col in colors.iteritems(): 257 for id, col in colors.items():
260 dist_fg = GCMColor(col["foreground"]).dist(c_fg) 258 dist_fg = GCMColor(col["foreground"]).dist(c_fg)
261 dist_bg = GCMColor(col["background"]).dist(c_bg) 259 dist_bg = GCMColor(col["background"]).dist(c_bg)
262 if dist_fg <= bdist_fg and dist_bg <= bdist_bg: 260 if dist_fg <= bdist_fg and dist_bg <= bdist_bg:
263 best_fit = id 261 best_fit = id
264 bdist_fg = dist_fg 262 bdist_fg = dist_fg
323 value = cfg_parser.get(sect, name) 321 value = cfg_parser.get(sect, name)
324 self.mset(name, value) 322 self.mset(name, value)
325 gcm_debug(4, u"{0} -> '{1}' == {2}".format(name, value, self.mget(name))) 323 gcm_debug(4, u"{0} -> '{1}' == {2}".format(name, value, self.mget(name)))
326 324
327 def is_str(self, mvalue): 325 def is_str(self, mvalue):
328 return isinstance(mvalue, basestring) 326 return isinstance(mvalue, str)
329 327
330 def is_string(self, mvalue): 328 def is_string(self, mvalue):
331 return mvalue == None or self.is_str(mvalue) 329 return mvalue == None or self.is_str(mvalue)
332 330
333 def is_log_level(self, mvalue): 331 def is_log_level(self, mvalue):