1. Andre Staltz
  2. hypergrass

Commits

STALTZ  committed e2c7123

"FIXBUG windows python scripts are not understanding unicode (e.g., hgapi uses UTF8)"

  • Participants
  • Parent commits 2d77302
  • Branches default

Comments (0)

Files changed (5)

File TODO

View file
 + DONE IMPROVE Vim highlighter makes the tag line all colored
 + DONE minor improvement to formatting of generated commit message
 + DONE IMPROVE support for quotes in the commit message (but no double quotes)
-- TODO FIXBUG windows python scripts are not understanding unicode (e.g., hgapi uses UTF8)
++ DONE FIXBUG windows python scripts are not understanding unicode (e.g., hgapi uses UTF8)
 - TODO NEW installation NSIS for windows
 - TODO NEW installation for linux
 - NEW wiki page at bitbucket

File src/hgapi.py

View file
 except: #python 3
     from urllib.parse import unquote
 import re
+import sys
 import os.path
 try:
     import json #for reading logs
         Throws on error."""    
         proc = Popen(["hg", "--cwd", self.path, "--encoding", "UTF-8"] + list(args), stdout=PIPE, stderr=PIPE)
 
-        out, err = [x.decode("utf-8") for x in  proc.communicate()]
+        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

View file
-# -*- coding: utf-8 -*-
+# -*- coding: <utf-8> -*-
 #
 # hypergrass mercurial utility
 #
 # Copyright (c) 2012 by Andre Medeiros.
-
+from __future__ import unicode_literals
 import re
 import optparse
 from optparse import OptionParser
 import subprocess
 
 _bullet_re = re.compile(r'\s*[-+*]\s+')
-_done_re = re.compile('\+[ \t]*\+ *DONE')
+_done_re = re.compile(r'\+[ \t]*\+ *DONE')
 
 class PlainHelpFormatter(optparse.IndentedHelpFormatter): 
 	def format_description(self, description):
 		if description:
-			return description + "\n"
+			return description + '\n'
 		else:
-			return ""
+			return ''
 
 def quit_and_normal_commit():
-	subprocess.call(["hg commit"], shell=True)
+	subprocess.call(['hg commit'], shell=True)
 	sys.exit(0)
 
 def normalize_log(lines):
 	return '; '.join(lines)
 
 def ignore_comments(line):
-	"""Anything after \'###\' in a line is considered a comment, will not show in the commit message"""
+	"""Anything after \'##\' in a line is considered a comment, will not show in the commit message"""
 	poscomment = line.find('##')
 	if poscomment >= 0:
 		return line[0:poscomment]
 starting with '+ DONE', those tasks will be the commit message. If there is
 no task marked with '+ DONE', 'hyg' behaves just like 'hg commit'.
 """
-	parser = OptionParser(usage="%prog [options]", description=desc, formatter=PlainHelpFormatter()) #, version="%prog 0.1")
-	parser.add_option("-p", "--preview", 
-		action="store_true", dest="preview", default=False, 
+	parser = OptionParser(usage='%prog [options]', description=desc, formatter=PlainHelpFormatter()) #, version="%prog 0.1")
+	parser.add_option('-p', '--preview', 
+		action='store_true', dest='preview', default=False, 
 		help="shows what message would be committed, but does not commit")
-	parser.add_option("-c", "--comments",
-		action="store_true", dest="comments", default=False,
+	parser.add_option('-c', '--comments',
+		action='store_true', dest='comments', default=False,
 		help="includes comments (\'## ...\') in the commit message")
 
 	# get options from command line
 	todofilename = repo.config('hypergrass','todofile')
 
 	if not todofilename:
-		print 'ERROR: todo filename not defined'
+		print('ERROR: todo filename not defined')
 		sys.exit(1)
 	
 	# quit if todo file does not exist
 	if not os.path.exists(rootfolder+'/'+todofilename):
-		print 'ERROR: todo file not found'
+		print('ERROR: todo file not found')
 		sys.exit(1)
 
 	# discover what files were modified
 	if todofilename not in files_modified:
 		# preview and exit
 		if options.preview:
-			print '-- Nothing from ' + todofilename + ' --'
+			print('-- Nothing from ' + todofilename + ' --')
 			return
 		quit_and_normal_commit()
 
 
 	# show done lines
 	for line in log:
-		print line
+		print(line)
 
 	# preview and exit
 	if options.preview:
 		if not log:
-			print '-- Nothing from ' + todofilename + ' --'
+			print('-- Nothing from ' + todofilename + ' --')
 		return
 
 	# do the final commit, if there was a message extracted from the todo file
 	if not log:
 		quit_and_normal_commit()
 	else:
-		subprocess.call(["hg commit --message \""+log+"\""], shell=True)
+		subprocess.Popen(['hg','commit','--message',"\""+log+"\""], shell=True)
 		sys.exit(0)
 
 if __name__ == '__main__':

File src/win_runscripts/hyg.py

View file
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
 import sys
-reload(sys)
-sys.setdefaultencoding("utf-8")
+#reload(sys)
+#sys.setdefaultencoding("utf-8")
 import os.path
 sys.path.append(
     os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))

File src/win_runscripts/hypergrass.py

View file
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
 import sys
-reload(sys)
-sys.setdefaultencoding("utf-8")
+#reload(sys)
+#sys.setdefaultencoding("utf-8")
 import os.path
 sys.path.append(
     os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))