File: mtpshell.py

package info (click to toggle)
pymtp 0.0.4-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 212 kB
  • sloc: python: 734; makefile: 7
file content (43 lines) | stat: -rwxr-xr-x 993 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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()