From 6af94df00a78b51076bceec9f947db6cbc3bce96 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Sat, 7 Dec 2019 20:20:40 +0700 Subject: [PATCH] LGTM fixes. Remove unused import and variables --- powerdnsadmin/__init__.py | 2 +- powerdnsadmin/decorators.py | 2 +- powerdnsadmin/lib/utils.py | 16 ++++++++++++---- powerdnsadmin/models/__init__.py | 2 +- powerdnsadmin/models/domain.py | 3 ++- powerdnsadmin/models/server.py | 1 - powerdnsadmin/models/setting.py | 1 - powerdnsadmin/routes/admin.py | 8 +++----- powerdnsadmin/routes/base.py | 2 +- powerdnsadmin/routes/dashboard.py | 6 +++--- powerdnsadmin/routes/domain.py | 8 +++----- powerdnsadmin/routes/user.py | 6 ++---- update_zones.py | 1 - 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/powerdnsadmin/__init__.py b/powerdnsadmin/__init__.py index f4f5540..3f7c17a 100755 --- a/powerdnsadmin/__init__.py +++ b/powerdnsadmin/__init__.py @@ -49,7 +49,7 @@ def create_app(config=None): # HSTS if app.config.get('HSTS_ENABLED'): from flask_sslify import SSLify - _sslify = SSLify(app) + _sslify = SSLify(app) # lgtm [py/unused-import] # Load app's components assets.init_app(app) diff --git a/powerdnsadmin/decorators.py b/powerdnsadmin/decorators.py index e06deff..1486928 100644 --- a/powerdnsadmin/decorators.py +++ b/powerdnsadmin/decorators.py @@ -1,7 +1,7 @@ import base64 import binascii from functools import wraps -from flask import g, redirect, url_for, request, abort, current_app, render_template +from flask import g, request, abort, current_app, render_template from flask_login import current_user from .models import User, ApiKey, Setting, Domain diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index e690b6b..821489f 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -9,7 +9,6 @@ import os from distutils.version import StrictVersion from urllib.parse import urlparse from datetime import datetime, timedelta -from threading import Thread from .certutil import KEY_FILE, CERT_FILE @@ -58,12 +57,18 @@ def fetch_remote(remote_url, r.raise_for_status() except Exception as e: msg = "Returned status {0} and content {1}" - raise RuntimeError('Error while fetching {0}'.format(remote_url)) + raise RuntimeError('Error while fetching {0}. {1}'.format( + remote_url, msg)) return r -def fetch_json(remote_url, method='GET', data=None, params=None, headers=None, timeout=None): +def fetch_json(remote_url, + method='GET', + data=None, + params=None, + headers=None, + timeout=None): r = fetch_remote(remote_url, method=method, data=data, @@ -78,7 +83,10 @@ def fetch_json(remote_url, method='GET', data=None, params=None, headers=None, t if r.status_code == 204: return {} elif r.status_code == 409: - return {'error': 'Resource already exists or conflict', 'http_code': r.status_code} + return { + 'error': 'Resource already exists or conflict', + 'http_code': r.status_code + } try: assert ('json' in r.headers['content-type']) diff --git a/powerdnsadmin/models/__init__.py b/powerdnsadmin/models/__init__.py index 62eccc3..714a198 100644 --- a/powerdnsadmin/models/__init__.py +++ b/powerdnsadmin/models/__init__.py @@ -20,4 +20,4 @@ from .record_entry import RecordEntry def init_app(app): db.init_app(app) - _migrate = Migrate(app, db) + _migrate = Migrate(app, db) # lgtm [py/unused-import] diff --git a/powerdnsadmin/models/domain.py b/powerdnsadmin/models/domain.py index 5929090..31a2cbe 100644 --- a/powerdnsadmin/models/domain.py +++ b/powerdnsadmin/models/domain.py @@ -287,7 +287,8 @@ class Domain(db.Model): account_id = None # add new domain d = Domain() - d.name = domain['name'].rstrip('.') + d.name = domain['name'].rstrip( + '.') # lgtm [py/modification-of-default-value] d.master = str(domain['masters']) d.type = domain['kind'] d.serial = domain['serial'] diff --git a/powerdnsadmin/models/server.py b/powerdnsadmin/models/server.py index 7e32d33..1c1deba 100644 --- a/powerdnsadmin/models/server.py +++ b/powerdnsadmin/models/server.py @@ -3,7 +3,6 @@ from flask import current_app from urllib.parse import urljoin from ..lib import utils -from .base import db from .setting import Setting diff --git a/powerdnsadmin/models/setting.py b/powerdnsadmin/models/setting.py index ee89a14..6f44663 100644 --- a/powerdnsadmin/models/setting.py +++ b/powerdnsadmin/models/setting.py @@ -2,7 +2,6 @@ import sys import pytimeparse from ast import literal_eval from distutils.util import strtobool -from distutils.version import StrictVersion from .base import db diff --git a/powerdnsadmin/routes/admin.py b/powerdnsadmin/routes/admin.py index 85c217f..f23b93a 100644 --- a/powerdnsadmin/routes/admin.py +++ b/powerdnsadmin/routes/admin.py @@ -1,15 +1,13 @@ import re import json import traceback -import datetime from ast import literal_eval from distutils.version import StrictVersion -from flask import Blueprint, render_template, make_response, url_for, current_app, g, session, request, redirect, jsonify, abort -from flask_login import login_user, login_required, current_user +from flask import Blueprint, render_template, make_response, url_for, current_app, request, redirect, jsonify, abort +from flask_login import login_required, current_user -from .base import login_manager from ..decorators import operator_role_required, admin_role_required -from ..models.user import User, Anonymous +from ..models.user import User from ..models.account import Account from ..models.account_user import AccountUser from ..models.role import Role diff --git a/powerdnsadmin/routes/base.py b/powerdnsadmin/routes/base.py index d1df359..8e365bf 100644 --- a/powerdnsadmin/routes/base.py +++ b/powerdnsadmin/routes/base.py @@ -1,6 +1,6 @@ import base64 from flask import render_template, url_for, redirect, session, request, current_app -from flask_login import LoginManager, login_user +from flask_login import LoginManager from ..models.user import User diff --git a/powerdnsadmin/routes/dashboard.py b/powerdnsadmin/routes/dashboard.py index b062b92..877b07e 100644 --- a/powerdnsadmin/routes/dashboard.py +++ b/powerdnsadmin/routes/dashboard.py @@ -1,6 +1,6 @@ -from flask import Blueprint, render_template, make_response, url_for, current_app, request, jsonify, redirect +from flask import Blueprint, render_template, url_for, current_app, request, jsonify, redirect from flask_login import login_required, current_user -from sqlalchemy import not_, or_ +from sqlalchemy import not_ from ..lib.utils import customBoxes from ..models.user import User @@ -33,7 +33,7 @@ def domains_custom(boxId): .outerjoin(Account, Domain.account_id == Account.id) \ .outerjoin(AccountUser, Account.id == AccountUser.account_id) \ .filter( - db.or_( + d( DomainUser.user_id == current_user.id, AccountUser.user_id == current_user.id )) diff --git a/powerdnsadmin/routes/domain.py b/powerdnsadmin/routes/domain.py index e920738..67ed4cc 100644 --- a/powerdnsadmin/routes/domain.py +++ b/powerdnsadmin/routes/domain.py @@ -1,14 +1,12 @@ import re import json import traceback -import datetime from distutils.version import StrictVersion -from flask import Blueprint, render_template, make_response, url_for, current_app, g, session, request, redirect, abort, jsonify -from flask_login import login_user, login_required, current_user +from flask import Blueprint, render_template, make_response, url_for, current_app, request, redirect, abort, jsonify +from flask_login import login_required, current_user -from .base import login_manager from ..decorators import can_create_domain, operator_role_required, can_access_domain, can_configure_dnssec -from ..models.user import User, Anonymous +from ..models.user import User from ..models.account import Account from ..models.setting import Setting from ..models.history import History diff --git a/powerdnsadmin/routes/user.py b/powerdnsadmin/routes/user.py index 6d3d060..4995aad 100644 --- a/powerdnsadmin/routes/user.py +++ b/powerdnsadmin/routes/user.py @@ -1,12 +1,10 @@ import qrcode as qrc import qrcode.image.svg as qrc_svg from io import BytesIO -from flask import Blueprint, request, render_template, make_response, jsonify, redirect, url_for, current_app, session, g -from flask_login import current_user, login_user, logout_user, login_required +from flask import Blueprint, request, render_template, make_response, jsonify, redirect, url_for, session +from flask_login import current_user, login_required -from .base import login_manager from ..models.user import User -from ..models.role import Role user_bp = Blueprint('user', __name__, diff --git a/update_zones.py b/update_zones.py index 6e2f449..f13b873 100644 --- a/update_zones.py +++ b/update_zones.py @@ -13,7 +13,6 @@ import sys import logging -from flask import current_app from powerdnsadmin import create_app from powerdnsadmin.models.domain import Domain from powerdnsadmin.models.setting import Setting