Commits

Anonymous committed 78b7a0e

Debug tracing for fixing the encoding bug

  • Participants
  • Parent commits 09e1d90

Comments (0)

Files changed (3)

File src/hgapi.py

 # -*- coding: utf-8 -*-
-from __future__ import print_function, unicode_literals, with_statement
+from __future__ import print_function, with_statement
 from subprocess import Popen, STDOUT, PIPE
 try:
     from urllib import unquote
 except: #python 3
     from urllib.parse import unquote
 import re
+import platform
 import sys
 import os.path
 try:
 
     def hg_command(self, *args):
         """Run a hg command in path and return the result.
-        Throws on error."""    
-        proc = Popen(["hg", "--cwd", self.path, "--encoding", "UTF-8"] + list(args), stdout=PIPE, stderr=PIPE)
+        Throws on error."""
+        proc = Popen(["hg", "--cwd", self.path.encode(sys.getfilesystemencoding())] + list(args), stdout=PIPE, stderr=PIPE, shell=True)
 
-        out, err = [x.decode(sys.stdout.encoding) for x in  proc.communicate()]
+        if platform.system() == 'Windows':
+            out, err = [x.decode('cp1252') for x in  proc.communicate()]
+        else:
+            out, err = [x.decode(sys.stdout.encoding) for x in  proc.communicate()]
 
         if proc.returncode:
             cmd = (" ".join(["hg", "--cwd", self.path] + list(args)))

File src/hypergrasscore.py

-# -*- coding: <utf-8> -*-
+# -*- coding: utf-8 -*-
 #
 # hypergrass mercurial utility
 #
 	parser = OptionParser(usage='%prog [options]', description=desc, formatter=PlainHelpFormatter(), version="%prog "+HYGVERSION)
 	parser.add_option('-p', '--preview', 
 		action='store_true', dest='preview', default=False, 
-		help="shows what message would be committed, but does not commit")
+		help=u"shows what message would be committed, but does not commit".encode(sys.stdout.encoding))
 	parser.add_option('-c', '--comments',
 		action='store_true', dest='comments', default=False,
-		help="includes comments (\'## ...\') in the commit message")
+		help=u"includes comments (\'## ...\') in the commit message".encode(sys.stdout.encoding))
 
 	# get options from command line
 	(options, args) = parser.parse_args()
 
 	# build repo reference
-	repo = hgapi.Repo(os.path.abspath(os.curdir))
+	repo = hgapi.Repo(os.path.abspath(os.curdir.decode(sys.stdin.encoding)))
 	
 	# get rootfolder of repo and todo file name
-	rootfolder = os.path.abspath(os.curdir)
+	rootfolder = os.path.abspath(os.curdir.decode(sys.stdin.encoding))
+	print('1: '+rootfolder)
+	print(type(rootfolder))
 	if 'HG_PENDING' in os.environ:
 		rootfolder = os.environ['HG_PENDING']
+		print('2: '+rootfolder)
 	elif repo.config('bundle','mainreporoot'):
 		rootfolder = repo.config('bundle','mainreporoot')
+		print('3: '+rootfolder)
+		print(type(rootfolder))
 	else:
 		rootfolder = os.path.abspath(".")
 	todofilename = repo.config('hypergrass','todofile')
 	if not todofilename:
 		print('ERROR: todo filename not defined')
 		sys.exit(1)
+
+        print('stdin : '+sys.stdin.encoding)
+        print('stdout: '+sys.stdout.encoding)
+        print('default encoding: '+sys.getdefaultencoding())
+        #print('file sys encoding: '+sys.getfilesystemencoding())
+        #print(rootfolder)
+        #print(type(rootfolder))
+        #print(bytearray(rootfolder,'cp850'))
+        #print(rootfolder.encode('unicode_escape'))
+
+        fullpath = rootfolder + '/' + todofilename
+        print(fullpath)
+        print(type(rootfolder))
+        print(type(todofilename))
 	
 	# quit if todo file does not exist
 	if not os.path.exists(rootfolder+'/'+todofilename):
 		quit_and_normal_commit()
 
 	# get all done lines from the diff
-	diffoutput = repo.hg_command("diff","-U","999999999999",rootfolder+'/'+todofilename)
+	diffoutput = repo.hg_command("diff","-U","999999999999",rootfolder.encode(sys.getfilesystemencoding())+'/'+todofilename.encode(sys.getfilesystemencoding()))
 	log = []
 	#all_lines = diffoutput.splitlines()[4:]
 	for line in diffoutput.splitlines():

File src/win_runscripts/hypergrass.py

 # -*- coding: utf-8 -*-
 import sys
 import os.path
-sys.path.append(
-    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
+sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
 
 import hypergrasscore