ports/117863: [patch]chinese/pyDict: Fix encode problem, adjust it can run in real console
Sunry Chen
sunrychen at gmail.com
Tue Nov 6 13:10:02 UTC 2007
>Number: 117863
>Category: ports
>Synopsis: [patch]chinese/pyDict: Fix encode problem, adjust it can run in real console
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Nov 06 13:10:00 UTC 2007
>Closed-Date:
>Last-Modified:
>Originator: Sunry Chen
>Release: FreeBSD 6.2-STABLE
>Organization:
Shenzhen Institute of Technology
>Environment:
FreeBSD www.525183.com 6.2-STABLE FreeBSD 6.2-STABLE #8: Tue Sep 18 23:01:05 CST
2007 hplc at www.525183.com:/usr/obj/usr/src/sys/MYKERNEL i386
>Description:
As I mentioned in ports/117388, http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/117388(As I submitted this PR, the ports/117388 can be closed):
Run pydict in console or in X window's xterm, it generates such error:
File "/usr/local/bin/pydict", line 332
SyntaxError: Non-ASCII character '\xa7' in file /usr/local/bin/pydict on line 33
2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for de
tails
This is caused by source encoding problem. After solving this problem, it runs ok in X, but in real console it says:
Traceback (most recent call last):
File "/usr/local/bin/pydict", line 326, in <module>
from gtk import *
File "/usr/local/lib/python2.5/site-packages/gtk-1.2/gtk.py", line 33, in <mod
ule>
_gtk.gtk_init()
RuntimeError: cannot open display
This is because in real console there's no DISPLAY, while the code in line 326 or some others want to initialize the DISPLAY.
>How-To-Repeat:
Fresh installed chinese/pyDict, run pydict in console, not in X Window's term!
>Fix:
1. Add source encoding big5 for python source.
2. Adjust python source code, add a judge statement not to import gtk or any other source which affecting running it in real console mode.
Patch attached with submission follows:
diff -ruN pyDict.orig/Makefile pyDict/Makefile
--- pyDict.orig/Makefile Tue Nov 6 18:26:52 2007
+++ pyDict/Makefile Tue Nov 6 19:57:58 2007
@@ -9,9 +9,12 @@
PORTVERSION= 0.2.6.3
PORTREVISION= 3
CATEGORIES= chinese
-MASTER_SITES= ftp://freebsd.sinica.edu.tw/pub/statue/pyDict/
+MASTER_SITES= ftp://freebsd.sinica.edu.tw/pub/statue/pyDict/ \
+ http://www.525183.com/freebsd/pyDict/ \
+ http://www.chinatinco.com/freebsd/pyDict/ \
+ http://525183.serverbox.org/freebsd/pyDict/
-MAINTAINER= ports at FreeBSD.org
+MAINTAINER= sunrychen at gmail.com
COMMENT= A Chinese <-> English dictionary, under both console and X11
RUN_DEPENDS= ${LOCALBASE}/include/pygtk/pygtk.h:${PORTSDIR}/x11-toolkits/py-gtk \
@@ -29,7 +32,7 @@
.include <bsd.port.pre.mk>
-do-patch:
+pre-patch:
${REINPLACE_CMD} -e 's,/bin/grep,${GREP},g' \
-e 's,--after-context=20,-A 20,g' \
-e 's,/usr/X11R6,${PREFIX},g' ${WRKSRC}/dict.py
diff -ruN pyDict.orig/files/patch-dict.py pyDict/files/patch-dict.py
--- pyDict.orig/files/patch-dict.py Thu Jan 1 08:00:00 1970
+++ pyDict/files/patch-dict.py Tue Nov 6 18:28:54 2007
@@ -0,0 +1,50 @@
+--- ./dict.py.orig Wed Oct 17 22:02:16 2007
++++ ./dict.py Tue Nov 6 18:28:47 2007
+@@ -1,4 +1,5 @@
+ #!/usr/bin/env python
++# -*- coding: big5 -*-
+ #-------------------------------------------------
+ # this is a program that utilize the library of xdict.
+ # Made by Daniel Gau <r90057 at im.ntu.edu.tw>
+@@ -322,16 +323,17 @@
+ """Get the word this object describes."""
+ return self.word
+
+-from gtk import *
+-from GDK import *
++prop = [" "," "," ","<<§Î®eµü>>","<<°Æµü>>","art. ","<<³s±µµü>>","int. ","<<¦Wµü>>"," "," ","num. ", "prep. "," ","pron. ","<<°Êµü>>","<<§U°Êµü>>","<<«D¤Îª«°Êµü>>","<<¤Îª«°Êµü>>","vbl. "," ","st. ", "pr. ","<<¹L¥h¤Àµü>>","<<½Æ¼Æ>>","ing. "," ","<<§Î®eµü>>","<<°Æµü>>","pla. ","pn. "," "]
++
+ from string import split,replace,strip,lstrip,find,lower
+-import GtkExtra
+ import sys,os,string
++if os.environ.has_key('DISPLAY') and len(sys.argv) == 1:
++ from gtk import *
++ from GDK import *
++ import GtkExtra
+
+
+-prop = [" "," "," ","<<§Î®eµü>>","<<°Æµü>>","art. ","<<³s±µµü>>","int. ","<<¦Wµü>>"," "," ","num. ", "prep. "," ","pron. ","<<°Êµü>>","<<§U°Êµü>>","<<«D¤Îª«°Êµü>>","<<¤Îª«°Êµü>>","vbl. "," ","st. ", "pr. ","<<¹L¥h¤Àµü>>","<<½Æ¼Æ>>","ing. "," ","<<§Î®eµü>>","<<°Æµü>>","pla. ","pn. "," "]
+-
+-class Pref(GtkDialog):
++ class Pref(GtkDialog):
+ def __init__(self,modal=TRUE,app=None):
+ GtkDialog.__init__(self)
+ self.connect("destroy", self.quit)
+@@ -482,7 +484,7 @@
+ def quit(self,w=None,event=None):
+ self.hide()
+
+-class HelpDialog(GtkDialog):
++ class HelpDialog(GtkDialog):
+ def __init__(self,modal=TRUE,file=None):
+ GtkDialog.__init__(self)
+ self.set_title("pyDict Help")
+@@ -542,7 +544,7 @@
+ self.quit()
+
+
+-class App(GtkWindow):
++ class App(GtkWindow):
+ def __init__(self):
+ GtkWindow.__init__(self,WINDOW_TOPLEVEL)
+ self.create_vars()
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list