Vizible’s Blog

cython cause install skype4py failed

Posted in Python by wearetherock on September 18, 2009
$ sudo python setup.py install
running install
running build
running build_py
running build_ext
cythoning Skype4Py/utils.py to Skype4Py/utils.c

Error converting Pyrex file to C:
------------------------------------------------------------
...
        self._EventHandlerObj = Obj

    @staticmethod
    def __AddEvents_make_event(Event):
        # TODO: rework to make compatible with cython
        return property(lambda self: self._GetDefaultEventHandler(Event),
                       ^
------------------------------------------------------------

/dos/library/Skype4Py/tar/Skype4Py-1.0.31.0/Skype4Py/utils.py:462:24: Expected an identifier or literal
building 'Skype4Py.utils' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I. -I/usr/include/python2.6 -c Skype4Py/utils.c -o build/temp.linux-i686-2.6/Skype4Py/utils.o -O3
gcc: Skype4Py/utils.c: No such file or directory
gcc: no input files
error: command 'gcc' failed with exit status 1
$

~
Then

$ sudo apt-get remove cython
$ sudo python setup.py install
running install
running build
running build_py
copying Skype4Py/API/windows.py -> build/lib.linux-i686-2.6/Skype4Py/API
copying Skype4Py/API/faked_dbus.py -> build/lib.linux-i686-2.6/Skype4Py/API
copying Skype4Py/API/darwin.py -> build/lib.linux-i686-2.6/Skype4Py/API
running install_lib
...
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/bg.py to bg.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/lt.py to lt.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/sv.py to sv.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/ro.py to ro.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/conversion.py to conversion.pyc
running install_egg_info
Writing /usr/local/lib/python2.6/dist-packages/Skype4Py-1.0.31.0.egg-info
$

~

Tagged with: , ,

Python – Find Prime Number

Posted in Python by wearetherock on August 30, 2009
def get_prime_list(n):
        n  = int(n)
        maked_list = [False] * (n + 1)
        prime_list = []

        for i in range(2,n+1):
                if not maked_list[i] :
                        prime_list.append(i)
                        for j in range(i**2, n+1,i):
                                maked_list[j] = True
        return prime_list
print get_prime_list(10001)
~

Python – Find Factors of Number

Posted in Python by wearetherock on August 30, 2009

Code :
========================================

from math import sqrt
import sys

input = int(sys.argv[1])
factors = []
min_fac = 2

while input > min_fac - 1 :
        if (input % min_fac) == 0 :
                factors.append(min_fac)
                input = input / min_fac
        else :
                min_fac += 1
print factors

~
Example :
========================================

$ python prime.py 600851475143
[71, 839, 1471, 6857]

~

Python – SflPhone Dbus

Posted in Python by wearetherock on August 26, 2009

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
from gobject import GObject
from SimpleXMLRPCServer import SimpleXMLRPCServer
import thread

class SlfPhoneConnector :

	def __init__(self) :
		self.activeCalls = {}

		account = {
			"username" : "1111", 
			"Account.type" : "SIP", 
			"hostname" : "192.168.1.109", 
			"Account.alias" : "1111", 
			"password":"1111", 
			"Account.enable" : "TRUE"
		}
		session = dbus.SessionBus()

		conf_obj = session.get_object("org.sflphone.SFLphone", "/org/sflphone/SFLphone/ConfigurationManager")  
		self.conf_mgr = dbus.Interface(conf_obj ,"org.sflphone.SFLphone.ConfigurationManager")

		call_obj = session.get_object("org.sflphone.SFLphone", "/org/sflphone/SFLphone/CallManager")  
		self.call_mgr = dbus.Interface(call_obj ,"org.sflphone.SFLphone.CallManager")

		'''
		i= session.get_object("org.sflphone.SFLphone", "/org/sflphone/SFLphone/ConfigurationManager")  
		instance = dbus.Interface(object,"org.sfphone.SFLphone.Instance")
		'''

		self.call_mgr.connect_to_signal('incomingCall', self.on_incoming_call)
		self.call_mgr.connect_to_signal('callStateChanged', self.on_call_state_changed)

		self.account_id = self.conf_mgr.addAccount(account)

		self.conf_mgr.sendRegister(self.account_id, 1)			 
		
		#self.call_mgr.placeCall(self.account_id, self.account_id, "2222" )	 

	def on_incoming_call(self, account, callid, to):
		print "Incoming call: " + account + ", " + callid + ", " + to
		self.activeCalls[callid] = {'Account': account, 'To': to, 'State': '' }   

		self.call_mgr.accept(str(callid))

	# On call state changed event, set the values for new calls, 
	# or delete the call from the list of active calls
	def on_call_state_changed(self, callid, state):
		print "Call state changed: " + callid + ", " + state
		if state == "HUNGUP":
			try:
				del self.activeCalls[callid]
			except KeyError:
				print "Call " + callid + " didn't exist. Cannot delete."

		elif state in [ "RINGING", "CURRENT", "INCOMING", "HOLD" ]:
			try:
				self.activeCalls[callid]['State'] = state 
			except KeyError, e:
				print "This call didn't exist!: " + callid + ". Adding it to the list."
				callDetails = self.getCallDetails(callid)
				self.activeCalls[callid] = {'Account': callDetails['ACCOUNTID'], 'To': callDetails['PEER_NUMBER'], 'State': state }
		elif state in [ "BUSY", "FAILURE" ]:
			try:
				del self.activeCalls[callid]
			except KeyError, e:
				print "This call didn't exist!: " + callid   


	def getCallDetails(self, callid):
		"""Return informations on this call if exists"""
		return self.call_mgr.getCallDetails(callid)

	def place_call(self, callid):
		self.call_mgr.placeCall(self.account_id, self.account_id, callid)

	def hangup(self) :
		call0 = self.activeCalls.keys()[0]
		self.call_mgr.hangUp(call0)


def start_server(obj):
	server = SimpleXMLRPCServer( ("localhost", 9988), allow_none= True)
	server.register_instance(obj)

	print "server start @localhost 9988 forever ..."
	server.serve_forever()

if __name__ == "__main__" :

	DBusGMainLoop(set_as_default=True)
	s  = SlfPhoneConnector()

	thread.start_new_thread(start_server(s,))

	loop = gobject.MainLoop()
	loop.run()

Python – Simulate mouse click

Posted in Programming, Python by wearetherock on August 20, 2009
import time
import win32api
import win32con

time.sleep(1)
win32api.SetCursorPos((100,100))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.05)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

~