Skip to content

Commit

Permalink
Major code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Apr 11, 2024
1 parent 21df9b5 commit 84a7335
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 399 deletions.
5 changes: 5 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
line-length = 120
target-version = "py312"

[format]
quote-style = "single"
1 change: 1 addition & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rule_settings:
disable:
- list-comprehension
- dict-comprehension
- sum-comprehension
- for-append-to-extend
- use-next
rule_types:
Expand Down
14 changes: 5 additions & 9 deletions CB/Compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ def set_normal_term(self):
if system != 'Windows':
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)

def getch(self): # sourcery skip: assign-if-exp
if system == 'Windows':
return msvcrt.getch()
else:
return sys.stdin.read(1)
def getch(self):
return msvcrt.getch() if system == 'Windows' else sys.stdin.read(1)

def kbhit(self): # sourcery skip: remove-unnecessary-else
def kbhit(self):
if system == 'Windows':
return msvcrt.kbhit()
else:
dr, dw, de = select([sys.stdin], [], [], 0)
return dr != []
dr, dw, de = select([sys.stdin], [], [], 0)
return dr != []


def pause(headless):
Expand Down
20 changes: 5 additions & 15 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def init_master_config(self):
try:
self.masterConfig = json.load(gzip.open(io.BytesIO(
self.http.get('https://cursebreaker.acidweb.dev/config-v2.json.gz').content)))
except Exception:
except (StopIteration, UnicodeDecodeError, json.JSONDecodeError, httpx.RequestError) as e:
raise RuntimeError('Failed to fetch the master config file. '
'Check your connectivity to Google Cloud.') from None
'Check your connectivity to Google Cloud.') from e

def init_config(self):
if os.path.isfile('CurseBreaker.json'):
Expand Down Expand Up @@ -193,14 +193,14 @@ def check_if_dev_global(self):
return addon['Development']
return 0

def check_if_from_gh(self): # sourcery skip: sum-comprehension
def check_if_from_gh(self):
if self.config['GHAPIKey'] != '':
return False
count = 0
for addon in self.config['Addons']:
if addon['URL'].startswith('https://github.com/'):
count += 1
return count > 3
return count > 4

def cleanup(self, directories):
if len(directories) > 0:
Expand Down Expand Up @@ -301,7 +301,7 @@ def del_addon(self, url, keep):
return old['Name'], old['Version']
return False, False

def update_addon(self, url, update, force): # sourcery skip: extract-method
def update_addon(self, url, update, force):
if not (old := self.check_if_installed(url)):
return url, [], False, False, None, False, False, '?', None, None, None
dev = self.check_if_dev(old['URL'])
Expand Down Expand Up @@ -395,16 +395,6 @@ def block_toggle(self, url):
return not state
return None

def generic_toggle(self, option, inside=None):
if inside:
self.config[option][inside] = not self.config[option][inside]
self.save_config()
return self.config[option][inside]
else:
self.config[option] = not self.config[option]
self.save_config()
return self.config[option]

def backup_check(self):
if not self.config['Backup']['Enabled']:
return False
Expand Down
14 changes: 6 additions & 8 deletions CB/GitHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from . import retry, APIAuth


# noinspection PyTypeChecker
class GitHubAddon:
@retry()
def __init__(self, url, checkcache, packagercache, clienttype, apikey, http):
Expand All @@ -33,8 +32,7 @@ def __init__(self, url, checkcache, packagercache, clienttype, apikey, http):
else:
self.payload = self.payload.json()
for release in self.payload:
if release['assets'] and len(release['assets']) > 0 \
and not release['draft'] and not release['prerelease']:
if release['assets'] and len(release['assets']) > 0 and not release['draft'] and not release['prerelease']:
self.payloads.append(release)
if len(self.payloads) > 14:
break
Expand Down Expand Up @@ -149,11 +147,11 @@ def install(self, path):
class GitHubAddonRaw:
@retry()
def __init__(self, addon, apikey, http):
repository = addon["Repository"]
repository = addon['Repository']
self.http = http
self.apiKey = apikey
self.branch = addon["Branch"]
self.name = addon["Name"]
self.branch = addon['Branch']
self.name = addon['Name']
try:
self.payload = self.http.get(f'https://api.github.com/repos/{repository}/branches/{self.branch}',
auth=APIAuth('token', self.apiKey))
Expand All @@ -178,8 +176,8 @@ def __init__(self, addon, apikey, http):
self.currentVersion = self.payload['commit']['sha'][:7]
self.uiVersion = None
self.archive = None
self.directories = addon["Directories"]
self.author = addon["Authors"]
self.directories = addon['Directories']
self.author = addon['Authors']

@retry()
def get_addon(self):
Expand Down
1 change: 0 additions & 1 deletion CB/Tukui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import io
import httpx
import zipfile
from . import retry

Expand Down
Loading

0 comments on commit 84a7335

Please sign in to comment.