parent
ec0df6544a
commit
7188ef9f2f
|
@ -201,7 +201,7 @@ class DownloadURLOpener(urllib.request.FancyURLopener):
|
|||
# FYI: The omission of "%" in the list is to avoid double escaping!
|
||||
ESCAPE_CHARS = dict((ord(c), '%%%x' % ord(c)) for c in ' <>#"{}|\\^[]`')
|
||||
|
||||
def __init__( self, channel):
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
self._auth_retry_counter = 0
|
||||
urllib.request.FancyURLopener.__init__(self, None)
|
||||
|
@ -324,7 +324,7 @@ class DownloadURLOpener(urllib.request.FancyURLopener):
|
|||
|
||||
# end code based on urllib.py
|
||||
|
||||
def prompt_user_passwd( self, host, realm):
|
||||
def prompt_user_passwd(self, host, realm):
|
||||
# Keep track of authentication attempts, fail after the third one
|
||||
self._auth_retry_counter += 1
|
||||
if self._auth_retry_counter > 3:
|
||||
|
@ -333,7 +333,7 @@ class DownloadURLOpener(urllib.request.FancyURLopener):
|
|||
if self.channel.auth_username or self.channel.auth_password:
|
||||
logger.debug('Authenticating as "%s" to "%s" for realm "%s".',
|
||||
self.channel.auth_username, host, realm)
|
||||
return ( self.channel.auth_username, self.channel.auth_password )
|
||||
return (self.channel.auth_username, self.channel.auth_password)
|
||||
|
||||
return (None, None)
|
||||
|
||||
|
|
|
@ -243,10 +243,10 @@ def draw_text_pill(left_text, right_text, x=0, y=0, border=2, radius=14, font_de
|
|||
ctx.stroke()
|
||||
|
||||
ctx.move_to(x + x_border, y + 1 + border)
|
||||
ctx.set_source_rgba( 0, 0, 0, 1)
|
||||
ctx.set_source_rgba(0, 0, 0, 1)
|
||||
PangoCairo.show_layout(ctx, layout_left)
|
||||
ctx.move_to(x - 1 + x_border, y + border)
|
||||
ctx.set_source_rgba( 1, 1, 1, 1)
|
||||
ctx.set_source_rgba(1, 1, 1, 1)
|
||||
PangoCairo.show_layout(ctx, layout_left)
|
||||
|
||||
if right_text is not None:
|
||||
|
@ -276,10 +276,10 @@ def draw_text_pill(left_text, right_text, x=0, y=0, border=2, radius=14, font_de
|
|||
ctx.stroke()
|
||||
|
||||
ctx.move_to(x + left_side_width + x_border, y + 1 + border)
|
||||
ctx.set_source_rgba( 0, 0, 0, 1)
|
||||
ctx.set_source_rgba(0, 0, 0, 1)
|
||||
PangoCairo.show_layout(ctx, layout_right)
|
||||
ctx.move_to(x - 1 + left_side_width + x_border, y + border)
|
||||
ctx.set_source_rgba( 1, 1, 1, 1)
|
||||
ctx.set_source_rgba(1, 1, 1, 1)
|
||||
PangoCairo.show_layout(ctx, layout_right)
|
||||
|
||||
return surface
|
||||
|
|
|
@ -279,9 +279,11 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
action.connect('activate', self.on_item_view_hide_boring_podcasts_toggled)
|
||||
g.add_action(action)
|
||||
|
||||
value = EpisodeListModel.VIEWS[self.config.episode_list_view_mode or EpisodeListModel.VIEW_ALL]
|
||||
value = EpisodeListModel.VIEWS[
|
||||
self.config.episode_list_view_mode or EpisodeListModel.VIEW_ALL]
|
||||
action = Gio.SimpleAction.new_stateful(
|
||||
'viewEpisodes', GLib.VariantType.new('s'), GLib.Variant.new_string(value))
|
||||
'viewEpisodes', GLib.VariantType.new('s'),
|
||||
GLib.Variant.new_string(value))
|
||||
action.connect('activate', self.on_item_view_episodes_changed)
|
||||
g.add_action(action)
|
||||
|
||||
|
@ -1308,7 +1310,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
(x_bin, y_bin) = treeview.get_bin_window().get_position()
|
||||
y -= x_bin
|
||||
y -= y_bin
|
||||
(path, column, rx, ry) = treeview.get_path_at_pos( x, y) or (None,) * 4
|
||||
(path, column, rx, ry) = treeview.get_path_at_pos(x, y) or (None,) * 4
|
||||
|
||||
if not getattr(treeview, TreeViewHelper.CAN_TOOLTIP) or x > 50 or (column is not None and column != treeview.get_columns()[0]):
|
||||
setattr(treeview, TreeViewHelper.LAST_TOOLTIP, None)
|
||||
|
@ -1702,7 +1704,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if event is None or event.button == 3:
|
||||
menu = Gtk.Menu()
|
||||
|
||||
item = Gtk.ImageMenuItem( _('Update podcast'))
|
||||
item = Gtk.ImageMenuItem(_('Update podcast'))
|
||||
item.set_image(Gtk.Image.new_from_icon_name('view-refresh', Gtk.IconSize.MENU))
|
||||
item.set_action_name('win.updateChannel')
|
||||
menu.append(item)
|
||||
|
@ -1726,8 +1728,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
item = Gtk.ImageMenuItem(_('Delete podcast'))
|
||||
item.set_image(Gtk.Image.new_from_icon_name('edit-delete', Gtk.IconSize.MENU))
|
||||
item.connect( 'activate', self.on_itemRemoveChannel_activate)
|
||||
menu.append( item)
|
||||
item.connect('activate', self.on_itemRemoveChannel_activate)
|
||||
menu.append(item)
|
||||
|
||||
result = gpodder.user_extensions.on_channel_context_menu(self.active_channel)
|
||||
if result:
|
||||
|
@ -1947,13 +1949,16 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if downloaded:
|
||||
item = Gtk.CheckMenuItem(_('Archive'))
|
||||
item.set_active(any_locked)
|
||||
item.connect('activate', lambda w: self.on_item_toggle_lock_activate( w, False, not any_locked))
|
||||
item.connect('activate',
|
||||
lambda w: self.on_item_toggle_lock_activate(
|
||||
w, False, not any_locked))
|
||||
menu.append(item)
|
||||
|
||||
menu.append(Gtk.SeparatorMenuItem())
|
||||
# Single item, add episode information menu item
|
||||
item = Gtk.ImageMenuItem(_('Episode details'))
|
||||
item.set_image(Gtk.Image.new_from_icon_name( 'dialog-information', Gtk.IconSize.MENU))
|
||||
item.set_image(Gtk.Image.new_from_icon_name('dialog-information',
|
||||
Gtk.IconSize.MENU))
|
||||
item.set_action_name('win.toggleShownotes')
|
||||
menu.append(item)
|
||||
|
||||
|
@ -2117,8 +2122,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.toolCancel.set_sensitive(True)
|
||||
return (False, False, False, False, False, False)
|
||||
|
||||
( can_play, can_download, can_cancel, can_delete ) = (False,) * 4
|
||||
( is_played, is_locked ) = (False,) * 2
|
||||
(can_play, can_download, can_cancel, can_delete) = (False,) * 4
|
||||
(is_played, is_locked) = (False,) * 2
|
||||
|
||||
open_instead_of_play = False
|
||||
|
||||
|
@ -2870,7 +2875,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if self.active_channel is None:
|
||||
title = _('No podcast selected')
|
||||
message = _('Please select a podcast in the podcasts list to update.')
|
||||
self.show_message( message, title, widget=self.treeChannels)
|
||||
self.show_message(message, title, widget=self.treeChannels)
|
||||
return
|
||||
|
||||
# Dirty hack to check for "All episodes" (see gpodder.gtkui.model)
|
||||
|
@ -3105,7 +3110,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if self.active_channel is None:
|
||||
title = _('No podcast selected')
|
||||
message = _('Please select a podcast in the podcasts list to edit.')
|
||||
self.show_message( message, title, widget=self.treeChannels)
|
||||
self.show_message(message, title, widget=self.treeChannels)
|
||||
return
|
||||
|
||||
gPodderChannel(self.main_window,
|
||||
|
@ -3205,7 +3210,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if self.active_channel is None:
|
||||
title = _('No podcast selected')
|
||||
message = _('Please select a podcast in the podcasts list to remove.')
|
||||
self.show_message( message, title, widget=self.treeChannels)
|
||||
self.show_message(message, title, widget=self.treeChannels)
|
||||
return
|
||||
|
||||
self.remove_podcast_list([self.active_channel])
|
||||
|
@ -3241,11 +3246,15 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
def on_itemExportChannels_activate(self, widget, *args):
|
||||
if not self.channels:
|
||||
title = _('Nothing to export')
|
||||
message = _('Your list of podcast subscriptions is empty. Please subscribe to some podcasts first before trying to export your subscription list.')
|
||||
message = _('Your list of podcast subscriptions is empty. '
|
||||
'Please subscribe to some podcasts first before '
|
||||
'trying to export your subscription list.')
|
||||
self.show_message(message, title, widget=self.treeChannels)
|
||||
return
|
||||
|
||||
dlg = Gtk.FileChooserDialog(title=_('Export to OPML'), parent=self.gPodder, action=Gtk.FileChooserAction.SAVE)
|
||||
dlg = Gtk.FileChooserDialog(title=_('Export to OPML'),
|
||||
parent=self.gPodder,
|
||||
action=Gtk.FileChooserAction.SAVE)
|
||||
dlg.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
|
||||
dlg.add_button(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
|
||||
dlg.set_filter(self.get_opml_filter())
|
||||
|
@ -3253,13 +3262,19 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if response == Gtk.ResponseType.OK:
|
||||
filename = dlg.get_filename()
|
||||
dlg.destroy()
|
||||
exporter = opml.Exporter( filename)
|
||||
exporter = opml.Exporter(filename)
|
||||
if filename is not None and exporter.write(self.channels):
|
||||
count = len(self.channels)
|
||||
title = N_('%(count)d subscription exported', '%(count)d subscriptions exported', count) % {'count':count}
|
||||
self.show_message(_('Your podcast list has been successfully exported.'), title, widget=self.treeChannels)
|
||||
title = N_('%(count)d subscription exported',
|
||||
'%(count)d subscriptions exported',
|
||||
count) % {'count':count}
|
||||
self.show_message(_('Your podcast list has been successfully '
|
||||
'exported.'),
|
||||
title, widget=self.treeChannels)
|
||||
else:
|
||||
self.show_message( _('Could not export OPML to file. Please check your permissions.'), _('OPML export failed'), important=True)
|
||||
self.show_message(_('Could not export OPML to file. '
|
||||
'Please check your permissions.'),
|
||||
_('OPML export failed'), important=True)
|
||||
else:
|
||||
dlg.destroy()
|
||||
|
||||
|
@ -3324,7 +3339,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.treeChannels.set_cursor(path)
|
||||
|
||||
def on_treeChannels_cursor_changed(self, widget, *args):
|
||||
( model, iter ) = self.treeChannels.get_selection().get_selected()
|
||||
(model, iter) = self.treeChannels.get_selection().get_selected()
|
||||
|
||||
if model is not None and iter is not None:
|
||||
old_active_channel = self.active_channel
|
||||
|
@ -3345,7 +3360,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.update_episode_list_model()
|
||||
|
||||
def on_btnEditChannel_clicked(self, widget, *args):
|
||||
self.on_itemEditChannel_activate( widget, args)
|
||||
self.on_itemEditChannel_activate(widget, args)
|
||||
|
||||
def get_podcast_urls_from_selected_episodes(self):
|
||||
"""Get a set of podcast URLs based on the selected episodes"""
|
||||
|
|
|
@ -554,8 +554,8 @@ class PodcastEpisode(PodcastModelObject):
|
|||
return util.file_type_by_extension(self.extension())
|
||||
|
||||
@property
|
||||
def basename( self):
|
||||
return os.path.splitext( os.path.basename( self.url))[0]
|
||||
def basename(self):
|
||||
return os.path.splitext(os.path.basename(self.url))[0]
|
||||
|
||||
@property
|
||||
def pubtime(self):
|
||||
|
|
|
@ -635,7 +635,7 @@ class MP3PlayerDevice(Device):
|
|||
pass
|
||||
try:
|
||||
logger.info('Trying to remove partially copied file: %s' % to_file)
|
||||
os.unlink( to_file)
|
||||
os.unlink(to_file)
|
||||
logger.info('Yeah! Unlinked %s at least..' % to_file)
|
||||
except:
|
||||
logger.error('Error while trying to unlink %s. OH MY!' % to_file)
|
||||
|
@ -761,7 +761,7 @@ class MTPDevice(Device):
|
|||
raise ValueError("Expected + or -")
|
||||
except Exception as exc:
|
||||
logger.warning('WARNING: ignoring invalid time zone information for %s (%s)')
|
||||
return max( 0, _date )
|
||||
return max(0, _date)
|
||||
except Exception as exc:
|
||||
logger.warning('WARNING: the mtp date "%s" can not be parsed against mtp specification (%s)')
|
||||
return None
|
||||
|
|
|
@ -159,17 +159,17 @@ _MIME_TYPES = dict((k, v) for v, k in _MIME_TYPE_LIST)
|
|||
_MIME_TYPES_EXT = dict(_MIME_TYPE_LIST)
|
||||
|
||||
|
||||
def make_directory( path):
|
||||
def make_directory(path):
|
||||
"""
|
||||
Tries to create a directory if it does not exist already.
|
||||
Returns True if the directory exists after the function
|
||||
call, False otherwise.
|
||||
"""
|
||||
if os.path.isdir( path):
|
||||
if os.path.isdir(path):
|
||||
return True
|
||||
|
||||
try:
|
||||
os.makedirs( path)
|
||||
os.makedirs(path)
|
||||
except:
|
||||
logger.warn('Could not create directory: %s', path)
|
||||
return False
|
||||
|
@ -347,7 +347,7 @@ def directory_is_writable(path):
|
|||
return os.path.isdir(path) and os.access(path, os.W_OK)
|
||||
|
||||
|
||||
def calculate_size( path):
|
||||
def calculate_size(path):
|
||||
"""
|
||||
Tries to calculate the size of a directory, including any
|
||||
subdirectories found. The returned value might not be
|
||||
|
@ -357,14 +357,14 @@ def calculate_size( path):
|
|||
if path is None:
|
||||
return 0
|
||||
|
||||
if os.path.dirname( path) == '/':
|
||||
if os.path.dirname(path) == '/':
|
||||
return 0
|
||||
|
||||
if os.path.isfile( path):
|
||||
return os.path.getsize( path)
|
||||
if os.path.isfile(path):
|
||||
return os.path.getsize(path)
|
||||
|
||||
if os.path.isdir( path) and not os.path.islink( path):
|
||||
sum = os.path.getsize( path)
|
||||
if os.path.isdir(path) and not os.path.islink(path):
|
||||
sum = os.path.getsize(path)
|
||||
|
||||
try:
|
||||
for item in os.listdir(path):
|
||||
|
@ -527,7 +527,7 @@ def format_date(timestamp):
|
|||
return _('Yesterday')
|
||||
|
||||
try:
|
||||
diff = int( (time.time() - timestamp) / seconds_in_a_day )
|
||||
diff = int((time.time() - timestamp) / seconds_in_a_day)
|
||||
except:
|
||||
logger.warn('Cannot convert "%s" to date.', timestamp, exc_info=True)
|
||||
return None
|
||||
|
@ -553,19 +553,19 @@ def format_filesize(bytesize, use_si_units=False, digits=2):
|
|||
has a negative value.
|
||||
"""
|
||||
si_units = (
|
||||
( 'kB', 10**3 ),
|
||||
( 'MB', 10**6 ),
|
||||
( 'GB', 10**9 ),
|
||||
('kB', 10**3),
|
||||
('MB', 10**6),
|
||||
('GB', 10**9),
|
||||
)
|
||||
|
||||
binary_units = (
|
||||
( 'KiB', 2**10 ),
|
||||
( 'MiB', 2**20 ),
|
||||
( 'GiB', 2**30 ),
|
||||
('KiB', 2**10),
|
||||
('MiB', 2**20),
|
||||
('GiB', 2**30),
|
||||
)
|
||||
|
||||
try:
|
||||
bytesize = float( bytesize)
|
||||
bytesize = float(bytesize)
|
||||
except:
|
||||
return _('(unknown)')
|
||||
|
||||
|
@ -577,9 +577,9 @@ def format_filesize(bytesize, use_si_units=False, digits=2):
|
|||
else:
|
||||
units = binary_units
|
||||
|
||||
( used_unit, used_value ) = ( 'B', bytesize )
|
||||
(used_unit, used_value) = ('B', bytesize)
|
||||
|
||||
for ( unit, value ) in units:
|
||||
for (unit, value) in units:
|
||||
if bytesize >= value:
|
||||
used_value = bytesize / float(value)
|
||||
used_unit = unit
|
||||
|
@ -944,13 +944,14 @@ def filename_from_url(url):
|
|||
http://s/redirect.mp4?http://serv2/test.mp4 => ("test", ".mp4")
|
||||
"""
|
||||
(scheme, netloc, path, para, query, fragid) = urllib.parse.urlparse(url)
|
||||
(filename, extension) = os.path.splitext(os.path.basename( urllib.parse.unquote(path)))
|
||||
(filename, extension) = os.path.splitext(
|
||||
os.path.basename(urllib.parse.unquote(path)))
|
||||
|
||||
if file_type_by_extension(extension) is not None and not \
|
||||
query.startswith(scheme + '://'):
|
||||
# We have found a valid extension (audio, video)
|
||||
# and the query string doesn't look like a URL
|
||||
return ( filename, extension.lower() )
|
||||
return (filename, extension.lower())
|
||||
|
||||
# If the query string looks like a possible URL, try that first
|
||||
if len(query.strip()) > 0 and query.find('/') != -1:
|
||||
|
@ -961,7 +962,7 @@ def filename_from_url(url):
|
|||
return os.path.splitext(os.path.basename(query_url))
|
||||
|
||||
# No exact match found, simply return the original filename & extension
|
||||
return ( filename, extension.lower() )
|
||||
return (filename, extension.lower())
|
||||
|
||||
|
||||
def file_type_by_extension(extension):
|
||||
|
@ -1007,7 +1008,7 @@ def file_type_by_extension(extension):
|
|||
return None
|
||||
|
||||
|
||||
def get_first_line( s):
|
||||
def get_first_line(s):
|
||||
"""
|
||||
Returns only the first line of a string, stripped so
|
||||
that it doesn't have whitespace before or after.
|
||||
|
@ -1616,7 +1617,7 @@ def relpath(p1, p2):
|
|||
(common,l1,l2) = commonpath(pathsplit(p1), pathsplit(p2))
|
||||
p = []
|
||||
if len(l1) > 0:
|
||||
p = [ ('..' + os.sep) * len(l1) ]
|
||||
p = [('..' + os.sep) * len(l1)]
|
||||
p = p + l2
|
||||
if len(p) is 0:
|
||||
return "."
|
||||
|
|
Loading…
Reference in New Issue