2012년 10월 19일 금요일

Trac wikiprint 한글글꼴 설정.

아래 링크를 참조하여 한글이 포함된 trac 페이지도 wikiprint 로 PDF 문서를 잘 생성해서 쓰고 있었는데 어느때인가? ubuntu 를 업그레이드하면서 한글이 깨지기 시작했다.
http://kldp.org/node/109178

오늘 ubuntu 12.10 으로 업그레이드하면서 다시 확인해봤는데 역시나~~
이것저것 삽질하다 보니 짜안 한글이 TT_TT..
/usr/share/pyshared/wikipiprint/defaults.py 를 아래와 같이 수정.
  • 원본..
"""
Author: Alvaro Iradier
"""

#Default CSS to use for xhtml2pdf
CSS = """
html {
    font-family: Helvetica;
    font-size: 10px;
    font-weight: normal;
    color: #000000;
    background-color: transparent;
  • 수정본
"""
Author: Alvaro Iradier
"""

#Default CSS to use for xhtml2pdf
CSS = """
@font-face {
    font-family: NanumGothic;
    src: url(file:///usr/share/fonts/truetype/nanum/NanumGothic.ttf);
    }
html {
    font-family: NanumGothic;
    font-size: 10px;
    font-weight: normal;
    color: #000000;
    background-color: transparent;

2012년 10월 18일 목요일

리눅스배포판 정보 얻기

$ lsb_release -rd
Description:    Ubuntu 12.10
Release:    12.10

파이썬에서 r"\x30" 디코딩하기.


>>> r"\x30".decode("string_escape")
'0'

2012년 3월 7일 수요일

gcc 에서 디버깅심볼을 별도 파일로 저장하기.

http://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target

분리할 때..
gcc -ggdb -o test test.c;
cp test test.debug;
strip --only-keep-debug test.debug;
strip test;


합칠 때
objcopy --add-gnu-debuglink=test.debug test


gdb 에서..
http://sigquit.wordpress.com/2008/09/15/debugging-programs-with-a-external-symbol-file/
(gdb) symbol-file test.debug

2012년 2월 9일 목요일

라자루스에서 TForm 생성시 class name 바꾸기..

아래링크를 참조하여 윈도용 라자루스에서 TForm 의 Class Name 을 바꿔보려 했다.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=1072
라자루스에서 TForm 의 기본 class name 은 'Window' 인데 아래와 같이 해도 바뀌지는 않는다.

type
{ TFormMain }
TFormMain = class(TForm)
....
protected
PrevWndProc: Windows.WNDPROC;
procedure WndProc( var TheMessage: TLMessage); override;
procedure CreateParams(var Params: TCreateParams); override;
end;

procedure TFormMain.CreateParams(var Params: TCreateParams);
begin
inherited;
StrCopy(Params.WinClassName, 'MyClass');
end;

procedure TFormMain.MenuItem2Click(Sender: TObject);
var
class_name :array [0..255] of Char;
ret :LongInt;
begin
ret := GetClassName(WindowHandle, class_name, SizeOf(class_name));
if ret > 0 then
begin
MessageDlg(class_name, mtInformation, [mbOK], 0 )
end;
end;
그래서, 라자루스 포럼에 질문을 올렸더니, 직접 패치를 만들어보라는 대답이 돌아왔다. TT_TT;;
http://www.lazarus.freepascal.org/index.php/topic,15941.msg86071.html#msg86071
그래서, 직접 수정해보기로 했다.
라자루스 소스를 분석해보면 TCreateParams.WinClassName 를 전혀 사용하지 않고 있다.
아래 코드와 같이 대충 동작하도록 만들어보았는데, 윈7, XP 에서 동작하는 것을 확인했다.
Ansi 쪽이 호출되는 상황이면 충돌이 발생하는데 그 원인을 모르겠다.
파스칼,델파이,라자루스 모두 익숙하지 않은지라 그리 깔끔해보지는 않는다.
고수님들이 손 봐줬으면 좋겠다.
Lazarus-0.9.31-35255-fpc-2.6.1-20120209-win32.exe 에 포함된 소스를 기준으로 작업

unit Win32WSForms;

{$mode objfpc}{$H+}
{$I win32defines.inc} // added

interface
....
....
class function TWin32WSCustomForm.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Params: TCreateWindowExParams;
lForm: TCustomForm absolute AWinControl;
Bounds: TRect;
SystemMenu: HMenu;
// addtion start
WindowClass: WndClass;
{$ifdef WindowsUnicodeSupport}
WindowClassW: WndClassW;
{$endif}
AErrorCode: Cardinal;
// addtion end
begin
// general initialization of Params
PrepareCreateWindow(AWinControl, AParams, Params);
// customization of Params
with Params do
begin
if (Parent = 0) then
begin
 ......
end;
CalcFormWindowFlags(lForm, Flags, FlagsEx);
pClassName := @ClsName[0];

// addtion start
if AParams.WinClassName[0] <> #0 then
begin
pClassName := @AParams.WinClassName[0];
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
  if not GetClassInfoW(System.HInstance(), PWideChar(WideString(pClassName)), @WindowClassW) then
  begin
    if GetClassInfoW(System.HInstance(), PWideChar(WideString(ClsName)), @WindowClassW) then
    begin
  WindowClassW.lpszClassName:=PWideChar(WideString(pClassName));
  if Windows.RegisterClassW(@WindowClassW) = 0 then
  begin
    AErrorCode := GetLastError;
    //DebugLn(['Failed to RegisterClassW, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
    raise Exception.Create('Failed to RegisterClassW, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
  end;
    end
    else
    begin
      AErrorCode := GetLastError;
  //DebugLn(['Failed to GetClassInfoW, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
  raise Exception.Create('Failed to GetClassInfoW, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
    end;
  end;
end
else
{$endif}
begin
  FillChar(WindowClass, SizeOf(WindowClass),0);
  if not GetClassInfo(System.HInstance(), pClassName, @WindowClass) then
  begin
    if GetClassInfo(System.HInstance(), PChar(AnsiString(ClsName)), @WindowClass) then
    begin
  WindowClass.lpszClassName:=pClassName;
  if Windows.RegisterClass(@WindowClass) = 0 then
  begin
    AErrorCode := GetLastError;
    //DebugLn(['Failed to RegisterClass, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
    raise Exception.Create('Failed to RegisterClass, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
  end;
    end
    else
    begin
      AErrorCode := GetLastError;
  //DebugLn(['Failed to GetClassInfo, error: ', AErrorCode, ' : ', GetLastErrorText(AErrorCode)]);
  raise Exception.Create('Failed to GetClassInfo, error: ' + IntToStr(AErrorCode) + ' : ' + GetLastErrorText(AErrorCode));
    end;
  end;
end;
end;
// addtion end

WindowTitle := StrCaption;
AdjustFormBounds(lForm, Bounds);
if (lForm.Position in [poDefault, poDefaultPosOnly]) and not (csDesigning in lForm.ComponentState) then
begin
....

2011년 10월 4일 화요일

파이썬으로 자기 PC IP 알아내는 방법.

자기PC 의 IP를 알아내는 방법은 여러가지가 있겠지만 파이썬에서는 아래 코드가 가장 심플한듯..
http://python.kr/viewtopic.php?p=76315#76315
>>> import urllib
>>> urllib.thishost()
'192.168.10.101'

2011년 5월 24일 화요일

윈도에서 pymssql 1.9 를 iconv 라이브러리와 링크하기.

pymssql 1.9 개발버전이 DB 인터페이스로 freetds 라이브러리를 사용하는데, cp949 같은 encoding 을 지원하려면 iconv 라이브러리를 사용해야 한다.
따라서, freetds 를 iconv 라이브러와 링크하기가 더 정확한 표현이다.

방법은 이미 http://code.google.com/p/pymssql/issues/detail?id=54 에 이슈로 등록해놓았다.
다만, 백업차원에서 여기에 남겨놓는다.

Below is pymssql's build order using static freetds and iconv library.
1. download and extract the libiconv-1.13.1 from http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
2. download and extract the freetds-0.91rc from http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-0.91rc.tgz
3. download and install msys from www.mingw.org
4. download and install tdm-gcc 4.5.2 from http://tdm-gcc.tdragon.net/download
5. clone pymssql source.
6. run the msys shell
7. $ export PATH=/c/devtool/mingw_tdm/bin/:$PATH
8. $ gcc -v
gcc version 4.5.2 (tdm-1)
9. $ cd /d/work/libiconv-1.13.1
11. $ ./configure --prefix=/opt/freetds/freetds --disable-shared --enable-static --enable-extra-encodings
12. $ make
13. $ make install
14. $ cd /d/work/freetds-0.91.dev.20110523RC2
15. $ $ ./configure --prefix=/opt/freetds/freetds --enable-threadsafe --disable-shared
--enable-static --enable-msdblib --enable-odbc-wide --with-tdsver=7.2 --enable-libiconv --with-libiconv-prefix=/opt/freetds/freetds
16. $ make
17. $ make install
18. zip [msys_inst_path]\opt\freetds folder to freetds.zip
19. replace [pymssql_src]\win32\freetds.zip with new freetds.zip
20. fix the setup.py as below.
Because of iconv and sysdb order, link error occurred in pymssql build.
So, iconv and sysdb order is changed.
@@ -53,9 +53,9 @@
include_dirs = [os.path.join(FREETDS, 'include')]
library_dirs = [os.path.join(FREETDS, 'lib')]
libraries = [
- 'libiconv',
+ 'sybdb',
+ #'libiconv',
'iconv',
- 'sybdb',
'ws2_32',
'wsock32',
'kernel32',

21. run cmd.exe and cd D:\work\pymssql19_hg
22. D:\work\pymssql19_hg>set PATH=c:\devtool\mingw_tdm\bin;%PATH%
23. D:\work\pymssql19_hg>python26 setup.py build -c mingw32 bdist_wininst