flake warnings (#304)

This commit is contained in:
Bruno Cabral
2022-12-12 02:44:27 -08:00
committed by GitHub
parent f10a3f1d1a
commit fb4109bd77
67 changed files with 252 additions and 248 deletions

View File

@@ -281,7 +281,7 @@ class AURClient:
return set()
else:
return index.values()
except:
except Exception:
return set()
def clean_caches(self):
@@ -314,4 +314,3 @@ class AURClient:
def is_supported(arch_config: dict) -> bool:
return arch_config['aur'] and git.is_installed()

View File

@@ -414,7 +414,7 @@ class ArchManager(SoftwareManager, SettingsController):
res.update_total()
return res
def _fill_aur_pkgs_offline(self, aur_pkgs: dict, arch_config: dict, output: List[ArchPackage], disk_loader: Optional[DiskCacheLoader]):
def _fill_aur_pkgs_offline(self, aur_pkgs: dict, arch_config: dict, output: List[ArchPackage], disk_loader: Optional[DiskCacheLoader]):
self.logger.info("Reading cached data from installed AUR packages")
editable_pkgbuilds = self._read_editable_pkgbuilds() if arch_config['edit_aur_pkgbuild'] is not False else None
@@ -850,7 +850,7 @@ class ArchManager(SoftwareManager, SettingsController):
body=self.i18n['arch.action.db_locked.error'],
type_=MessageType.ERROR)
return True
except:
except Exception:
self.logger.error("An error occurred while removing the pacman database lock")
traceback.print_exc()
handler.watcher.show_message(title=self.i18n['error'].capitalize(),
@@ -1065,7 +1065,7 @@ class ArchManager(SoftwareManager, SettingsController):
output_handler.join()
self.logger.error("'pacman' returned an unexpected response or error phrase after upgrading the repository packages")
return False
except:
except Exception:
handler.watcher.change_substatus('')
handler.watcher.print("An error occurred while upgrading repository packages")
self.logger.error("An error occurred while upgrading repository packages")
@@ -1092,7 +1092,7 @@ class ArchManager(SoftwareManager, SettingsController):
return False
return True
except:
except Exception:
self.logger.error("An error occurred while removing packages: {}".format(', '.join(to_remove)))
traceback.print_exc()
output_handler.stop_working()
@@ -1180,7 +1180,7 @@ class ArchManager(SoftwareManager, SettingsController):
else:
any_upgraded = True
watcher.print(self.i18n['arch.upgrade.success'].format('"{}"'.format(pkg.name)))
except:
except Exception:
if any_upgraded:
self._update_aur_index(watcher)
@@ -1307,7 +1307,7 @@ class ArchManager(SoftwareManager, SettingsController):
return True
def _fill_aur_providers(self, names: str, output: Set[str]):
def _fill_aur_providers(self, names: str, output: Set[str]):
for _, data in self.aur_client.gen_updates_data(names):
providers = data.get('p')
@@ -1596,7 +1596,7 @@ class ArchManager(SoftwareManager, SettingsController):
if pkg.first_submitted:
info['08_first_submitted'] = self._parse_timestamp(ts=pkg.first_submitted,
error_msg="Could not parse AUR package '{}' 'first_submitted' field".format(pkg.name, pkg.first_submitted))
error_msg="Could not parse AUR package '{}' 'first_submitted' field ({})".format(pkg.name, pkg.first_submitted))
if pkg.last_modified:
info['09_last_modified'] = self._parse_timestamp(ts=pkg.last_modified,
@@ -1764,7 +1764,7 @@ class ArchManager(SoftwareManager, SettingsController):
try:
Path(extract_path).mkdir(parents=True, exist_ok=True)
except:
except Exception:
self.logger.error("Could not create temp dir {} to extract previous versions data".format(extract_path))
traceback.print_exc()
return data
@@ -1814,7 +1814,7 @@ class ArchManager(SoftwareManager, SettingsController):
try:
self.logger.info("Removing temporary history dir {}".format(extract_path))
shutil.rmtree(extract_path)
except:
except Exception:
self.logger.error("Could not remove temp path '{}'".format(extract_path))
raise
@@ -2181,7 +2181,7 @@ class ArchManager(SoftwareManager, SettingsController):
if not os.path.exists(cache_path):
try:
os.mkdir(cache_path)
except:
except Exception:
print("Could not create cache directory '{}'".format(cache_path))
traceback.print_exc()
return
@@ -2190,11 +2190,11 @@ class ArchManager(SoftwareManager, SettingsController):
dest_pkgbuild = '{}/PKGBUILD'.format(cache_path)
try:
shutil.copy(src_pkgbuild, dest_pkgbuild)
except:
except Exception:
context.watcher.print("Could not copy '{}' to '{}'".format(src_pkgbuild, dest_pkgbuild))
traceback.print_exc()
def _ask_and_install_missing_deps(self, context: TransactionContext, missing_deps: List[Tuple[str, str]]) -> bool:
def _ask_and_install_missing_deps(self, context: TransactionContext, missing_deps: List[Tuple[str, str]]) -> bool:
context.watcher.change_substatus(self.i18n['arch.missing_deps_found'].format(bold(context.name)))
if not confirm_missing_deps(missing_deps, context.watcher, self.i18n):
@@ -2264,7 +2264,7 @@ class ArchManager(SoftwareManager, SettingsController):
missing_deps = self._list_missing_deps(context)
except PackageNotFoundException:
return False
except:
except Exception:
traceback.print_exc()
return False
@@ -2406,8 +2406,8 @@ class ArchManager(SoftwareManager, SettingsController):
def _multithreaded_download_enabled(self, arch_config: dict) -> bool:
return bool(arch_config['repositories_mthread_download']) \
and self.context.file_downloader.is_multithreaded() \
and pacman.is_mirrors_available()
and self.context.file_downloader.is_multithreaded() \
and pacman.is_mirrors_available()
def _download_packages(self, pkgnames: List[str], handler: ProcessHandler, root_password: Optional[str], sizes: Dict[str, int] = None, multithreaded: bool = True) -> int:
if multithreaded:
@@ -2431,7 +2431,7 @@ class ArchManager(SoftwareManager, SettingsController):
return len(pkgnames)
else:
raise ArchDownloadException()
except:
except Exception:
traceback.print_exc()
raise ArchDownloadException()
@@ -2516,7 +2516,7 @@ class ArchManager(SoftwareManager, SettingsController):
status_handler = None
installed_with_same_name = self.read_installed(disk_loader=context.disk_loader, internet_available=True, names=context.get_package_names()).installed
context.watcher.change_substatus(self.i18n['arch.installing.package'].format(bold(context.name))) #
context.watcher.change_substatus(self.i18n['arch.installing.package'].format(bold(context.name))) #
installed = self._handle_install_call(context=context, to_install=to_install, status_handler=status_handler)
@@ -3128,7 +3128,7 @@ class ArchManager(SoftwareManager, SettingsController):
try:
self.configman.save_config(arch_config)
return True, None
except:
except Exception:
return False, [traceback.format_exc()]
def get_upgrade_requirements(self, pkgs: List[ArchPackage], root_password: Optional[str], watcher: ProcessWatcher) -> UpgradeRequirements:
@@ -3323,7 +3323,7 @@ class ArchManager(SoftwareManager, SettingsController):
if not cache_dir or not os.path.isdir(cache_dir):
watcher.show_message(title=self.i18n['arch.custom_action.clean_cache'].capitalize(),
body=self.i18n['arch.custom_action.clean_cache.no_dir'.format(bold(cache_dir))].capitalize(),
body=self.i18n['arch.custom_action.clean_cache.no_dir'].format(bold(cache_dir)).capitalize(),
type_=MessageType.WARNING)
return True
@@ -3415,7 +3415,7 @@ class ArchManager(SoftwareManager, SettingsController):
self._write_editable_pkgbuilds(editable)
return True
except:
except Exception:
traceback.print_exc()
return False
@@ -3436,7 +3436,7 @@ class ArchManager(SoftwareManager, SettingsController):
editable.remove(pkgname)
self._write_editable_pkgbuilds(editable)
except:
except Exception:
traceback.print_exc()
return False
@@ -3679,7 +3679,7 @@ class ArchManager(SoftwareManager, SettingsController):
else:
rebuild_detector.remove_from_ignored(pkg.name)
pkg.allow_rebuild = True
except:
except Exception:
self.logger.error("An unexpected exception happened")
traceback.print_exc()
return False

View File

@@ -31,7 +31,7 @@ def should_sync(arch_config: dict, aur_supported: bool, handler: Optional[Proces
if handler:
handler.watcher.print(msg)
return False
except:
except Exception:
logger.warning("Could not convert the database synchronization time from '{}".format(SYNC_FILE))
traceback.print_exc()
return True
@@ -48,6 +48,6 @@ def register_sync(logger: Logger):
Path('/'.join(SYNC_FILE.split('/')[0:-1])).mkdir(parents=True, exist_ok=True)
with open(SYNC_FILE, 'w+') as f:
f.write(str(int(time.time())))
except:
except Exception:
logger.error("Could not write to database sync file '{}'".format(SYNC_FILE))
traceback.print_exc()

View File

@@ -288,7 +288,7 @@ class DependenciesAnalyser:
if not version_required or match_required_version(pkgdata['v'], exp_op,
version_required):
yield pkgname, pkgdata
except:
except Exception:
self._log.warning(f"Could not compare AUR package '{pkgname}' version '{pkgdata['v']}' "
f"with the dependency expression '{dep_exp}'")
traceback.print_exc()
@@ -588,7 +588,7 @@ class DependenciesAnalyser:
if repo_selected:
providers_data.update(pacman.map_updates_data(repo_selected))
# adding the providers as "installed" packages
provided_map.update(pacman.map_provided(remote=True, pkgs=repo_selected))
provided_map.update(pacman.map_provided(remote=True, pkgs=repo_selected))
if aur_selected:
for pkgname, pkgdata in self.aur_client.gen_updates_data(aur_selected):

View File

@@ -11,7 +11,7 @@ RE_DESKTOP_ENTRY = re.compile(r'[\n^](Exec|Icon|NoDisplay)\s*=\s*(.+)')
RE_CLEAN_NAME = re.compile(r'[+*?%]')
def write_several(pkgs: Dict[str, ArchPackage], overwrite: bool = True, maintainer: str = None, after_desktop_files: Optional[Callable] = None, after_written: Optional[Callable[[str], None]] = None) -> int:
def write_several(pkgs: Dict[str, ArchPackage], overwrite: bool = True, maintainer: str = None, after_desktop_files: Optional[Callable] = None, after_written: Optional[Callable[[str], None]] = None) -> int:
if overwrite:
to_cache = {p.name for p in pkgs.values()}
else:

View File

@@ -56,7 +56,7 @@ class MultiThreadedDownloader:
msg = "Package '{}' signature successfully downloaded".format(pkg['n'])
self.logger.info(msg)
watcher.print(msg)
except:
except Exception:
self.logger.warning("An error occurred while download package '{}' signature".format(pkg['n']))
traceback.print_exc()
@@ -178,7 +178,7 @@ class MultithreadedDownloadService:
substatus_prefix=status_prefix,
size=sizes.get(pkg['n']) if sizes else None):
downloaded += 1
except:
except Exception:
traceback.print_exc()
watcher.show_message(title=self.i18n['error'].capitalize(),
body=self.i18n['arch.mthread_downloaded.error.cancelled'],

View File

@@ -26,7 +26,7 @@ def should_sync(logger: logging.Logger):
msg = "Package databases already synchronized"
logger.info(msg)
return False
except:
except Exception:
logger.warning("Could not convert the database synchronization time from '{}".format(SYNC_FILE))
traceback.print_exc()
return True
@@ -37,6 +37,6 @@ def register_sync(logger: Logger):
Path('/'.join(SYNC_FILE.split('/')[0:-1])).mkdir(parents=True, exist_ok=True)
with open(SYNC_FILE, 'w+') as f:
f.write(str(int(time.time())))
except:
except Exception:
logger.error("Could not write to mirrors sync file '{}'".format(SYNC_FILE))
traceback.print_exc()

View File

@@ -250,7 +250,7 @@ class ArchPackage(SoftwarePackage):
if isinstance(other, ArchPackage):
if self.view_name is not None and other.view_name is not None:
return self.view_name == other.view_name and self.repository == other.repository
return self.name == other.name and self.repository == other.repository
def get_cached_pkgbuild_path(self) -> str:

View File

@@ -697,7 +697,7 @@ def map_updates_data(pkgs: Iterable[str], files: bool = False, description: bool
latest_name = None
latest_field = None
data = {'ds': None, 's': None, 'c': None, 'p': None, 'd': None,
'r': None, 'v': None, 'des': None}
'r': None, 'v': None, 'des': None}
else:
latest_field = None
@@ -862,7 +862,7 @@ def map_required_by(names: Iterable[str] = None, remote: bool = False) -> Dict[s
if output:
latest_name, required = None, None
res = {}
for l in output.split('\n'):
if l:
if l[0] != ' ':

View File

@@ -17,7 +17,7 @@ class CallAsUser:
try:
os.setuid(getpwnam(self._user).pw_uid)
return self._target()
except:
except Exception:
traceback.print_exc()
@@ -33,7 +33,7 @@ class WriteToFile:
f.write(self._content)
return True
except:
except Exception:
traceback.print_exc()
return False

View File

@@ -91,7 +91,7 @@ class RepositorySuggestionsDownloader(Thread):
try:
suggestions_timestamp = datetime.fromtimestamp(float(timestamp_str))
except:
except Exception:
self._log.error(f'Could not parse the Arch cached suggestions timestamp: {timestamp_str}')
traceback.print_exc()
return True
@@ -122,14 +122,14 @@ class RepositorySuggestionsDownloader(Thread):
try:
with open(self.file_suggestions(), 'w+') as f:
f.write(text)
except:
except Exception:
self._log.error(f"An exception happened while writing the file '{self.file_suggestions()}'")
traceback.print_exc()
try:
with open(self.file_suggestions_timestamp(), 'w+') as f:
f.write(str(timestamp))
except:
except Exception:
self._log.error(f"An exception happened while writing the file '{self.file_suggestions_timestamp()}'")
traceback.print_exc()

View File

@@ -216,7 +216,7 @@ class UpdatesSummarizer:
self.logger.warning("No version declared in SRCINFO of '{}'".format(pkg_data[0]))
else:
self.logger.warning("Could not retrieve the SRCINFO for '{}'".format(pkg_data[0]))
except:
except Exception:
self.logger.warning("Could not retrieve the SRCINFO for '{}'".format(pkg_data[0]))
else:
version = pacman.get_version_for_not_installed(pkg_data[0])
@@ -341,7 +341,7 @@ class UpdatesSummarizer:
if pkgdata:
requirement.required_size = pkgdata['ds']
requirement.extra_size = pkgdata['s']
current_size = installed_sizes.get(pkg.name) if installed_sizes else None
if current_size is not None and pkgdata['s'] is not None:
@@ -742,7 +742,7 @@ class UpdatesSummarizer:
if match_required_version(current_version=v, operator=op, required_version=dep_split[1]):
version_match = True
break
except:
except Exception:
self.logger.error("Error when comparing versions {} (provided) and {} (required)".format(v, dep_split[1]))
traceback.print_exc()

View File

@@ -1,3 +1,4 @@
from __future__ import annotations
import glob
import logging
import os
@@ -22,6 +23,10 @@ from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_FILE, ARCH_CONFIG_DIR, A
from bauh.gems.arch.aur import URL_INDEX
from bauh.view.util.translation import I18n
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from bauh.gems.arch.controller import ArchManager
URL_INFO = 'https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'
GLOBAL_MAKEPKG = '/etc/makepkg.conf'
@@ -49,7 +54,7 @@ class AURIndexUpdater(Thread):
try:
exp_hours = int(self.config['aur_idx_exp'])
except:
except Exception:
traceback.print_exc()
return True
@@ -68,7 +73,7 @@ class AURIndexUpdater(Thread):
try:
index_timestamp = datetime.fromtimestamp(float(timestamp_str))
return (index_timestamp + timedelta(hours=exp_hours)) <= datetime.utcnow()
except:
except Exception:
traceback.print_exc()
return True
@@ -143,7 +148,7 @@ class AURIndexUpdater(Thread):
class ArchDiskCacheUpdater(Thread):
def __init__(self, taskman: TaskManager, i18n: I18n, logger: logging.Logger,
controller: "ArchManager", internet_available: bool, aur_indexer: Thread,
controller: ArchManager, internet_available: bool, aur_indexer: Thread,
create_config: CreateConfigFile):
super(ArchDiskCacheUpdater, self).__init__(daemon=True)
self.logger = logger
@@ -265,7 +270,7 @@ class ArchCompilationOptimizer(Thread):
ti = time.time()
try:
ncpus = os.cpu_count()
except:
except Exception:
self.logger.error('Could not determine the number of processors. Aborting...')
ncpus = None
@@ -385,7 +390,7 @@ class ArchCompilationOptimizer(Thread):
if self.create_config.config['optimize'] and aur.is_supported(self.create_config.config):
try:
self.optimize()
except:
except Exception:
self.logger.error("Unexpected exception")
traceback.print_exc()
self.taskman.update_progress(self.task_id, 100, None)
@@ -396,7 +401,7 @@ class ArchCompilationOptimizer(Thread):
try:
self.logger.info("Removing custom 'makepkg.conf' -> '{}'".format(CUSTOM_MAKEPKG_FILE))
os.remove(CUSTOM_MAKEPKG_FILE)
except:
except Exception:
self.logger.error("Unexpected exception")
traceback.print_exc()
@@ -428,7 +433,7 @@ class RefreshMirrors(Thread):
@staticmethod
def is_enabled(arch_config: dict, aur_supported: bool) -> bool:
return (arch_config['repositories'] or aur_supported) \
and arch_config['refresh_mirrors_startup'] and pacman.is_mirrors_available()
and arch_config['refresh_mirrors_startup'] and pacman.is_mirrors_available()
@classmethod
def should_synchronize(cls, arch_config: dict, aur_supported: bool, logger: logging.Logger) -> bool:
@@ -468,7 +473,7 @@ class RefreshMirrors(Thread):
self.taskman.update_progress(self.task_id, 50, self.i18n['arch.custom_action.refresh_mirrors.status.updating'])
try:
handler.handle_simple(pacman.sort_fastest_mirrors(self.root_password, sort_limit), output_handler=self._notify_output)
except:
except Exception:
self.logger.error("Could not sort mirrors by speed")
traceback.print_exc()
@@ -476,7 +481,7 @@ class RefreshMirrors(Thread):
self.refreshed = True
else:
self.logger.error("It was not possible to refresh mirrors")
except:
except Exception:
self.logger.error("It was not possible to refresh mirrors")
traceback.print_exc()
@@ -518,7 +523,7 @@ class SyncDatabases(Thread):
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(bold(self.refresh_mirrors.task_name)))
self.refresh_mirrors.join()
self.taskman.update_progress(self.task_id, 1, self.i18n['arch.task.checking_settings'])
self.taskman.update_progress(self.task_id, 1, self.i18n['arch.task.checking_settings'])
arch_config = self.create_config.config
aur_supported = aur.is_supported(arch_config)
@@ -580,7 +585,7 @@ class SyncDatabases(Thread):
else:
self.logger.error("Could not synchronize database")
except:
except Exception:
self.logger.info("Error while synchronizing databases")
traceback.print_exc()