Merge lp:~dobey/rhythmbox-ubuntuone/highlander into lp:rhythmbox-ubuntuone

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 114
Merged at revision: 114
Proposed branch: lp:~dobey/rhythmbox-ubuntuone/highlander
Merge into: lp:rhythmbox-ubuntuone
Diff against target: 139 lines (+12/-55)
2 files modified
ubuntuone/MusicStoreWidget.py (+7/-44)
ubuntuone/ubuntuone.py (+5/-11)
To merge this branch: bzr merge lp:~dobey/rhythmbox-ubuntuone/highlander
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+98214@code.launchpad.net

Commit message

There Can Be Only One library path location
Remove the unnecessary symlink logic and only use U1LIBRARYPATH

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+0 because there can be only one.

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

It's a kind of magic!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/MusicStoreWidget.py'
2--- ubuntuone/MusicStoreWidget.py 2012-03-15 20:16:12 +0000
3+++ ubuntuone/MusicStoreWidget.py 2012-03-19 15:02:17 +0000
4@@ -24,7 +24,6 @@
5 from gi.repository.UbuntuOneUI import MusicStore as U1MusicStore
6 # pylint: enable=E0611,F0401
7
8-from dirspec import basedir
9 from gettext import lgettext as _
10
11 gettext.bindtextdomain("rhythmbox-ubuntuone", "/usr/share/locale")
12@@ -56,7 +55,6 @@
13 self.db = None
14 self.shell = None
15 self.source = None
16- self.u1_library_symlink = None
17 self.entry_type = U1EntryType()
18
19 def activate(self, shell):
20@@ -86,9 +84,6 @@
21 self.source.props.query_model = RB.RhythmDBQueryModel.new_empty(
22 self.db)
23
24- # Do these every time
25- self.add_u1_library()
26-
27 def deactivate(self, shell):
28 """Plugin shutdown."""
29 # remove source
30@@ -106,22 +101,17 @@
31 pass
32
33 def _udf_path_to_library_uri(self, path):
34- """Calculate the path in the library.
35- Since the library is accessed via the created symlink, but the path
36- passed to us is to a file in the actual music store UDF, we need to
37- work out the path inside the library, i.e., what the path to that file
38- is via the symlink."""
39+ """Build a URI from the path for the song in the library."""
40 if path.startswith(U1LIBRARYPATH):
41- subpath = path[len(U1LIBRARYPATH):]
42+ library_path = path
43 else:
44 subpath = path
45- if subpath.startswith("/"):
46- subpath = subpath[1:]
47- library_path = os.path.join(self.u1_library_symlink, subpath)
48+ if subpath.startswith("/"):
49+ subpath = subpath[1:]
50+ library_path = os.path.join(U1LIBRARYPATH, subpath)
51 # convert path to URI. Don't use urllib for this; Python and
52 # glib escape URLs differently. gio does it the glib way.
53- library_uri = Gio.File.new_for_path(library_path).get_uri()
54- return library_uri
55+ return Gio.File.new_for_path(library_path).get_uri()
56
57 def download_finished(self, source, path):
58 """A file is finished downloading"""
59@@ -158,34 +148,7 @@
60 player = self.shell.get_property('shell-player')
61 player.stop()
62 player.play_entry(entry, self.source)
63-
64- def add_u1_library(self):
65- """Add the U1 library if not listed in RB and re-add if changed."""
66- u1_library_path_folder = basedir.save_data_path("ubuntuone")
67- # Ensure that we can write to the folder, because syncdaemon creates it
68- # with no write permissions
69- os.chmod(u1_library_path_folder,
70- os.stat(u1_library_path_folder)[stat.ST_MODE] | stat.S_IWUSR)
71- # Translators: this is the name under Music for U1 music in Rhythmbox
72- u1_library_path = os.path.join(u1_library_path_folder,
73- _("Purchased from Ubuntu One"))
74- if not os.path.islink(u1_library_path):
75- if not os.path.exists(u1_library_path):
76- print "Attempting to symlink %s to %s" % (U1LIBRARYPATH,
77- u1_library_path)
78- os.symlink(U1LIBRARYPATH, u1_library_path)
79- else:
80- # something that isn't a symlink already exists. That's not
81- # supposed to happen.
82- # Write a warning and carry on.
83- print ("Warning: library location %s existed. It should have "
84- "been a symlink to %s, and it wasn't. This isn't supposed "
85- "to happen. Carrying on anyway, on the assumption that "
86- "you know what you're doing. If this is a problem, then "
87- "delete or rename %s.") % (u1_library_path, U1LIBRARYPATH,
88- u1_library_path)
89- self.u1_library_symlink = u1_library_path
90-
91+
92
93 class U1Source(RB.Source):
94 """A Rhythmbox source widget for the U1 Music Store."""
95
96=== modified file 'ubuntuone/ubuntuone.py'
97--- ubuntuone/ubuntuone.py 2012-01-27 22:34:42 +0000
98+++ ubuntuone/ubuntuone.py 2012-03-19 15:02:17 +0000
99@@ -14,14 +14,13 @@
100 # <http://www.gnu.org/licenses/>.
101 """The Ubuntu One Rhythmbox plugin."""
102
103-import os
104-
105+from dirspec.basedir import xdg_config_home
106 # pylint: disable=E0611
107-from gi.repository import Gio, GLib, GObject, Peas
108+from gi.repository import Gio, GObject, Peas
109 # pylint: enable=E0611
110
111 # pylint: disable=W0403
112-from MusicStoreWidget import U1MusicStoreWidget
113+from MusicStoreWidget import U1MusicStoreWidget, U1LIBRARYPATH
114 # pylint: enable=W0403
115
116
117@@ -33,11 +32,6 @@
118 def __init__(self):
119 GObject.GObject.__init__(self)
120
121- # The folder where files get stored
122- self.u1_library_path_url = 'file://{0}'.format(
123- os.path.join(GLib.get_home_dir(),
124- '.ubuntuone',
125- 'Purchased from Ubuntu One'))
126 # RhythmDB settings so we can handle changes
127 self.rdbconf = Gio.Settings('org.gnome.rhythmbox.rhythmdb')
128 self.rdbconf.connect('changed::locations', self._locations_changed)
129@@ -48,8 +42,8 @@
130 def _locations_changed(self, *args, **kwargs):
131 """Handle the locations setting being changed."""
132 libraries = self.rdbconf.get_strv('locations')
133- if self.u1_library_path_url not in libraries:
134- libraries.append(self.u1_library_path_url)
135+ if U1LIBRARYPATH not in libraries:
136+ libraries.append(U1LIBRARYPATH)
137 self.rdbconf.set_strv('locations', libraries)
138
139 def do_activate(self):

Subscribers

People subscribed via source and target branches