codestyle in bin dir
This commit is contained in:
parent
e4334eafb4
commit
297387ecbd
|
@ -9,5 +9,5 @@ install:
|
|||
- pip3 install coverage minimock pycodestyle
|
||||
- python3 tools/localdepends.py
|
||||
script:
|
||||
- pycodestyle share src/gpodder tools *.py
|
||||
- pycodestyle share src/gpodder tools bin/* *.py
|
||||
- make releasetest
|
||||
|
|
45
bin/gpo
45
bin/gpo
|
@ -65,7 +65,6 @@
|
|||
"""
|
||||
|
||||
|
||||
|
||||
import sys
|
||||
import collections
|
||||
import os
|
||||
|
@ -138,6 +137,7 @@ from gpodder import model
|
|||
from gpodder import common
|
||||
from gpodder.config import config_value_to_string
|
||||
|
||||
|
||||
def incolor(color_id, s):
|
||||
if have_ansi and cli._config.ui.cli.colors:
|
||||
return '\033[9%dm%s\033[0m' % (color_id, s)
|
||||
|
@ -148,11 +148,13 @@ def incolor(color_id, s):
|
|||
inred, ingreen, inyellow, inblue = (functools.partial(incolor, x)
|
||||
for x in range(1, 5))
|
||||
|
||||
|
||||
def FirstArgumentIsPodcastURL(function):
|
||||
"""Decorator for functions that take a podcast URL as first arg"""
|
||||
setattr(function, '_first_arg_is_podcast', True)
|
||||
return function
|
||||
|
||||
|
||||
def get_terminal_size():
|
||||
if None in (termios, fcntl, struct):
|
||||
return (80, 24)
|
||||
|
@ -163,6 +165,7 @@ def get_terminal_size():
|
|||
rows, cols, xp, yp = struct.unpack('HHHH', x)
|
||||
return rows, cols
|
||||
|
||||
|
||||
class gPodderCli(object):
|
||||
COLUMNS = 80
|
||||
EXIT_COMMANDS = ('quit', 'exit', 'bye')
|
||||
|
@ -210,10 +213,12 @@ class gPodderCli(object):
|
|||
|
||||
# Generator for all prefixes of a given string (longest first)
|
||||
# e.g. ['gpodder', 'gpodde', 'gpodd', 'gpod', 'gpo', 'gp', 'g']
|
||||
mkprefixes = lambda n: (n[:x] for x in range(len(n), 0, -1))
|
||||
def mkprefixes(n):
|
||||
return (n[:x] for x in range(len(n), 0, -1))
|
||||
|
||||
# Return True if the given prefix is unique in "names"
|
||||
is_unique = lambda p: len([n for n in names if n.startswith(p)]) == 1
|
||||
def is_unique(p):
|
||||
return len([n for n in names if n.startswith(p)]) == 1
|
||||
|
||||
for name in names:
|
||||
is_still_unique = True
|
||||
|
@ -240,26 +245,26 @@ class gPodderCli(object):
|
|||
|
||||
def _start_action(self, msg, *args):
|
||||
line = util.convert_bytes(msg % args)
|
||||
if len(line) > self.COLUMNS-7:
|
||||
line = line[:self.COLUMNS-7-3] + '...'
|
||||
if len(line) > self.COLUMNS - 7:
|
||||
line = line[:self.COLUMNS - 7 - 3] + '...'
|
||||
else:
|
||||
line = line + (' '*(self.COLUMNS-7-len(line)))
|
||||
line = line + (' ' * (self.COLUMNS - 7 - len(line)))
|
||||
self._current_action = line
|
||||
print(self._current_action, end='')
|
||||
|
||||
def _update_action(self, progress):
|
||||
if have_ansi:
|
||||
progress = '%3.0f%%' % (progress*100.,)
|
||||
result = '['+inblue(progress)+']'
|
||||
progress = '%3.0f%%' % (progress * 100.,)
|
||||
result = '[' + inblue(progress) + ']'
|
||||
print('\r' + self._current_action + result, end='')
|
||||
|
||||
def _finish_action(self, success=True, skip=False):
|
||||
if skip:
|
||||
result = '['+inyellow('SKIP')+']'
|
||||
result = '[' + inyellow('SKIP') + ']'
|
||||
elif success:
|
||||
result = '['+ingreen('DONE')+']'
|
||||
result = '[' + ingreen('DONE') + ']'
|
||||
else:
|
||||
result = '['+inred('FAIL')+']'
|
||||
result = '[' + inred('FAIL') + ']'
|
||||
|
||||
if have_ansi:
|
||||
print('\r' + self._current_action + result)
|
||||
|
@ -406,7 +411,7 @@ class gPodderCli(object):
|
|||
|
||||
return ' '
|
||||
|
||||
episodes = ('%3d.%s %s %s' % (i+1, ((' %s' % e.guid) if show_guid else ''), status_str(e), e.title)
|
||||
episodes = ('%3d.%s %s %s' % (i + 1, ((' %s' % e.guid) if show_guid else ''), status_str(e), e.title)
|
||||
for i, e in enumerate(podcast.get_all_episodes()))
|
||||
return episodes
|
||||
|
||||
|
@ -687,7 +692,7 @@ class gPodderCli(object):
|
|||
|
||||
def show_list():
|
||||
self._pager('\n'.join('%3d: %s\n %s' %
|
||||
(index+1, title, url if title != url else '')
|
||||
(index + 1, title, url if title != url else '')
|
||||
for index, (title, url) in enumerate(results)))
|
||||
|
||||
show_list()
|
||||
|
@ -713,7 +718,7 @@ class gPodderCli(object):
|
|||
self._error(_('Invalid value.'))
|
||||
continue
|
||||
|
||||
title, url = results[index-1]
|
||||
title, url = results[index - 1]
|
||||
self._info(_('Adding %s...') % title)
|
||||
self.subscribe(url)
|
||||
if not multiple:
|
||||
|
@ -812,11 +817,11 @@ class gPodderCli(object):
|
|||
|
||||
def _checkargs(self, func, command_line):
|
||||
args, varargs, keywords, defaults = inspect.getargspec(func)
|
||||
args.pop(0) # Remove "self" from args
|
||||
args.pop(0) # Remove "self" from args
|
||||
defaults = defaults or ()
|
||||
minarg, maxarg = len(args)-len(defaults), len(args)
|
||||
minarg, maxarg = len(args) - len(defaults), len(args)
|
||||
|
||||
if len(command_line) < minarg or (len(command_line) > maxarg and \
|
||||
if len(command_line) < minarg or (len(command_line) > maxarg and
|
||||
varargs is None):
|
||||
self._error('Wrong argument count for %s.' % func.__name__)
|
||||
return False
|
||||
|
@ -831,7 +836,6 @@ class gPodderCli(object):
|
|||
|
||||
return None
|
||||
|
||||
|
||||
def _tab_completion(self, text, count):
|
||||
"""Tab completion function for readline"""
|
||||
if readline is None:
|
||||
|
@ -857,7 +861,6 @@ class gPodderCli(object):
|
|||
|
||||
return None
|
||||
|
||||
|
||||
def _parse_single(self, command_line):
|
||||
try:
|
||||
result = self._parse(command_line)
|
||||
|
@ -896,6 +899,7 @@ def stylize(s):
|
|||
s = re.sub(r' - .*', lambda m: ingreen(m.group(0)), s)
|
||||
return s
|
||||
|
||||
|
||||
def main():
|
||||
global logger, cli
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -913,5 +917,6 @@ def main():
|
|||
else:
|
||||
print(__doc__, end='')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
11
bin/gpodder
11
bin/gpodder
|
@ -50,6 +50,7 @@ except ImportError:
|
|||
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
def main():
|
||||
# Paths to important files
|
||||
gpodder_script = sys.argv[0]
|
||||
|
@ -92,10 +93,10 @@ def main():
|
|||
gpodder.images_folder = images_folder
|
||||
gpodder.icon_file = icon_file
|
||||
|
||||
s_usage = 'usage: %%prog [options]\n\n%s' % ( __doc__.strip() )
|
||||
s_version = '%%prog %s' % ( gpodder.__version__ )
|
||||
s_usage = 'usage: %%prog [options]\n\n%s' % (__doc__.strip())
|
||||
s_version = '%%prog %s' % (gpodder.__version__)
|
||||
|
||||
parser = OptionParser( usage = s_usage, version = s_version)
|
||||
parser = OptionParser(usage=s_usage, version=s_version)
|
||||
|
||||
parser.add_option("-v", "--verbose",
|
||||
action="store_true", dest="verbose", default=False,
|
||||
|
@ -114,7 +115,7 @@ def main():
|
|||
gpodder.ui.gtk = True
|
||||
gpodder.ui.python3 = True
|
||||
|
||||
gpodder.ui.unity = (os.environ.get('DESKTOP_SESSION', 'unknown').lower() in
|
||||
gpodder.ui.unity = (os.environ.get('DESKTOP_SESSION', 'unknown').lower() in
|
||||
('ubuntu', 'ubuntu-2d'))
|
||||
|
||||
from gpodder import log
|
||||
|
@ -154,6 +155,6 @@ def main():
|
|||
else:
|
||||
logger.error('No GUI selected.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -128,4 +128,3 @@ if result in 'Yy':
|
|||
sys.exit(1)
|
||||
|
||||
print('Done. Have fun with gPodder 3!')
|
||||
|
||||
|
|
Loading…
Reference in New Issue