How to use the pymtp.MTP function in PyMTP

To help you get started, we’ve selected a few PyMTP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emdete / python-mtp / examples / mtpshell.py View on Github external
def main():
	if 'LIBMTP_DEBUG' in environ: MTP.set_debug(int(environ['LIBMTP_DEBUG']))
	with MTP(False) as mtp:
		print("Welcome to the PyMTP Shell")
		print("You are currently connected to '{}'".format(mtp.get_devicename()))
		print("Your MTP object is '{}'".format("mtp"))
		print("Your progress callback object is '{}'".format("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
github exaile / exaile / plugins / mtpdevice.py View on Github external
    @common.threaded
    def connect(self, panel):
        '''
            Connects to the MTP device and loads playlist/track
             info into exaile.
        '''
        if self.connecting: self.disconnect()

        self.connecting = True
        self.panel = panel
        self.collection_panel = self.exaile.collection_panel
        self.mtp = pymtp.MTP()
        try:
            self.mtp.connect()
            self.connected = True
        except:
            self.panel.on_connect_complete(None)
            gobject.idle_add(panel.on_error, _("Couldn't connect to the MTP device,"
                                        " wait a few seconds or reconnect the"
                                        " device, then try again."))
            self.connected = False
            self.connecting = False
            return

        self.panel.track_count.set_label(_("Loading tracks..."))
        tracks = self.mtp.get_tracklisting()
        gobject.idle_add(self._load_tracks, tracks)
github akretion / pywebdriver / pywebdriver / plugins / signature_driver.py View on Github external
def get_signature_http():

    file_ = None
    data = None

    download_path = config.get('signature_driver', 'download_path') or \
        '/tmp'
    signature_file = config.get('signature_driver', 'signature_file') or \
        'signature.svg'

    try:
        mtp = pymtp.MTP()
        mtp.connect()
    except Exception as err:
        app.logger.error('Unable to connect device %s' % str(err))
        return jsonify(jsonrpc='2.0', result=data)

    for f in mtp.get_filelisting():
        if f.filename == signature_file:
            file_ = f
            break
    if file_:
        dest_file = os.path.join(download_path, signature_file)
        try:
            mtp.get_file_to_file(file_.item_id, dest_file)
            app.logger.debug('file downloaded to %s' % dest_file)
            with open(dest_file, 'r') as f:
                data = f.read()
github guardianproject / keysync / otrapps / util.py View on Github external
from potr.utils import bytes_to_long
from potr.compatcrypto import DSAKey

if __name__ == '__main__':
    sys.path.insert(0, "../") # so the main() test suite can find otrapps module
import otrapps.errors as errors


# gracefully handle it when pymtp doesn't exist
class MTPDummy():
    def detect_devices(self):
        return []
try:
    import pymtp
    mtp = pymtp.MTP()
except:
    mtp = MTPDummy()
# GNOME GVFS mount point for MTP devices

if sys.platform != 'win32':
    # this crashes windows in the ntpath sys lib
    mtp.gvfs_mountpoint = os.path.join(os.getenv('HOME'), '.gvfs', 'mtp')


HLEN = sha1().digest_size  # length of the hash output

#RSAPrivateKey ::= SEQUENCE {
#  version Version,
#  modulus INTEGER, -- n
#  publicExponent INTEGER, -- e
#  privateExponent INTEGER, -- d