Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > f24ad0310394ff516b81a93fbff0de48 > files > 9

python-pymtp-0.0.4-6mdv2010.0.i586.rpm

#!/usr/bin/env python
#
# A PyMTP Shell - Automagically initiates the MTP device, makes it
# easier to develop and test stuff.
# (C) 2008 Nick Devito
#

import sys
sys.path.insert(0, "../") # So examples work on first try

import pymtp

def callback(sent, total):
	"""
		A generic traffic sent/total callback
	"""
	print "Sent: %s; Total: %s" % (sent, total)

def main():
	mtp = pymtp.MTP()
	mtp.connect()
	print "Welcome to the PyMTP Shell"
	print "You are currently connected to '%s'" % (mtp.get_devicename())
	print "Your MTP object is '%s'" % ("mtp")
	print "Your progress callback object is '%s'" % ("callback")
	print "To exit, type 'quit'"
	while True:
		try:
			if mtp.device:
				result = raw_input("(connected) >>> ")
			else:
				result = raw_input("(disconnected) >>> ")
			if result.startswith("quit"):
				mtp.disconnect()
				sys.exit()
			else:
				exec result
		except Exception, message:
			print "An exception occurred:"
			print message

if __name__ == "__main__":
	main()