From 8d0b1ee81377ed3180346e51f42ee783f349f2fb Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Jun 01 2016 07:28:25 +0000 Subject: Fixed pep8 warnings Signed-off-by: Abhijeet Kasurde --- diff --git a/check-cache-coverage.py b/check-cache-coverage.py index 8aad708..0f6c6f7 100755 --- a/check-cache-coverage.py +++ b/check-cache-coverage.py @@ -40,4 +40,3 @@ sys.stdout.flush() total = empty + full print full, "cache values found. ", empty, "are missing." print full / float(total) * 100, "percent cache coverage." - diff --git a/hubs/app.py b/hubs/app.py index 1a77545..fe661ab 100755 --- a/hubs/app.py +++ b/hubs/app.py @@ -19,6 +19,7 @@ from hubs.utils import username2avatar app = flask.Flask(__name__) + # Register some useful global filters. def days_since(then): return (datetime.datetime.utcnow() - then).days @@ -33,6 +34,7 @@ logging.basicConfig() # the right tag to link people to. AGPL ftw. SOURCE_URL = 'https://pagure.io/fedora-hubs/blob/develop/f'#/hubs/widgets/badges.py' + app.config.from_object('hubs.default_config') if 'HUBS_CONFIG' in os.environ: app.config.from_envvar('HUBS_CONFIG') @@ -222,7 +224,7 @@ def hub_edit_post(name): error = True if not is_js: flask.flash( - 'Could not save your changes to the database '\ + 'Could not save your changes to the database ' 'if the error persists, please warn an admin', 'error') if is_js: @@ -327,7 +329,7 @@ def hub_add_widget_post(name): except Exception as err: print err flask.flash( - 'Could not save the configuration to the database '\ + 'Could not save the configuration to the database ' 'if the error persists, please warn an admin', 'error') @@ -398,7 +400,7 @@ def widget_edit_post(hub, idx): session.commit() except Exception as err: flask.flash( - 'Could not save the configuration to the database '\ + 'Could not save the configuration to the database ' 'if the error persists, please warn an admin', 'error') return flask.redirect(flask.url_for('hub', name=hub)) @@ -414,7 +416,7 @@ def widget_edit_delete(hub, idx): session.commit() except Exception as err: flask.flash( - 'Could not delete this widget from this hub in the database '\ + 'Could not delete this widget from this hub in the database ' 'if the error persists, please warn an admin', 'error') return flask.redirect(flask.url_for('hub_edit', name=hub)) @@ -532,7 +534,7 @@ def check_auth(): def get_hub(session, name): """ Utility shorthand to get a hub and 404 if not found. """ hub = session.query(hubs.models.Hub)\ - .filter(hubs.models.Hub.name==name)\ + .filter(hubs.models.Hub.name == name)\ .first() if not hub: diff --git a/hubs/backend/triage.py b/hubs/backend/triage.py index fac1bb0..ad86221 100755 --- a/hubs/backend/triage.py +++ b/hubs/backend/triage.py @@ -37,6 +37,7 @@ import logging import logging.config log = logging.getLogger('hubs.backend.triage') + def triage(session, outbound, msg): topic = msg['topic'] category = topic.split('.')[3] @@ -88,7 +89,8 @@ def main(args): inbound_name = config['hubs.redis.triage-queue-name'] outbound_name = config['hubs.redis.work-queue-name'] - log.info("Triage proc starting. Moving from %r to %r." % (inbound_name, outbound_name)) + log.info("Triage proc starting. Moving from %r to %r." + % (inbound_name, outbound_name)) inbound = retask.queue.Queue(inbound_name) inbound.connect() diff --git a/hubs/tests/test_widgets/__init__.py b/hubs/tests/test_widgets/__init__.py index 1e917ed..38d77af 100644 --- a/hubs/tests/test_widgets/__init__.py +++ b/hubs/tests/test_widgets/__init__.py @@ -62,7 +62,6 @@ class WidgetTest(unittest.TestCase): _config=json.dumps({'calendar': team})) hub.widgets.append(widget) - # TODO - test that it is in the registry # TODO - test that it has all the things it needs diff --git a/hubs/widgets/about.py b/hubs/widgets/about.py index 2383081..c1ff1f6 100755 --- a/hubs/widgets/about.py +++ b/hubs/widgets/about.py @@ -5,11 +5,11 @@ from hubs.widgets import templating import hubs.validators as validators - chrome = panel(" About") template = templating.environment.get_template('templates/about.html') position = 'both' + @argument(name="text", default="I am a Fedora user, and this is my about", validator=validators.text, help="Text about a user.") diff --git a/hubs/widgets/badges.py b/hubs/widgets/badges.py index 4ddbb3d..c5a18d0 100755 --- a/hubs/widgets/badges.py +++ b/hubs/widgets/badges.py @@ -13,6 +13,7 @@ chrome = panel("Badges") template = templating.environment.get_template('templates/badges.html') position = 'right' + @argument(name="username", default=None, validator=validators.username, diff --git a/hubs/widgets/dummy.py b/hubs/widgets/dummy.py index f25f65a..2e73bca 100755 --- a/hubs/widgets/dummy.py +++ b/hubs/widgets/dummy.py @@ -9,6 +9,7 @@ chrome = panel("This is a dummy widget") template = templating.environment.get_template('templates/dummy.html') position = 'both' + @argument(name="text", default="Lorem ipsum dolor...", validator=validators.text, help="Some dummy text to display.") diff --git a/hubs/widgets/fedmsgstats.py b/hubs/widgets/fedmsgstats.py index 9cd15fd..986951b 100755 --- a/hubs/widgets/fedmsgstats.py +++ b/hubs/widgets/fedmsgstats.py @@ -33,8 +33,10 @@ def data(session, widget, username): fedmsgs_text=commas(fedmsgs), subscribers_text=commas(len(subscribers)), subscribed_text=commas(len(sub_list)), - hub_subscribe_url=flask.url_for('hub_subscribe', hub=widget.hub.name), - hub_unsubscribe_url=flask.url_for('hub_unsubscribe', hub=widget.hub.name), + hub_subscribe_url=flask.url_for( + 'hub_subscribe', hub=widget.hub.name), + hub_unsubscribe_url=flask.url_for( + 'hub_unsubscribe', hub=widget.hub.name), ) diff --git a/hubs/widgets/feed.py b/hubs/widgets/feed.py index 282a400..f40e453 100755 --- a/hubs/widgets/feed.py +++ b/hubs/widgets/feed.py @@ -40,6 +40,7 @@ paths = fmn.lib.load_rules(root='fmn.rules') template = templating.environment.get_template('templates/feed.html') position = 'left' + def apply_markup(match): markup = match['subtitle'] for username in match['usernames']: @@ -62,12 +63,13 @@ def apply_markup(match): return markup + @argument(name="username", default=None, validator=validators.username, help="A FAS username.") @argument(name="fmn_context", - default="irc", # TODO - Make this 'hubs', or... + default="irc", # TODO - Make this 'hubs', or... validator=validators.fmn_context, help="A FMN context.") def data(session, widget, username, fmn_context): diff --git a/hubs/widgets/githubissues.py b/hubs/widgets/githubissues.py index 2bd6c87..295c76b 100755 --- a/hubs/widgets/githubissues.py +++ b/hubs/widgets/githubissues.py @@ -15,32 +15,33 @@ position = 'right' validator=validators.github_organization, help="Github Organization or username") def data(session, widget, display_number, org, repo): - url = '/'.join(['https://api.github.com/repos',org,repo,"issues"]) - issue_response = requests.get(url) - data = issue_response.json() - all_issues = list() - for i in range(0,10): - issue_details=dict() - issue_num=data[i]['number'] - issue_title=data[i]['title'] - issue_openedby=data[i]['user']['login'] - if(data[i]['assignee']!=None): - issue_assignee=data[i]['assignee']['login'] - else: - issue_assignee=data[i]['assignee'] - issue_details['num']=issue_num - issue_details['title']=issue_title - issue_details['openedby']=issue_openedby - issue_details['assignee']=issue_assignee - all_issues.append(issue_details) - all_issues.reverse() - return dict( - org=org, - repo=repo, - all_issues=all_issues, - display_number=display_number, - ) + url = '/'.join(['https://api.github.com/repos', org, repo, "issues"]) + issue_response = requests.get(url) + data = issue_response.json() + all_issues = list() + for i in range(0, 10): + issue_details = dict() + issue_num = data[i]['number'] + issue_title = data[i]['title'] + issue_openedby = data[i]['user']['login'] + if(data[i]['assignee'] is not None): + issue_assignee = data[i]['assignee']['login'] + else: + issue_assignee = data[i]['assignee'] + issue_details['num'] = issue_num + issue_details['title'] = issue_title + issue_details['openedby'] = issue_openedby + issue_details['assignee'] = issue_assignee + all_issues.append(issue_details) + all_issues.reverse() + return dict( + org=org, + repo=repo, + all_issues=all_issues, + display_number=display_number, + ) + @hint() def should_invalidate(message, session, widget): - raise NotImplementedError + raise NotImplementedError diff --git a/hubs/widgets/linechart.py b/hubs/widgets/linechart.py index 2c5562f..f12ef8f 100755 --- a/hubs/widgets/linechart.py +++ b/hubs/widgets/linechart.py @@ -25,8 +25,10 @@ def data(session, widget, username): 'Bodhi', 'faf', 'kerneltest', 'github', 'Trac', 'meetbot', 'planet', 'fedocal', 'hotness'] categories = [c.lower() for c in categories] - categories = "&".join(['category=%s' % c for c in categories ]) - url = "https://apps.fedoraproject.org/datagrepper/charts/stackedline?delta=604800&N=12&style=clean&height=300&fill=true&user={username}&split_on=categories" + categories = "&".join(['category=%s' % c for c in categories]) + url = "https://apps.fedoraproject.org/datagrepper/charts/stackedline" \ + "?delta=604800&N=12&style=clean&height=300&fill=true"\ + "&user={username}&split_on=categories" url = url + "&" + categories url = url.format(username=username) return dict(url=url) diff --git a/hubs/widgets/pagureissues.py b/hubs/widgets/pagureissues.py index 3975253..118f8d5 100755 --- a/hubs/widgets/pagureissues.py +++ b/hubs/widgets/pagureissues.py @@ -29,29 +29,29 @@ def data(session, widget, repo): issue_assignee = None if issue['assignee']: - issue_assignee=issue['assignee']['name'] + issue_assignee = issue['assignee']['name'] issue_project_user = None if 'project' in issue: - issue_project_name = issue['project']['name'] - if issue['project']['parent']: - issue_project_user = issue['project']['user']['username'] - else: - if '/' in repo: - issue_project_name, issue_project_user = repo.split('/', 1) + issue_project_name = issue['project']['name'] + if issue['project']['parent']: + issue_project_user = issue['project']['user']['username'] else: - issue_project_name = repo + if '/' in repo: + issue_project_name, issue_project_user = repo.split('/', 1) + else: + issue_project_name = repo all_issues.append( - dict( - issue_project_name=issue_project_name, - issue_project_user=issue_project_user, - issue_id=issue['id'], - issue_title=issue['title'][:45], - issue_title_full=issue['title'], - issue_openedby=issue['user']['name'], - issue_assignee=issue_assignee, - ) + dict( + issue_project_name=issue_project_name, + issue_project_user=issue_project_user, + issue_id=issue['id'], + issue_title=issue['title'][:45], + issue_title_full=issue['title'], + issue_openedby=issue['user']['name'], + issue_assignee=issue_assignee, + ) ) all_issues.reverse() @@ -65,4 +65,4 @@ def data(session, widget, repo): @hint() def should_invalidate(message, session, widget): - raise NotImplementedError + raise NotImplementedError diff --git a/hubs/widgets/stats.py b/hubs/widgets/stats.py index 319e287..55c90db 100755 --- a/hubs/widgets/stats.py +++ b/hubs/widgets/stats.py @@ -33,7 +33,8 @@ def data(session, widget): hub_unstar_url=flask.url_for('hub_unstar', hub=widget.hub.name), hub_star_url=flask.url_for('hub_star', hub=widget.hub.name), hub_subscribe_url=flask.url_for('hub_subscribe', hub=widget.hub.name), - hub_unsubscribe_url=flask.url_for('hub_unsubscribe', hub=widget.hub.name), + hub_unsubscribe_url=flask.url_for( + 'hub_unsubscribe', hub=widget.hub.name), ) diff --git a/hubs/widgets/workflow/pendingacls.py b/hubs/widgets/workflow/pendingacls.py index 8538999..581bd70 100644 --- a/hubs/widgets/workflow/pendingacls.py +++ b/hubs/widgets/workflow/pendingacls.py @@ -11,7 +11,8 @@ from hubs.widgets.chrome import panel # If 'pending_acls' is empty, then don't render any chrome. chrome = panel('Pending ACL Requests', key='pending_acls') # TODO -- add approve/deny buttons or just link through to pkgdb -template = templating.environment.get_template('templates/workflow/pendingacls.html') +template = templating.environment.get_template( + 'templates/workflow/pendingacls.html') position = 'right' diff --git a/populate-from-fas.py b/populate-from-fas.py index 754de7f..8c3531b 100755 --- a/populate-from-fas.py +++ b/populate-from-fas.py @@ -35,12 +35,13 @@ suffix_blacklist = [ for letter in reversed(sorted(list(set(string.letters.lower())))): - session = hubs.models.init(fedmsg_config['hubs.sqlalchemy.uri'], True, True) + session = hubs.models.init( + fedmsg_config['hubs.sqlalchemy.uri'], True, True) print "Querying FAS for the %r users.. hang on." % letter request = fasclient.send_request('/user/list', - req_params={'search': '%s*' % letter}, - auth=True, - timeout=500) + req_params={'search': '%s*' % letter}, + auth=True, + timeout=500) users = request['people'] for user in users: @@ -54,7 +55,8 @@ for letter in reversed(sorted(list(set(string.letters.lower())))): session.commit() # Go back now and set up the groups... - session = hubs.models.init(fedmsg_config['hubs.sqlalchemy.uri'], True, True) + session = hubs.models.init( + fedmsg_config['hubs.sqlalchemy.uri'], True, True) for user in users: hubs_user = hubs.models.User.by_username(session, user['username']) @@ -86,12 +88,11 @@ for letter in reversed(sorted(list(set(string.letters.lower())))): mailing_list_url=membership['mailing_list_url'], ) - - if not hubs_user in hub.subscribers: + if hubs_user not in hub.subscribers: hub.subscribe(session, hubs_user, role='subscriber') - if not hubs_user in hub.members: + if hubs_user not in hub.members: hub.subscribe(session, hubs_user, role='member') - if not hubs_user in hub.owners: + if hubs_user not in hub.owners: if role['role_type'] in [u'administrator', u'sponsor']: hub.subscribe(session, hubs_user, role='owner') diff --git a/populate.py b/populate.py index 5e89881..9762426 100755 --- a/populate.py +++ b/populate.py @@ -23,7 +23,8 @@ for username in users: session.commit() ############## Internationalizationteam -hub = hubs.models.Hub(name='i18n', summary='The Internationalization Team', archived=True) +hub = hubs.models.Hub( + name='i18n', summary='The Internationalization Team', archived=True) session.add(hub) widget = hubs.models.Widget(plugin='stats', index=0)