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

2011년 2월 20일 일요일

mingw-w64 로 파이썬 64비트 모듈 컴파일하기

http://tdm-gcc.tdragon.net/ 의 32비트용 mingw tdm-gcc 로 아래와 같이 하면 파이썬 32비트 모듈을 쉽게 컴파일할 수 있습니다.
setup.py build -c mingw32 bdist_wininst

bdist_wininst 는 인스톨러를 생성하기 위한 옵션입니다.
64비트용 mingw(http://mingw-w64.sourceforge.net/) 를 이용하여 파이썬 64비트 모듈을 컴파일할수 있지 않을까 생각해봤습니다.
구글링을 해보니 완전하지는 않지만 대략적인 순서와 방법을 알 수 있습니다.
http://projects.scipy.org/numpy/wiki/MicrosoftToolchainSupport
요약하면
1. libpythonXY.a 생성 (64비트버전의 경우 '파이썬설치폴더\libs\libpythonXY.a' 가 없음.)
2. 파이썬 모듈 컴파일.

다음은 윈도7 64비트, 파이썬 2.7 64비트버전 기준으로 설명합니다.
같은 방식으로 2.5, 2.6 버전 64비트 모듈 빌드도 됩니다.
1. mingw64 tdm64-gcc 설치하기
1.1. http://tdm-gcc.tdragon.net/ 에서 tdm64-gcc 4.5.1 버전 설치.

2. libpython27.a 생성하기
2.1. http://sourceforge.net/projects/mingw/files/MinGW/gendef/ 에서
gendef 바이너리 패키지를 다운로드하고 압축해제.
(lzma 는 7zip(http://www.7-zip.org/) 로 압축해제가능)

2.2. c:\windows\system32\python27.dll 을 gendef 를 압축해제한 폴더로 복사.
되도록, 윈도탐색기를 이용해서 복사하기 바람.
freecommander 를 이용하니 32비트 python27.dll 이 복사되어서 고생..TT_TT.

2.3. 아래 명령으로 python27.def 생성.
E:\gendef\bin>gendef.exe python27.dll
* [python27.dll] Found PE+ image

"PE+ image" 인지 반드시 확인.
"PE+ image"는 64비트, "PE image" 는 32비트 DLL일 때 나옴.
생성된 python27.def 에서 "Py_InitModule4_64" 문자열이 있는지 확인.
32비트용 DLL이었다면 "Py_InitModule4" 문자열이 있음.

2.4. tdm64-gcc bin폴더를 PATH 에 추가.
E:\gendef\bin>set PATH=c:\devtool\mingw_tdm64\bin;%PATH%


2.5. libpython27.a 생성
E:\gendef\bin>dlltool -d python27.def -l libpython27.a


2.6. libpython27.a 를 "파이썬설치폴더\lib" 폴더로 복사.
E:\gendef\bin>copy libpython27.a c:\devtool\py27x64\libs
1개 파일이 복사되었습니다.


3. 모듈빌드하기.
예제로 pycrypto 모듈을 빌드.
3.1. http://pypi.python.org/pypi/pycrypto/ 에서 pycrypto 소스 다운로드후 압축해제.

3.2. tdm64-gcc bin폴더를 PATH 에 추가.
E:\gendef\bin>set PATH=c:\devtool\mingw_tdm64\bin;%PATH%


3.3. 모듈 빌드해 보기.
E:\myprg\python\pycrypto-2.3>c:\devtool\py27x64\python.exe setup.py build_ext -c
mingw32 -DMS_WIN64 build -c mingw32 bdist_wininst

64비트 빌드의 경우 MS_WIN64 가 define 되어 있어야 함.
불행히도, 아래와 같이 심볼이 중복되었다는 에러메시지가 나옴.
libmsvcr90.a, libmingw32.a 둘중 하나가 잘 못 만들어진 걸로 보임.
...........
c:/crossdev/src/mingw-w64-svn/mingw-w64-crt/crt/mingw_helpers.c:20: multiple def
inition of `_decode_pointer'
c:/devtool/mingw_tdm64/bin/../lib/gcc/x86_64-w64-mingw32/4.5.1/../../../../x86_64-w64-mingw32/lib/libmsvcr90.a(dkbgs00301.o):(.text+0x0): first defined here
c:/devtool/mingw_tdm64/bin/../lib/gcc/x86_64-w64-mingw32/4.5.1/../../../../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-mingw_helpers.o): In function `_encode_pointer':
c:/crossdev/src/mingw-w64-svn/mingw-w64-crt/crt/mingw_helpers.c:26: multiple definition of `_encode_pointer'
c:/devtool/mingw_tdm64/bin/../lib/gcc/x86_64-w64-mingw32/4.5.1/../../../../x86_64-w64-mingw32/lib/libmsvcr90.a(dkbgs00311.o):(.text+0x0): first defined here
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


3.4. 아래 링크를 참조하여 "파이썬설치폴더\Lib\distutils\cygwinccompiler.py" 수정.
http://www.mail-archive.com/mingw-w64-public@lists.sourceforge.net/msg01902.html


# the same as cygwin plus some additional parameters
class Mingw32CCompiler (CygwinCCompiler):

compiler_type = 'mingw32'

def __init__ (self,
verbose=0,
dry_run=0,
force=0):

CygwinCCompiler.__init__ (self, verbose, dry_run, force)
...................
self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
compiler_so='gcc -mno-cygwin -mdll -O -Wall',
compiler_cxx='g++ -mno-cygwin -O -Wall',
linker_exe='gcc -mno-cygwin',
linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
# Maybe we should also append -mthreads, but then the finished
...................



linker_so='%s -mno-cygwin %s %s'

이 부분을 아래처럼 -Wl,--allow-multiple-definition 을 추가.
linker_so='%s -mno-cygwin -Wl,--allow-multiple-definition %s %s'


3.5. 다시 시도해보면 에러없이 빌드될 것이다.
dist 폴더에 pycrypto-2.3.win-amd64-py2.7.exe 생성확인.

3.6. 파이썬 2.5의 경우 인스톨러 생성시(bdist_wininst 옵션) 에러가 발생함.
dist 폴더에 pycrypto-2.3.win32-py2.5.exe 생성확인.
.......
adding 'PLATLIB\Crypto\Util\_number_new.py'
adding 'PLATLIB\Crypto\Util\__init__.py'
error: c:\devtool\py25x64\lib\distutils\command\wininst-8.0.exe: No such file or directory

파이썬 2.7 또는 2.6의 wininst-9.0-amd64.exe 를 wininst-8.0.exe 로 복사해주면 해결됨.
copy C:\devtool\py27x64\Lib\distutils\command\wininst-9.0-amd64.exe
C:\devtool\py25x64\Lib\distutils\command\wininst-8.0.exe

생성된 설치패키지를 설치하여 정상적으로 임포트되는 것까지만 확인했습니다.
모듈자체 동작에 문제가 없는지 각자 확인해보시기 바랍니다.

2010년 11월 29일 월요일

2010년 8월 6일 금요일

Python Thread Pool TCP Server 구현.

아래 링크를 참조하여 간단하게 Python Multithread Pool TCP Server 를 구현해 보았다.
http://code.activestate.com/recipes/574454/
http://www.cherrypy.org/browser/cherrypy/_cphttpserver.py?rev=1

TCP 서버 클래스 사용시 다중상속에 따른 생성자 호출이 복잡하고 생성자 인수를 변경하지 않기 위하여
인스턴스 생성후 별도의 초기화 메쏘드를 호출하는 방식을 택했다.
아래 소스를 보면 쉽게 이해할 수 있을 것이다.
아래 소스와 같은 폴더에 적당한 index.html 를 만들고 실행한 후 웹브라우저로 8002 포트에 접속해보자.
import SocketServer
import Queue
import threading
import socket

class ThreadPoolMixIn(SocketServer.ThreadingMixIn):
'''
use a thread pool instead of a new thread on every request
'''
allow_reuse_address = True # seems to fix socket.error on server restart

def create_pool(self, numThreads):
# set up the threadpool
self.numThreads = numThreads
self.requests = Queue.Queue(self.numThreads)

self.threadPool = []

for x in range(self.numThreads):
t = threading.Thread(target = self.process_request_thread)
self.threadPool.append(t)
t.setDaemon(1)
t.start()

def process_request_thread(self):
'''
obtain request from queue instead of directly from server socket
'''
while True:
SocketServer.ThreadingMixIn.process_request_thread(self, *self.requests.get())

def process_request(self, request, client_address):
self.requests.put((request, client_address))

class ThreadPoolTCPServer(ThreadPoolMixIn, SocketServer.TCPServer):
pass

class ThreadPoolUDPServer(ThreadPoolMixIn, SocketServer.UDPServer):
pass

if __name__ == '__main__':
import SimpleHTTPServer
import SocketServer

def test(HandlerClass = SimpleHTTPServer.SimpleHTTPRequestHandler,
ServerClass = ThreadPoolTCPServer,
protocol="HTTP/1.0"):
'''
Test: Run an HTTP server on port 8002
'''

port = 8002
server_address = ('', port)

HandlerClass.protocol_version = protocol
httpd = ServerClass(server_address, HandlerClass)
httpd.create_pool(10)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()

test()


2010년 8월 5일 목요일

Python 라이브러리 소스패키지로 RPM 생성하기.

우분투나 데비안에는 레포지토리에 웬만한 파이썬라이브러리들이 다 포함되어 있지만,
CentOS 5.5 에는 별로 없을 뿐더러 그나마도 예전 버전이다.

필요한 라이브러리를 찾아서 수작업으로 설치해줘야 하는 상황이다. TT_TT.

아래처럼 설치하면 되지만 삭제,업그레이드를 수작업으로 해야되어서 왠지 찜찜.
python setup.py install
egg 패키지도 완전삭제는 수작업으로 해야 되어서 역시 찜찜.

그래서, CentOS 5.5상에서 RPM 패키지를 생성하기로 결정했다.
아래와 같이 하면 소스패키지에서 RPM 패키지를 생성할 수 있다고 한다.
python setup.py bdist_rpm

하지만, 불행히도 아래와 같은 메시지를 보게 될 것이다.
파일 처리 중: ctypes-1.0.2-1
Provides: _ctypes.so _ctypes_test.so
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.3.4) libc.so.6(GLIBC_2.4) libpthread.so.0 python(abi) = 2.4 rtld(GNU_HASH)
파일 처리 중: ctypes-debuginfo-1.0.2-1
Provides: _ctypes.so.debug _ctypes_test.so.debug
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/ctypes-1.0.2-1-buildroot
오류: Installed (but unpackaged) file(s) found:
   /usr/lib/python2.4/site-packages/ctypes/__init__.pyo
   /usr/lib/python2.4/site-packages/ctypes/_endian.pyo
..............................
   /usr/lib/python2.4/site-packages/ctypes/util.pyo
   /usr/lib/python2.4/site-packages/ctypes/wintypes.pyo

RPM 제작 오류:
    Installed (but unpackaged) file(s) found:
   /usr/lib/python2.4/site-packages/ctypes/__init__.pyo
   /usr/lib/python2.4/site-packages/ctypes/_endian.pyo
.............................
   /usr/lib/python2.4/site-packages/ctypes/util.pyo
   /usr/lib/python2.4/site-packages/ctypes/wintypes.pyo
error: command 'rpmbuild' failed with exit status 1

우분투 10.4에서는 에러없이 생성된다.(이건 무슨 조화?)
포기할까 하다가 cx-Freeze 는 에러없이 RPM 패키지가 생성되는 것이다.
cx-Freeze 의 setup.py 를 분석하면 답이 있다.

먼저, 다음명령으로 라이브러리 빌드에는 문제가 없는지 확인한다.
여기서, 문제가 발생하는 건 각자 알아서 해결하자.(README 파일이나 홈페이지 참조)
python setup.py build

cx-Freeze 소스를 받아서 압축해제하고 setup.py 를 열어보면 다음 내용을 볼 수 있을 것이다.
......
import distutils.command.bdist_rpm
......
class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):

# rpm automatically byte compiles all Python files in a package but we
# don't want that to happen for initscripts and samples so we tell it to
# ignore those files
def _make_spec_file(self):
specFile = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self)
specFile.insert(0, "%define _unpackaged_files_terminate_build 0%{nil}")
return specFile

def run(self):
distutils.command.bdist_rpm.bdist_rpm.run(self)
specFile = os.path.join(self.rpm_base, "SPECS",
"%s.spec" % self.distribution.get_name())
queryFormat = "%{name}-%{version}-%{release}.%{arch}.rpm"
command = "rpm -q --qf '%s' --specfile %s" % (queryFormat, specFile)
origFileName = os.popen(command).read()
parts = origFileName.split("-")
parts.insert(2, "py%s%s" % sys.version_info[:2])
newFileName = "-".join(parts)
self.move_file(os.path.join("dist", origFileName),
os.path.join("dist", newFileName))
......
commandClasses = dict(
build_ext = build_ext,
build_scripts = build_scripts,
bdist_rpm = bdist_rpm, # 여기
install = install,
install_packagedata = install_packagedata)
.....
setup(name = "cx_Freeze",
description = "create standalone executables from Python scripts",
long_description = "create standalone executables from Python scripts",
version = "4.2",
cmdclass = commandClasses, # 여기
options = dict(bdist_rpm = dict(doc_files = docFiles),
install = dict(optimize = 1)),
ext_modules = extensions,
packages = ['cx_Freeze'],
maintainer="Anthony Tuininga",
maintainer_email="anthony.tuininga@gmail.com",
url = "http://cx-freeze.sourceforge.net",
scripts = ["cxfreeze"],
classifiers = classifiers,
keywords = "freeze",
license = "Python Software Foundation License")


bdist_rpm 빌드명령을 커스터마이징하고 setup 에 등록해주면 되는 것이다.
다음은 ctypes 1.0.2 소스의 setup.py 를 수정한 부분이다.

........
print 'Installing data files to %s' % self.install_dir
install_data.install_data.finalize_options(self)


### 추가된 부분
import distutils.command.bdist_rpm
class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):

# rpm automatically byte compiles all Python files in a package but we
# don't want that to happen for initscripts and samples so we tell it to
# ignore those files
def _make_spec_file(self):
specFile = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self)
specFile.insert(0, "%define _unpackaged_files_terminate_build 0%{nil}")
return specFile

def run(self):
distutils.command.bdist_rpm.bdist_rpm.run(self)
specFile = os.path.join(self.rpm_base, "SPECS",
"%s.spec" % self.distribution.get_name())
queryFormat = "%{name}-%{version}-%{release}.%{arch}.rpm"
command = "rpm -q --qf '%s' --specfile %s" % (queryFormat, specFile)
origFileName = os.popen(command).read()
parts = origFileName.split("-")
parts.insert(2, "py%s%s" % sys.version_info[:2])
newFileName = "-".join(parts)
self.move_file(os.path.join("dist", origFileName),
os.path.join("dist", newFileName))
### 추가 끝부분

################################################################
# Specify the _ctypes extension
#
kw = {}
# common source files
kw["sources"] = ["source/_ctypes.c",
...........
url="http://starship.python.net/crew/theller/ctypes/",
platforms=["windows", "Linux", "MacOS X", "Solaris", "FreeBSD"],
download_url="http://sourceforge.net/project/showfiles.php?group_id=71702",

cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext,
'clean': my_clean, 'install_data': my_install_data,
'bdist_rpm': bdist_rpm #<< 여기
## 'ce_install_lib': ce_install_lib
},

)

## Local Variables:
## compile-command: "python setup.py build"
## End:


자, 다시 RPM 패키지를 만들어보자.
python setup.py bdist_rpm
마지막에 복사오류가 나지만 dist 폴더에 RPM 패키지가 생성되어있을 것이다.

몇몇패키지들은 RPM 생성중 오류가 나지만 로그메시지를 잘 보면 해결할 수 있을 것이다.
(root 권한으로 수행(cofigobj?), MANIFEST 파일삭제(pymssql?),
setup.cfg 수정(mysql-python) 등등등)

위방법으로 Cython, MySQL-python, configobj, ctypes, hashlib, importlib, multiprocessing,
pymssql, pyodbc, subprocess32, unittest2 소스패키지에서 RPM 패키지를 생성해냈다.