CLI: Fix subscribe/unsubscribe when list has not been loaded yet
This commit is contained in:
parent
795d044e24
commit
6a10e3c9a0
27
bin/gpo
27
bin/gpo
|
@ -294,7 +294,7 @@ class gPodderCli(object):
|
|||
podcasts = self._model.get_podcasts()
|
||||
opml.Exporter(filename).write(podcasts)
|
||||
|
||||
def get_podcast(self, url, create=False):
|
||||
def get_podcast(self, url, create=False, check_only=False):
|
||||
"""Get a specific podcast by URL
|
||||
|
||||
Returns a podcast object for the URL or None if
|
||||
|
@ -304,16 +304,27 @@ class gPodderCli(object):
|
|||
if url is None:
|
||||
self._error(_('Invalid url: %s') % url)
|
||||
return None
|
||||
|
||||
podcast = self._model.load_podcast(url, create=create, \
|
||||
|
||||
# Subscribe to new podcast
|
||||
if create:
|
||||
return self._model.load_podcast(url, create=True,
|
||||
max_episodes=self._config.max_episodes_per_feed)
|
||||
if podcast is None:
|
||||
|
||||
# Load existing podcast
|
||||
for podcast in self._model.get_podcasts():
|
||||
if podcast.url == url:
|
||||
return podcast
|
||||
|
||||
if not check_only:
|
||||
self._error(_('You are not subscribed to %s.') % url)
|
||||
return None
|
||||
|
||||
return podcast
|
||||
return None
|
||||
|
||||
def subscribe(self, url, title=None):
|
||||
existing = self.get_podcast(url, check_only=True)
|
||||
if existing is not None:
|
||||
self._error(_('Already subscribed to %s.') % existing.url)
|
||||
return True
|
||||
|
||||
try:
|
||||
podcast = self.get_podcast(url, create=True)
|
||||
if podcast is None:
|
||||
|
@ -324,6 +335,7 @@ class gPodderCli(object):
|
|||
podcast.rename(title)
|
||||
podcast.save()
|
||||
except Exception, e:
|
||||
logger.warn('Cannot subscribe: %s', e, exc_info=True)
|
||||
if hasattr(e, 'strerror'):
|
||||
self._error(e.strerror)
|
||||
else:
|
||||
|
@ -824,6 +836,7 @@ def stylize(s):
|
|||
return s
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger(__name__)
|
||||
cli = gPodderCli()
|
||||
args = sys.argv[1:]
|
||||
if args:
|
||||
|
|
|
@ -1349,7 +1349,7 @@ class Model(object):
|
|||
|
||||
def load_podcast(self, url, create=True, authentication_tokens=None,
|
||||
max_episodes=0):
|
||||
assert all(url != podcast.url for podcast in self.children)
|
||||
assert all(url != podcast.url for podcast in self.get_podcasts())
|
||||
return self.PodcastClass.load(self, url, create,
|
||||
authentication_tokens,
|
||||
max_episodes)
|
||||
|
|
Loading…
Reference in New Issue