Skip to content

Commit

Permalink
Apply flake8 linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
splewis committed Nov 25, 2016
1 parent 925c065 commit 819b6ed
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = D203
exclude = .git,__pycache__,templates
max-line-length = 99
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ before_script:
- mysql -e 'create database test_db;'

script:
- flake8 --count get5/
- ./test.sh
13 changes: 9 additions & 4 deletions get5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import flask.ext.sqlalchemy
import flask.ext.openid
import flask_limiter
import requests

# Import the Flask Framework
app = Flask(__name__, instance_relative_config=True)
Expand All @@ -52,7 +51,7 @@

# Setup database connection
db = flask.ext.sqlalchemy.SQLAlchemy(app)
from models import User, Team, GameServer, Match, MapStats, PlayerStats
from models import User, Team, GameServer, Match, MapStats, PlayerStats # noqa: E402

# Setup rate limiting
limiter = flask_limiter.Limiter(
Expand Down Expand Up @@ -111,7 +110,8 @@ def login():
def create_or_login(resp):
match = _steam_id_re.search(resp.identity_url)
steam_id = match.group(1)
if (not steam_id) or ('WHITELISTED_IDS' in app.config and steam_id not in app.config['WHITELISTED_IDS']):
is_whitelisted = (steam_id in config_setting('WHITELISTED_IDS'))
if (not steam_id) or (config_setting('WHITELISTED_IDS') and is_whitelisted):
return 'Sorry, you don\'t have access to this webpanel'

g.user = User.get_or_create(steam_id)
Expand Down Expand Up @@ -202,13 +202,15 @@ def metrics():
@cache.cached(timeout=300)
def get_metrics():
values = []

def add_val(name, value):
values.append((name, value))

add_val('Registered users', User.query.count())
add_val('Saved teams', Team.query.count())
add_val('Matches created', Match.query.count())
add_val('Completed matches', Match.query.filter(Match.end_time != None).count())
add_val('Completed matches', Match.query.filter(
Match.end_time is not None).count())
add_val('Servers added', GameServer.query.count())
add_val('Maps with stats saved', MapStats.query.count())
add_val('Unique players', PlayerStats.query.distinct().count())
Expand All @@ -230,8 +232,11 @@ def add_val(name, value):
'DEFAULT_PAGE': '/matches',
'ADMINS_ACCESS_ALL_MATCHES': False,
'PUBLIC_TEAMS_EXPORTED': True,
'WHITELISTED_IDS': [],
'ADMIN_IDS': [],
}


def config_setting(key):
if key in app.config:
return app.config[key]
Expand Down
16 changes: 11 additions & 5 deletions get5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def match_map_finish(matchid, mapnumber):
return 'Success'


@api_blueprint.route('/match/<int:matchid>/map/<int:mapnumber>/player/<steamid64>/update', methods=['POST'])
@api_blueprint.route(
'/match/<int:matchid>/map/<int:mapnumber>/player/<steamid64>/update',
methods=['POST'])
@limiter.limit('100 per minute', key_func=rate_limit_key)
def match_map_update_player(matchid, mapnumber, steamid64):
match = Match.query.get_or_404(matchid)
Expand Down Expand Up @@ -185,10 +187,14 @@ def match_map_update_player(matchid, mapnumber, steamid64):
player_stats.v3 = as_int(request.values.get('v3'))
player_stats.v4 = as_int(request.values.get('v4'))
player_stats.v5 = as_int(request.values.get('v5'))
player_stats.firstkill_t = as_int(request.values.get('firstkill_t'))
player_stats.firstkill_ct = as_int(request.values.get('firstkill_ct'))
player_stats.firstdeath_t = as_int(request.values.get('firstdeath_t'))
player_stats.firstdeath_ct = as_int(request.values.get('firstdeath_ct'))
player_stats.firstkill_t = as_int(
request.values.get('firstkill_t'))
player_stats.firstkill_ct = as_int(
request.values.get('firstkill_ct'))
player_stats.firstdeath_t = as_int(
request.values.get('firstdeath_t'))
player_stats.firstdeath_ct = as_int(
request.values.get('firstdeath_ct'))

db.session.commit()
else:
Expand Down
3 changes: 2 additions & 1 deletion get5/get5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def create_test_data(self):
team1 = Team.create(user, 'EnvyUs', 'fr', 'nv', ['76561198053858673'])
team2 = Team.create(user, 'Fnatic', 'se', 'fntc',
['76561198053858673'])
server = GameServer.create(user, 'myserver1', '127.0.0.1', '27015', 'password')
server = GameServer.create(
user, 'myserver1', '127.0.0.1', '27015', 'password')
server.in_use = True

GameServer.create(user, 'myserver2', '127.0.0.1', '27016', 'password')
Expand Down
1 change: 0 additions & 1 deletion get5/logos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import glob
import ntpath
import os


Expand Down
10 changes: 7 additions & 3 deletions get5/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ class MatchForm(Form):

team1_string = StringField('Team 1 title text',
default='',
validators=[validators.Length(min=-1, max=Match.team1_string.type.length)])
validators=[validators.Length(min=-1,
max=Match.team1_string.type.length)])

team2_id = SelectField('Team 2', coerce=int,
validators=[validators.required(), different_teams_validator])

team2_string = StringField('Team 2 title text',
default='',
validators=[validators.Length(min=-1, max=Match.team2_string.type.length)])
validators=[validators.Length(min=-1,
max=Match.team2_string.type.length)])

# use_map_veto = CheckBox
mapchoices = [
Expand Down Expand Up @@ -232,7 +234,9 @@ def admintools_check(user, match):
if user is None:
raise BadRequestError('You do not have access to this page')

if user.id != match.user_id and not (user.admin and get5.config_setting('ADMINS_ACCESS_ALL_MATCHES')):
grant_admin_access = user.admin and get5.config_setting(
'ADMINS_ACCESS_ALL_MATCHES')
if user.id != match.user_id and not grant_admin_access:
raise BadRequestError('You do not have access to this page')

if match.finished():
Expand Down
8 changes: 4 additions & 4 deletions get5/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_recent_matches(self, limit=10):

recent_matches = matches.filter(
((Match.team1_id == self.id) | (Match.team2_id == self.id)) & (
Match.cancelled == False) & (Match.start_time != None)
Match.cancelled == False) & (Match.start_time != None) # noqa: E712
).order_by(-Match.id).limit(5)

if recent_matches is None:
Expand Down Expand Up @@ -563,10 +563,10 @@ def get_or_create(matchid, mapnumber, steam_id):
return rv


@cache.memoize(timeout=60*60*24) # 1 day timeout
@cache.memoize(timeout=60 * 60 * 24) # 1 day timeout
def get_steam_name(steam64):
url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={}&steamids={}'.format(
app.config['STEAM_API_KEY'], steam64)
url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={}&steamids={}'
url = url.format(app.config['STEAM_API_KEY'], steam64)
response = requests.get(url)
if response.status_code == 200:
try:
Expand Down
7 changes: 5 additions & 2 deletions get5/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

class ServerForm(Form):
display_name = StringField('Display Name',
validators=[validators.Length(min=-1, max=GameServer.display_name.type.length)])
validators=[
validators.Length(min=-1,
max=GameServer.display_name.type.length)])

ip_string = StringField('Server IP',
validators=[
Expand All @@ -25,7 +27,8 @@ class ServerForm(Form):
rcon_password = StringField('RCON password',
validators=[
validators.required(),
validators.Length(min=-1, max=GameServer.rcon_password.type.length)])
validators.Length(min=-1,
max=GameServer.rcon_password.type.length)])


@server_blueprint.route('/server/create', methods=['GET', 'POST'])
Expand Down
4 changes: 2 additions & 2 deletions get5/steamid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def steam64_from_dom(dom):


def custom_url_to_steam3(url):
if not '?xml=1' in url:
if '?xml=1' not in url:
url += '?xml=1'

try:
Expand Down Expand Up @@ -75,7 +75,7 @@ def auth_to_steam64(auth):
elif auth.startswith('STEAM_'):
return steam2_to_steam64(auth)

elif auth.startswith('7656119') and not 'steam' in auth:
elif auth.startswith('7656119') and 'steam' not in auth:
return True, auth

elif auth.startswith('[U:1:'):
Expand Down
1 change: 0 additions & 1 deletion get5/steamid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ def test_auth_to_steam64(self):
self.assertEqual(actual, expected)



if __name__ == '__main__':
unittest.main()
11 changes: 7 additions & 4 deletions get5/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def valid_auth(form, field):

class TeamForm(Form):
name = StringField('Team Name', validators=[
validators.required(), validators.Length(min=-1, max=Team.name.type.length)])
validators.required(),
validators.Length(min=-1, max=Team.name.type.length)])

flag_choices = [('', 'None')] + countries.country_choices
country_flag = SelectField('Country Flag', choices=flag_choices, default='')
country_flag = SelectField(
'Country Flag', choices=flag_choices, default='')

logo_choices = logos.get_logo_choices()
logo = SelectField('Logo Name', choices=logo_choices, default='')
Expand Down Expand Up @@ -162,7 +164,6 @@ def teams_user(userid):
return 'Public teams are not exported', 400

teams_dict = {}
admin_user = User.get_public_user()
for team in user.teams:
team_dict = {}
team_dict['name'] = team.name
Expand All @@ -176,7 +177,9 @@ def teams_user(userid):
# Render teams page
my_teams = (g.user is not None and userid == g.user.id)
teams = user.teams.paginate(page, 20)
return render_template('teams.html', user=g.user, teams=teams, my_teams=my_teams, page=page, owner=user)
return render_template('teams.html', user=g.user, teams=teams, my_teams=my_teams,
page=page, owner=user)


@team_blueprint.route('/teams/public', methods=['GET'])
def teams_public():
Expand Down
14 changes: 9 additions & 5 deletions get5/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import socket
import subprocess


Expand Down Expand Up @@ -70,9 +71,10 @@ class RconError(ValueError):
pass


def send_rcon_command(host, port, rcon_password, command, raise_errors=False, num_retries=3, timeout=3.0):
from valve.source.rcon import RCON, IncompleteMessageError, AuthenticationError, NoResponseError
import socket
def send_rcon_command(host, port, rcon_password, command,
raise_errors=False, num_retries=3, timeout=3.0):
from valve.source.rcon import (RCON, IncompleteMessageError,
AuthenticationError, NoResponseError)

try:
port = int(port)
Expand Down Expand Up @@ -114,7 +116,9 @@ def strip_rcon_logline(response):

def get_version():
try:
root_dir = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__), '..'))
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=root_dir).strip()
root_dir = os.path.realpath(os.path.join(
os.getcwd(), os.path.dirname(__file__), '..'))
cmd = ['git', 'rev-parse', '--short', 'HEAD']
return subprocess.check_output(cmd, cwd=root_dir).strip()
except (OSError, subprocess.CalledProcessError):
return None
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ astroid==1.4.5
autopep8==1.2.4
blinker==1.4
colorama==0.3.7
configparser==3.5.0
coverage==4.1
docopt==0.6.2
enum==0.4.6
enum34==1.1.6
flake8==3.2.1
Flask==0.10.1
Flask-Assets==0.11
Flask-Cache==0.13.1
Expand All @@ -17,16 +19,19 @@ Flask-OpenID==1.2.5
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
Flask-Testing==0.4.2
Flask-Uploads==0.2.1
Flask-WTF==0.12
itsdangerous==0.24
Jinja2==2.8
lazy-object-proxy==1.2.2
limits==1.1.1
Mako==1.0.4
MarkupSafe==0.23
mccabe==0.5.2
monotonic==1.1
MySQL-python==1.2.5
pep8==1.7.0
pycodestyle==2.2.0
pyflakes==1.2.3
pylint==1.5.5
python-editor==1.0
Expand Down

0 comments on commit 819b6ed

Please sign in to comment.