Commits

windwiny committed 386be3b

add set syntax in config file
change global config class G

Comments (0)

Files changed (2)

 import wx
 import wx.stc
 
-class G:
-    str_encode = locale.getdefaultlocale()[1]
-
-    if sys.platform == 'win32':
-        startupinfo = subprocess.STARTUPINFO()
-        if sys.version.startswith('2.7') or sys.version.startswith('2.6'):
-            nn = subprocess._subprocess
-        else :
-            nn = subprocess
-        startupinfo.dwFlags |= nn.STARTF_USESHOWWINDOW
-        startupinfo.wShowWindow = nn.SW_HIDE
-    else:
-        startupinfo = None
-
 def create(parent):
     return grsyncdlg(parent)
 
                 self.sp.remove(sp)
 
     def create_subproc_logthread(self, cmd):
-        sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                              shell=True, startupinfo=G.startupinfo)
+        sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE,
+                              startupinfo=G.startupinfo)
         self.sp.append(sp)
 
         def thpg(sp, self):
                 self.stcSyncLog.GotoLine(self.stcSyncLog.GetLineCount())
 
     def getcmd(self):
-        cmds = ['rsync']
+        cmds = [G._pg_RSYNC]
         if self.chk__dry_run.GetValue(): cmds.append('-n')
         if self.chk_v.GetValue(): cmds.append('-v')
         if self.chk_z.GetValue(): cmds.append('-z')
     def OnBtnHelpButton(self, event):
         event.Skip()
         if not hasattr(self, '_rsyncdoc'):
-            sp = subprocess.Popen('rsync --help -v', stdout=subprocess.PIPE,
-                                  shell=True, startupinfo=G.startupinfo)
+            sp = subprocess.Popen('%s --help -v' % G._pg_RSYNC, shell=True,
+                                  stdout=subprocess.PIPE,
+                                  startupinfo=G.startupinfo)
             self._rsyncdoc = sp.stdout.read().decode(G.str_encode)
             self._dlg = wx.Dialog(self, title=u"rsync --help", size=wx.Size(640,480),
                                   style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
 
 class G:
     str_encode = locale.getdefaultlocale()[1]
+    _pg_RSYNC = 'rsync'
+    _pg_GUIDIFF = 'bc2'
+
+    if sys.platform == 'win32':
+        startupinfo = subprocess.STARTUPINFO()
+        if sys.version.startswith('2.7') or sys.version.startswith('2.6'):
+            nn = subprocess._subprocess
+        else :
+            nn = subprocess
+        startupinfo.dwFlags |= nn.STARTF_USESHOWWINDOW
+        startupinfo.wShowWindow = nn.SW_HIDE
+    else:
+        startupinfo = None
+
     db = sqlite3.connect(':memory:')
     cs = db.cursor()
     cs.execute('''create table KV(l, r) ''')
             line = line.strip()
             if not line:
                 continue
-            if line[0] == '#':
+            if line[0] == '#':  # comment
+                continue
+            elif line[0] == ';':# add path and set program name
+                kv = line[1:].split('=')
+                if len(kv) == 2:
+                    k, v = kv[0].strip().upper(), kv[1].strip()
+                    if k and v:
+                        if k == 'PATH':
+                            if v not in os.environ['PATH']:
+                                os.environ['PATH'] = v + os.pathsep + os.environ['PATH']
+                                print ' add path %s' % v
+                        else:
+                            setattr(G, '_pg_%s' % k, v)
+                            print ' set %s = %s' % (k, v)
                 continue
             line = line.split('->')
             if len(line) != 2:
             return
         if not G.cygpath(l, False): return
         if not G.cygpath(r, False): return
-        os.environ['PATH'] = r"d:\Program Files\Beyond Compare 2;" + os.environ['PATH']
         if '-d' in sys.argv:
-            print 'bc2 "%s" "%s"' % (l, r)
+            print '%s "%s" "%s"' % (G._pg_GUIDIFF, l, r)
         else:
-            subprocess.Popen('bc2 "%s" "%s"' % (l, r))
+            subprocess.Popen('%s "%s" "%s"' % (G._pg_GUIDIFF, l, r))
     
     @staticmethod 
     def runsync(l, r, parent=None):
-        os.environ['PATH'] = r"f:\ux\grsync\bin;" + os.environ['PATH']
-        
         lu = G.cygpath(l)
         ru = G.cygpath(r)
         if not lu or not ru:
             return
         import mygrsyncdlg
+        mygrsyncdlg.G = G
         dlg = mygrsyncdlg.grsyncdlg(parent)
         dlg.SetTitle(dlg.GetTitle() + ' ' + l)
         dlg.txtSRC.SetValue(lu)