[python-pymtp] Initial import

Ville-Pekka Vainio vpv at fedoraproject.org
Sat Jan 15 21:34:35 UTC 2011


commit 398cecd6277767e8b651e3ef46b8b6aa72482cb5
Author: Ville-Pekka Vainio <vpivaini at cs.helsinki.fi>
Date:   Sat Jan 15 23:34:00 2011 +0200

    Initial import

 .gitignore            |    1 +
 adapt-to-libmtp8.diff |  236 +++++++++++++++++++++++++++++++++++++++++++++++++
 python-pymtp.spec     |   71 +++++++++++++++
 sources               |    1 +
 4 files changed, 309 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..7a23a2e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/pymtp-latest.tar.bz2
diff --git a/adapt-to-libmtp8.diff b/adapt-to-libmtp8.diff
new file mode 100644
index 0000000..6bbc05e
--- /dev/null
+++ b/adapt-to-libmtp8.diff
@@ -0,0 +1,236 @@
+Adapt to libmtp8 (libmtp_0.3.7)
+
+ -- Rafael Laboissiere <rafael at debian.org>  Thu, 02 Apr 2009 22:17:24 +0200
+
+--- pymtp-0.0.4.orig/examples/sendtrack.py
++++ pymtp-0.0.4/examples/sendtrack.py
+@@ -9,7 +9,7 @@
+ sys.path.insert(0, "../")
+ 
+ import pymtp
+-import pyid3lib
++from ID3 import *
+ 
+ def usage():
+ 	print "Usage: %s <source> <target> <parent>\n(The parent id can be 0 for the root directory)" % (sys.argv[0])
+@@ -26,20 +26,19 @@
+ 	target = sys.argv[2]
+ 	parent = int(sys.argv[3])
+ 
+-	id3data = pyid3lib.tag(source)
++	id3data = ID3(source)
+ 
+-	metadata = pymtp.LIBMTP_Track()
++        metadata = pymtp.LIBMTP_Track()
++	metadata.parent_id = parent;
+ 
+-	if (hasattr(id3data, 'artist')):
++        if (hasattr(id3data, 'artist')):
+ 		metadata.artist = id3data.artist
+ 	if (hasattr(id3data, 'title')):
+ 		metadata.title = id3data.title
+ 	if (hasattr(id3data, 'album')):
+ 		metadata.album = id3data.album
+-	if (hasattr(id3data, 'tracknum')):
+-		metadata.tracknumber = id3data.tracknum
+-		
+-	track_id = mtp.send_track_from_file(source, target, metadata, parent=parent)
++
++	track_id = mtp.send_track_from_file(source, target, metadata)
+ 	print "Created new track with ID: %s" % (track_id)
+ 	mtp.disconnect()
+ 		
+--- pymtp-0.0.4.orig/examples/sendfile.py
++++ pymtp-0.0.4/examples/sendfile.py
+@@ -12,7 +12,7 @@
+ import pyid3lib
+ 
+ def usage():
+-	print "Usage: %s <source> <target> <parent>\n(The parent id can be 0 for the root directory)" % (sys.argv[0])
++	print "Usage: %s <source> <target>" % (sys.argv[0])
+ 
+ def main():
+ 	if len(sys.argv) <= 3:
+@@ -24,9 +24,8 @@
+ 
+ 	source = sys.argv[1]
+ 	target = sys.argv[2]
+-	parent = int(sys.argv[3])
+ 
+-	file_id = mtp.send_file_from_file(source, target, parent=parent)
++	file_id = mtp.send_file_from_file(source, target)
+ 	print "Created new track with ID: %s" % (file_id)
+ 	mtp.disconnect()
+ 		
+--- pymtp-0.0.4.orig/pymtp.py
++++ pymtp-0.0.4/pymtp.py
+@@ -167,6 +167,7 @@
+ 
+ LIBMTP_File._fields_ = [("item_id", ctypes.c_uint32),
+                         ("parent_id", ctypes.c_uint32),
++                        ("storage_id", ctypes.c_uint32),
+                         ("filename", ctypes.c_char_p),
+                         ("filesize", ctypes.c_uint64),
+ 			("filetype", ctypes.c_int),
+@@ -183,8 +184,10 @@
+ 		
+ LIBMTP_Track._fields_ = [("item_id", ctypes.c_uint32),
+ 			("parent_id", ctypes.c_uint32),
++                        ("storage_id", ctypes.c_uint32),
+ 			("title", ctypes.c_char_p),
+ 			("artist", ctypes.c_char_p),
++			("composer", ctypes.c_char_p),
+ 			("genre", ctypes.c_char_p),
+ 			("album", ctypes.c_char_p),
+ 			("date", ctypes.c_char_p),
+@@ -277,6 +280,8 @@
+ 		return self.no_tracks
+ 
+ LIBMTP_Playlist._fields_ = [("playlist_id", ctypes.c_uint32),
++	  		    ("parent_id", ctypes.c_uint32),
++                            ("storage_id", ctypes.c_uint32),
+                             ("name", ctypes.c_char_p),
+                             ("tracks", ctypes.POINTER(ctypes.c_uint32)),
+                             ("no_tracks", ctypes.c_uint32),
+@@ -293,6 +298,7 @@
+ 
+ LIBMTP_Folder._fields_ = [("folder_id", ctypes.c_uint32),
+                           ("parent_id", ctypes.c_uint32),
++                          ("storage_id", ctypes.c_uint32),
+                           ("name", ctypes.c_char_p),
+                           ("sibling", ctypes.POINTER(LIBMTP_Folder)),
+                           ("child", ctypes.POINTER(LIBMTP_Folder))]
+@@ -819,7 +825,7 @@
+ 		else:
+ 			return LIBMTP_Filetype["UNKNOWN"]
+ 
+-	def send_file_from_file(self, source, target, parent=0, callback=None):
++	def send_file_from_file(self, source, target, callback=None):
+ 		"""
+ 			Sends a file from the filesystem to the connected device
+ 			and stores it at the target filename inside the parent.
+@@ -831,9 +837,6 @@
+ 			@param source: The path on the filesystem where the file resides
+ 			@type target: str
+ 			@param target: The target filename on the device
+-			@type parent: int or 0
+-			@param parent: The parent directory for the file to go 
+-			 into; If 0, the file goes into main directory
+ 			@type callback: function or None
+ 			@param callback: The function provided to libmtp to 
+ 			 receive callbacks from ptp. Callback function must
+@@ -856,7 +859,7 @@
+ 		  filesize=os.stat(source).st_size)
+ 
+ 		ret = self.mtp.LIBMTP_Send_File_From_File(self.device, source, \
+-		  ctypes.pointer(metadata), callback, None, parent)
++		  ctypes.pointer(metadata), callback, None)
+ 
+ 		if (ret != 0):
+ 			self.debug_stack()
+@@ -864,7 +867,7 @@
+ 
+ 		return metadata.item_id
+ 		
+-	def send_track_from_file(self, source, target, metadata, parent=0, callback=None):
++	def send_track_from_file(self, source, target, metadata, callback=None):
+ 		"""
+ 			Sends a track from the filesystem to the connected 
+ 			device
+@@ -875,9 +878,6 @@
+ 			@param target: The target filename on the device
+ 			@type metadata: LIBMTP_Track
+ 			@param metadata: The track metadata
+-			@type parent: int or 0
+-			@param parent: The parent directory for the track;
+-			 if 0, the track will be placed in the base dir.
+ 			@type callback: function or None
+ 			@param callback: The function provided to libmtp to
+ 			 receive callbacks from ptp. Callback function must
+@@ -896,12 +896,11 @@
+ 			callback = Progressfunc(callback)
+ 		
+ 		metadata.filename = target
+-		metadata.parent_id = parent
+ 		metadata.filetype = self.find_filetype(source)
+ 		metadata.filesize = os.stat(source).st_size
+ 
+ 		ret = self.mtp.LIBMTP_Send_Track_From_File(self.device, source, \
+-		  ctypes.pointer(metadata), callback, None, parent)
++		  ctypes.pointer(metadata), callback, None)
+ 
+ 		if (ret != 0):
+ 			self.debug_stack()
+@@ -1031,14 +1030,14 @@
+ 		if (self.device == None):
+ 			raise NotConnected
+ 
+-		ret = self.mtp.LIBMTP_Get_Playlist(self.device, playlist_id).contents
+-
+-		if (ret != 0):
++		try:
++			ret = self.mtp.LIBMTP_Get_Playlist(self.device, playlist_id).contents
++		except ValueError:
+ 			raise ObjectNotFound
+ 
+ 		return ret
+ 
+-	def create_new_playlist(self, metadata, parent=0):
++	def create_new_playlist(self, metadata):
+ 		"""
+ 			Creates a new playlist based on the metadata object
+ 			passed.
+@@ -1046,8 +1045,6 @@
+ 			@type metadata: LIBMTP_Playlist
+ 			@param metadata: A LIBMTP_Playlist object describing 
+ 			 the playlist
+-			@type parent: int or 0
+-			@param parent: The parent ID or 0 for base
+ 			@rtype: int
+ 			@return: The object ID of the new playlist
+ 		"""
+@@ -1055,13 +1052,13 @@
+ 		if (self.device == None):
+ 			raise NotConnected
+ 		
+-		ret = self.mtp.LIBMTP_Create_New_Playlist(self.device, ctypes.pointer(metadata), parent)
++		ret = self.mtp.LIBMTP_Create_New_Playlist(self.device, ctypes.pointer(metadata))
+ 
+-		if (ret == 0):
++		if (ret != 0):
+ 			self.debug_stack()
+ 			raise CommandFailed
+ 
+-		return ret
++		return metadata.playlist_id
+ 
+ 	def update_playlist(self, metadata):
+ 		"""
+@@ -1173,7 +1170,7 @@
+ 
+ 		return ret
+ 
+-	def create_folder(self, name, parent=0):
++	def create_folder(self, name, parent=0, storage=0):
+ 		"""
+ 			This creates a new folder in the parent. If the parent 
+ 			is 0, it will go in the main directory.
+@@ -1182,6 +1179,9 @@
+ 			@param name: The name for the folder
+ 			@type parent: int
+ 			@param parent: The parent ID or 0 for main directory
++                        @type storage: int
++                        @param storage: The storage id or 0 to create the new folder
++                                        on the primary storage
+ 			@rtype: int
+ 			@return: Returns the object ID of the new folder
+ 		"""
+@@ -1189,7 +1189,7 @@
+ 		if (self.device == None):
+ 			raise NotConnected
+ 			
+-		ret = self.mtp.LIBMTP_Create_Folder(self.device, name, parent)
++		ret = self.mtp.LIBMTP_Create_Folder(self.device, name, parent, storage)
+ 
+ 		if (ret == 0):
+ 			self.debug_stack()
diff --git a/python-pymtp.spec b/python-pymtp.spec
new file mode 100644
index 0000000..b946aa9
--- /dev/null
+++ b/python-pymtp.spec
@@ -0,0 +1,71 @@
+%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
+# debuginfo would be empty
+%global debug_package %{nil}
+%global module pymtp
+
+Name:           python-pymtp
+Version:        0.0.4
+Release:        0.3%{?dist}
+Summary:        A Pythonic wrapper around libmtp
+
+Group:          Development/Libraries
+License:        GPLv3+
+URL:            http://downloads.nick125.com/projects/%{module}
+Source0:        http://downloads.nick125.com/projects/%{module}/%{module}-latest.tar.bz2
+# Make pymtp work with libmtp >= 1.0.0. Upstream seems inactive.
+Patch0:         http://patch-tracker.debian.org/patch/series/dl/pymtp/0.0.4-2/adapt-to-libmtp8.diff
+BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+# Depend on the libmtp soname provides of the correct arch
+%global libmtp libmtp.so.8
+%ifarch x86_64 ppc64 ia64 sparc64 s390x
+%global mark64 ()(64bit)
+%endif
+
+BuildRequires:  python-devel
+Requires:       %{libmtp}%{?mark64}
+
+%description
+A Pythonic wrapper around libmtp, allowing python applications to communicate
+with MTP devices.
+
+%prep
+%setup -q -n %{module}-%{version}
+%patch0 -p1
+# Examples are documentation, remove executable permission
+chmod -x examples/*
+# Remove the shebang to silence rpmlint
+sed -i '1d' pymtp.py
+
+%build
+%{__python} setup.py build
+
+
+%install
+rm -rf $RPM_BUILD_ROOT
+# Install into python_sitearch for the arch-specific dependency
+%{__python} setup.py install -O1 --skip-build --install-purelib $RPM_BUILD_ROOT%{python_sitearch} 
+
+ 
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+
+%files
+%defattr(-,root,root,-)
+%doc README COPYING examples
+%{python_sitearch}/PyMTP*
+%{python_sitearch}/%{module}*
+
+
+%changelog
+* Mon Nov 01 2010 Ville-Pekka Vainio <vpivaini AT cs.helsinki.fi> - 0.0.4-0.3
+- Make the package arch-dependent and depend on the libmtp.so.8 soname
+- Remove the shebang from pylint.py
+
+* Fri Oct 15 2010 Ville-Pekka Vainio <vpivaini AT cs.helsinki.fi> - 0.0.4-0.2
+- Use Debian's patch, which also fixes the examples
+- Add Requires: libmtp
+
+* Wed Oct 13 2010 Ville-Pekka Vainio <vpivaini AT cs.helsinki.fi> - 0.0.4-0.1
+- Initial Fedora package
diff --git a/sources b/sources
index e69de29..8416c76 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+5eff39cbcc2e073228df04fe1ab1fce8  pymtp-latest.tar.bz2


More information about the scm-commits mailing list