Fix issues pointed out by ruff

Signed-off-by: Alfred Wingate <parona@protonmail.com>
This commit is contained in:
Alfred Wingate 2023-11-14 23:43:04 +02:00
parent 70f88ed37d
commit a8f35aee25
No known key found for this signature in database
GPG Key ID: A12750536B5E7010
7 changed files with 20 additions and 22 deletions

View File

@ -29,8 +29,8 @@ from portage.exception import AmbiguousPackageName
from portage.output import green, turquoise, white, yellow from portage.output import green, turquoise, white, yellow
from euscan import CONFIG, output from euscan import CONFIG, output
from euscan.out import progress_bar
from euscan._version import __version__ from euscan._version import __version__
from euscan.out import progress_bar
# Globals # Globals
isatty = os.environ.get("TERM") != "dumb" and sys.stdout.isatty() isatty = os.environ.get("TERM") != "dumb" and sys.stdout.isatty()
@ -75,7 +75,7 @@ def print_usage(_error=None, help=None):
if _error: if _error:
out = sys.stderr out = sys.stderr
if not _error in ( if _error not in (
"global-options", "global-options",
"packages", "packages",
): ):
@ -284,7 +284,7 @@ def parse_args():
# apply getopts to command line, show partial help on failure # apply getopts to command line, show partial help on failure
try: try:
opts, args = getopt.getopt(sys.argv[1:], short_opts, long_opts) opts, args = getopt.getopt(sys.argv[1:], short_opts, long_opts)
except: except getopt.GetoptError:
raise ParseArgsException(opts_mode + "-options") raise ParseArgsException(opts_mode + "-options")
# set options accordingly # set options accordingly

View File

@ -127,7 +127,7 @@ def get_deb_url(name):
if not deb_url: if not deb_url:
logger.error(" Cannot get package from %s" % url) logger.error(" Cannot get package from %s" % url)
name = raw_input(" Package name in Debian: ") name = input(" Package name in Debian: ")
return deb_url, deb_type return deb_url, deb_type

View File

@ -84,6 +84,6 @@ ROBOTS_TXT_BLACKLIST_DOMAINS = [
"(.*)festvox\.org(.*)", "(.*)festvox\.org(.*)",
] ]
from euscan.out import EuscanOutput from euscan.out import EuscanOutput # noqa: E402
output = EuscanOutput(CONFIG) output = EuscanOutput(CONFIG)

View File

@ -27,8 +27,10 @@ def guess_package(cp, url):
if match: if match:
pkg = match.group(1) pkg = match.group(1)
try: try:
# Output is None if input is invalid, therefore TypeError when
# this None is attempted to be unpacked into three variables.
cp, ver, rev = portage.pkgsplit("fake/" + pkg) cp, ver, rev = portage.pkgsplit("fake/" + pkg)
except: except TypeError:
pass pass
cat, pkg = cp.split("/") cat, pkg = cp.split("/")
@ -92,7 +94,7 @@ def cpan_mangle_version(pv):
def cpan_vercmp(cp, a, b): def cpan_vercmp(cp, a, b):
try: try:
return float(a) - float(b) return float(a) - float(b)
except: except OverflowError:
return helpers.simple_vercmp(a, b) return helpers.simple_vercmp(a, b)
@ -113,7 +115,7 @@ def scan_pkg(pkg, options):
options["versionmangle"] = ["cpan", "gentoo"] options["versionmangle"] = ["cpan", "gentoo"]
url = "http://search.cpan.org/api/dist/%s" % remote_pkg url = "http://search.cpan.org/api/dist/%s" % remote_pkg
cp, ver, rev = pkg.cp, pkg.version, pkg.revision cp, ver = pkg.cp, pkg.version
m_ver = cpan_mangle_version(ver) m_ver = cpan_mangle_version(ver)
output.einfo("Using CPAN API: " + url) output.einfo("Using CPAN API: " + url)

View File

@ -4,8 +4,6 @@ import urllib.parse
import urllib.request import urllib.request
import xml.dom.minidom import xml.dom.minidom
import portage
from euscan import helpers, mangling, output from euscan import helpers, mangling, output
HANDLER_NAME = "php" HANDLER_NAME = "php"
@ -35,7 +33,7 @@ def scan_url(pkg, url, options):
def scan_pkg(pkg, options): def scan_pkg(pkg, options):
cp, ver, rev = pkg.cp, pkg.version, pkg.revision cp, ver = pkg.cp, pkg.version
package = options["data"] package = options["data"]
channel = options["type"] channel = options["type"]

View File

@ -1,20 +1,16 @@
import errno import errno
import os import os
import re import re
import urllib
import urllib.error import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
import urllib.robotparser
from xml.dom.minidom import Document from xml.dom.minidom import Document
import portage import portage
from portage import dep from portage import dep
try:
from urllib import robotparser, urlparse
except ImportError:
import urllib.robotparser
import urllib.parse
import euscan import euscan
from euscan import BLACKLIST_VERSIONS, CONFIG, ROBOTS_TXT_BLACKLIST_DOMAINS from euscan import BLACKLIST_VERSIONS, CONFIG, ROBOTS_TXT_BLACKLIST_DOMAINS
from euscan.version import parse_version from euscan.version import parse_version
@ -188,7 +184,9 @@ def join_version(components):
version += str(components[i]) version += str(components[i])
if i >= len(components) - 1: if i >= len(components) - 1:
break break
if type(components[i]) != str and type(components[i + 1]) != str: if not isinstance(components[i], str) and not isinstance(
components[i + 1], str
):
version += "." version += "."
return version return version
@ -200,10 +198,10 @@ def increment_version(components, level):
raise Exception raise Exception
for i in range(n, level + 1, -1): for i in range(n, level + 1, -1):
if type(components[i - 1]) == int: if isinstance(components[i - 1], int):
components[i - 1] = 0 components[i - 1] = 0
if type(components[level]) == int: if isinstance(components[level], int):
components[level] += 1 components[level] += 1
return components return components
@ -278,7 +276,7 @@ def urlallowed(url):
try: try:
rp.read() rp.read()
rpcache[baseurl] = rp rpcache[baseurl] = rp
except: except IOError:
rp = None rp = None
setdefaulttimeout(timeout) setdefaulttimeout(timeout)

View File

@ -69,7 +69,7 @@ def progress_bar():
def clean_colors(string): def clean_colors(string):
if type(string) is str: if isinstance(string, str):
string = re.sub("\033\[[0-9;]+m", "", string) string = re.sub("\033\[[0-9;]+m", "", string)
string = re.sub(r"\\u001b\[[0-9;]+m", "", string) string = re.sub(r"\\u001b\[[0-9;]+m", "", string)
string = re.sub(r"\x1b\[[0-9;]+m", "", string) string = re.sub(r"\x1b\[[0-9;]+m", "", string)