Commits

windwiny  committed 4f1faa5

some fix and change:
change chdir order
leftd init
using utf-8 decode config file
config maxinum read 1M
db column type using varchar

  • Participants
  • Parent commits 848a706

Comments (0)

Files changed (1)

File mygrsyncframe.py

 import time
 import sqlite3
 import locale
+import re
 import wx
 import wx.stc
 
 
     db = sqlite3.connect(':memory:')
     cs = db.cursor()
-    cs.execute('''create table KV(l, r) ''')
-    cs.execute('''create table EXCLUDE(exclude) ''')
+    cs.execute('''create table KV(l varchar, r varchar) ''')
+    cs.execute('''create table EXCLUDE(exclude varchar) ''')
 
     @classmethod
     def initfromfile(cls, fn='config.txt'):
+        print '---------------- read config %s ----------------' % fn
         if fn == 'config.txt' and not os.path.exists(fn):
             open(fn, 'wb').write(open('config.template', 'rb').read())
         cls.cs.execute('''delete from KV''')
         cls.cs.execute('''delete from EXCLUDE''')
-        f = open(fn, 'r')
-        for line in f:
+        data = open(fn, 'rb').read(1024**2)
+        try:
+            data = data.decode('utf-8').encode(G.str_encode)
+            print 'config file encode is utf-8'
+        except UnicodeDecodeError:
+            print 'config file encode is %s' % G.str_encode
+            pass
+        for line in re.split('\n|\r', data):
             line = line.strip()
             if not line:
                 continue
                 continue
             l, r  = line[0].strip(), line[1].strip()
             cls.insert(l, r)
+        print '---------------- read config file end ----------------'
 
     @classmethod
     def insert(cls, l, r):
 
     def __init__(self, parent):
         self._init_ctrls(parent)
+        di = os.path.dirname(os.path.abspath(__file__))
+        if os.path.isfile(di):
+            di = os.path.dirname(di)
+        if os.path.isdir(di):
+            os.chdir(di)
+
         self.initctls()
-        self.init1()
+        self.initcfg()
 
     def initctls(self):
+        self.leftmd = False
         ff = wx.Font(9, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
         self.txtSRC.SetFont(ff)
         self.txtDST.SetFont(ff)
         self._logstc.AppendText(txt)
         self._logstc.GotoLine(self._logstc.GetLineCount())
 
-    def init1(self):
-        di = os.path.dirname(os.path.abspath(__file__))
-        if os.path.isfile(di):
-            di = os.path.dirname(di)
-        if os.path.isdir(di):
-            os.chdir(di)
+    def initcfg(self):
         G.initfromfile()
         if '-v' in sys.argv:
             G.showall()