Skip to content

Commit

Permalink
refactor: format python files through ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Aug 9, 2024
1 parent aba4cae commit 9276477
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 337 deletions.
6 changes: 3 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Starts the protonfix module
"""
"""Starts the protonfix module"""

import os
import sys
Expand All @@ -16,10 +15,11 @@
if all(RUN_CONDITIONS):
import traceback
from . import fix

try:
fix.main()

#pylint: disable=W0702
# pylint: disable=W0702
# Catch any exceptions and print a traceback
except:
sys.stderr.write('ProtonFixes ' + traceback.format_exc())
Expand Down
12 changes: 5 additions & 7 deletions checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Run some tests and generate warnings for proton configuration issues
"""
"""Run some tests and generate warnings for proton configuration issues"""

try:
from .logger import log
Expand All @@ -13,11 +12,11 @@ def esync_file_limits() -> bool:
https://www.reddit.com/r/SteamPlay/comments/9kqisk/tip_for_those_using_proton_no_esync1/
"""

warning = '''File descriptor limit is low
warning = """File descriptor limit is low
This can cause issues with ESYNC
For more details see:
https://github.com/zfigura/wine/blob/esync/README.esync
'''
"""

with open('/proc/sys/fs/file-max', encoding='ascii') as fsmax:
max_files = fsmax.readline()
Expand All @@ -28,12 +27,11 @@ def esync_file_limits() -> bool:


def run_checks() -> None:
""" Run checks to notify of any potential issues
"""
"""Run checks to notify of any potential issues"""

log.info('Running checks')
checks = [
esync_file_limits(),
]
]
if all(checks):
log.info('All checks successful')
21 changes: 10 additions & 11 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
""" Load configuration settings for protonfixes
"""
"""Load configuration settings for protonfixes"""

import os
from configparser import ConfigParser

try:
from .logger import log
except ImportError:
from logger import log


CONF_FILE = '~/.config/protonfixes/config.ini'
DEFAULT_CONF = '''
DEFAULT_CONF = """
[main]
enable_checks = true
enable_splash = false
Expand All @@ -18,7 +19,7 @@
[path]
cache_dir = ~/.cache/protonfixes
'''
"""

CONF = ConfigParser()
CONF.read_string(DEFAULT_CONF)
Expand All @@ -29,19 +30,17 @@
except Exception:
log.debug('Unable to read config file ' + CONF_FILE)


def opt_bool(opt):
""" Convert bool ini strings to actual boolean values
"""
"""Convert bool ini strings to actual boolean values"""

return opt.lower() in ['yes', 'y', 'true', '1']


# pylint: disable=E1101
locals().update(
{x:opt_bool(y) for x, y
in CONF['main'].items()
if 'enable' in x})
locals().update({x: opt_bool(y) for x, y in CONF['main'].items() if 'enable' in x})

locals().update({x:os.path.expanduser(y) for x, y in CONF['path'].items()})
locals().update({x: os.path.expanduser(y) for x, y in CONF['path'].items()})

try:
[os.makedirs(os.path.expanduser(d)) for n, d in CONF['path'].items()]
Expand Down
10 changes: 6 additions & 4 deletions debug.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
""" Prints debug info if the environment variable DEBUG is 1
"""
"""Prints debug info if the environment variable DEBUG is 1"""

import os
import sys
import shutil

# pylint: disable=E0611
from __main__ import CURRENT_PREFIX_VERSION, g_proton
from .logger import log

os.environ['DEBUG'] = '1'


def show_debug_info() -> None:
""" Show various debug info """
"""Show various debug info"""

check_args = [
'iscriptevaluator.exe' in sys.argv[2],
Expand All @@ -32,7 +33,7 @@ def show_debug_info() -> None:
log.debug('System Python Version:')
try:
log.debug(shutil.which(os.readlink(shutil.which('python'))))
except: #pylint: disable=W0702
except: # pylint: disable=W0702
log.debug(shutil.which('python'))
log.debug(line)

Expand Down Expand Up @@ -61,4 +62,5 @@ def show_debug_info() -> None:
log.debug(sys.argv)
log.debug('----- end protontricks debug info -----')


show_debug_info()
20 changes: 9 additions & 11 deletions download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Module with helper functions to download from file-hosting providers
"""
"""Module with helper functions to download from file-hosting providers"""

import os
import hashlib
Expand All @@ -12,26 +11,26 @@


def get_filename(headers: list) -> str:
""" Retrieve a filename from a request headers via Content-Disposition
"""
"""Retrieve a filename from a request headers via Content-Disposition"""
content_disp = [x for x in headers if x[0] == 'Content-Disposition'][0][1]
raw_filename = [x for x in content_disp.split(';') if x.startswith('filename=')][0]
return raw_filename.replace('filename=', '').replace('"', '')


def gdrive_download(gdrive_id: str, path: str) -> None:
""" Download a file from gdrive given the fileid and a path to save
"""
"""Download a file from gdrive given the fileid and a path to save"""
url = GDRIVE_URL.format(gdrive_id)
cjar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cjar))
urllib.request.install_opener(opener)

req = urllib.request.Request(url)
with urllib.request.urlopen(req, timeout=10) as resp:
confirm_cookie = [x for x in resp.getheaders() if
(x[0] == 'Set-Cookie'
and x[1].startswith('download_warning'))][0][1]
confirm_cookie = [
x
for x in resp.getheaders()
if (x[0] == 'Set-Cookie' and x[1].startswith('download_warning'))
][0][1]
confirm = confirm_cookie.split(';')[0].split('=')[1]

req = urllib.request.Request(f'{url}&confirm={confirm}')
Expand All @@ -42,8 +41,7 @@ def gdrive_download(gdrive_id: str, path: str) -> None:


def sha1sum(filename: str) -> str:
""" Computes the sha1sum of the specified file
"""
"""Computes the sha1sum of the specified file"""
if not os.path.isfile(filename):
return ''
hasher = hashlib.sha1()
Expand Down
Loading

0 comments on commit 9276477

Please sign in to comment.