From 59338752a49eed0b76c40165d136010a0d83315b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 6 Mar 2019 16:05:19 +0100 Subject: [PATCH] PEP8ness --- git_redmine.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/git_redmine.py b/git_redmine.py index 25a17d8..c6ccc5f 100644 --- a/git_redmine.py +++ b/git_redmine.py @@ -4,6 +4,8 @@ # pip install --user python-redmine click +from __future__ import print_function + import os import re import git @@ -80,9 +82,9 @@ def get_issue(issue_number=None): api = get_redmine_api() try: issue = api.issue.get(issue_number) - except: + except Exception: raise click.UsageError( - 'Cannot find issue %s' % issue_number) + 'Cannot find issue %s' % issue_number) return issue @@ -93,9 +95,9 @@ def get_current_issue(): issue_number = splitted[-1].split('-')[0] try: issue_number = int(issue_number) - except: + except Exception: raise click.UsageError( - 'Cannot find an issue number in current branch name %s' % branch_name) + 'Cannot find an issue number in current branch name %s' % branch_name) return issue_number @@ -119,8 +121,8 @@ def get_patches(number_of_commits=0): def helper(): for path in glob.glob(os.path.join(tempdir, '*.patch')): yield { - 'path': path, - 'filename': os.path.basename(path), + 'path': path, + 'filename': os.path.basename(path), } return list(helper()) @@ -132,6 +134,7 @@ def redmine(): ''' pass + @redmine.command() def shell(): import IPython @@ -152,13 +155,14 @@ def project(ctx): project = get_current_project() click.echo('Current project %s' % project) + def apply_attachments(repo, issue): if not issue.attachments.total_count: return - print 'Currently attached patches' + print('Currently attached patches') attachments = sorted(issue.attachments, key=lambda a: a.id) for i, attachment in enumerate(attachments): - print i, attachment.created_on, '%6d bytes' % attachment.filesize, attachment.filename + print(i, attachment.created_on, '%6d bytes' % attachment.filesize, attachment.filename) while True: indexes = click.prompt('Which patch would you like to apply (id separated by spaces) ?', type=str, default='') try: @@ -169,7 +173,7 @@ def apply_attachments(repo, issue): if not all(i < len(attachments) for i in indexes): raise ValueError('invalid values', indexes) except Exception as e: - print 'error:', e + print('error:', e) continue else: break @@ -180,8 +184,8 @@ def apply_attachments(repo, issue): p = repo.git.execute(['git', 'am'], istream=subprocess.PIPE, as_process=True) p.communicate(content) except Exception as e: - print e - print 'Applying patch', index, attachment.filename, 'failed, please fix it.' + print(e) + print('Applying patch', index, attachment.filename, 'failed, please fix it.') break @@ -212,7 +216,8 @@ def take(issue_number): branch.checkout() click.echo('Moved to branch %s' % branch_name) current_user = api.user.get('current') - if (not hasattr(issue, 'assigned_to') or issue.assigned_to.id != current_user.id) and click.confirm('Do you want to assign the issue to yourself ?'): + if ((not hasattr(issue, 'assigned_to') or issue.assigned_to.id != current_user.id) + and click.confirm('Do you want to assign the issue to yourself ?')): issue.assigned_to_id = current_user.id issue.save() if new: