mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-16 07:19:57 +00:00
chore: add metthod definition order plugin to pylint
Also reorder some methods to fix errors
This commit is contained in:
@ -96,8 +96,8 @@ def _parser() -> argparse.ArgumentParser:
|
||||
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command")
|
||||
|
||||
_set_aur_search_parser(subparsers)
|
||||
_set_help_parser(subparsers)
|
||||
_set_help_commands_unsafe_parser(subparsers)
|
||||
_set_help_parser(subparsers)
|
||||
_set_help_updates_parser(subparsers)
|
||||
_set_help_version_parser(subparsers)
|
||||
_set_package_add_parser(subparsers)
|
||||
@ -166,25 +166,6 @@ def _set_aur_search_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||
return parser
|
||||
|
||||
|
||||
def _set_help_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||
"""
|
||||
add parser for listing help subcommand
|
||||
|
||||
Args:
|
||||
root(SubParserAction): subparsers for the commands
|
||||
|
||||
Returns:
|
||||
argparse.ArgumentParser: created argument parser
|
||||
"""
|
||||
parser = root.add_parser("help", help="show help message",
|
||||
description="show help message for application or command and exit",
|
||||
formatter_class=_formatter)
|
||||
parser.add_argument("command", help="show help message for specific command", nargs="?")
|
||||
parser.set_defaults(handler=handlers.Help, architecture="", lock=None, quiet=True, report=False, repository="",
|
||||
unsafe=True, parser=_parser)
|
||||
return parser
|
||||
|
||||
|
||||
def _set_help_commands_unsafe_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||
"""
|
||||
add parser for listing unsafe commands
|
||||
@ -204,6 +185,25 @@ def _set_help_commands_unsafe_parser(root: SubParserAction) -> argparse.Argument
|
||||
return parser
|
||||
|
||||
|
||||
def _set_help_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||
"""
|
||||
add parser for listing help subcommand
|
||||
|
||||
Args:
|
||||
root(SubParserAction): subparsers for the commands
|
||||
|
||||
Returns:
|
||||
argparse.ArgumentParser: created argument parser
|
||||
"""
|
||||
parser = root.add_parser("help", help="show help message",
|
||||
description="show help message for application or command and exit",
|
||||
formatter_class=_formatter)
|
||||
parser.add_argument("command", help="show help message for specific command", nargs="?")
|
||||
parser.set_defaults(handler=handlers.Help, architecture="", lock=None, quiet=True, report=False, repository="",
|
||||
unsafe=True, parser=_parser)
|
||||
return parser
|
||||
|
||||
|
||||
def _set_help_updates_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||
"""
|
||||
add parser for service update check subcommand
|
||||
|
@ -67,8 +67,8 @@ class Versions(Handler):
|
||||
Args:
|
||||
root(str): root package name
|
||||
|
||||
Returns:
|
||||
Generator[tuple[str, str], None, None]: map of installed dependency to its version
|
||||
Yields:
|
||||
tuple[str, str]: map of installed dependency to its version
|
||||
"""
|
||||
def dependencies_by_key(key: str) -> Generator[str, None, None]:
|
||||
# in importlib it returns requires in the following format
|
||||
|
@ -76,8 +76,8 @@ class Web(Handler):
|
||||
args(argparse.Namespace): command line args
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
Generator[str, None, None]: command line arguments which were used for this specific command
|
||||
Yields:
|
||||
str: command line arguments which were used for this specific command
|
||||
"""
|
||||
# read configuration path from current settings
|
||||
if (configuration_path := configuration.path) is not None:
|
||||
|
@ -80,6 +80,13 @@ class Lock(LazyLogging):
|
||||
self.paths = configuration.repository_paths
|
||||
self.reporter = Client.load(repository_id, configuration, report=args.report)
|
||||
|
||||
def check_user(self) -> None:
|
||||
"""
|
||||
check if current user is actually owner of ahriman root
|
||||
"""
|
||||
check_user(self.paths, unsafe=self.unsafe)
|
||||
self.paths.tree_create()
|
||||
|
||||
def check_version(self) -> None:
|
||||
"""
|
||||
check web server version
|
||||
@ -89,13 +96,6 @@ class Lock(LazyLogging):
|
||||
self.logger.warning("status watcher version mismatch, our %s, their %s",
|
||||
__version__, status.version)
|
||||
|
||||
def check_user(self) -> None:
|
||||
"""
|
||||
check if current user is actually owner of ahriman root
|
||||
"""
|
||||
check_user(self.paths, unsafe=self.unsafe)
|
||||
self.paths.tree_create()
|
||||
|
||||
def clear(self) -> None:
|
||||
"""
|
||||
remove lock file
|
||||
|
@ -57,6 +57,7 @@ class Printer:
|
||||
"""
|
||||
return []
|
||||
|
||||
# pylint: disable=redundant-returns-doc
|
||||
def title(self) -> str | None:
|
||||
"""
|
||||
generate entry title from content
|
||||
|
@ -67,7 +67,7 @@ class FilteredAccessLogger(AccessLogger):
|
||||
Args:
|
||||
request(BaseRequest): http reqeust descriptor
|
||||
response(StreamResponse): streaming response object
|
||||
time(float):
|
||||
time(float): log record timestamp
|
||||
"""
|
||||
if self.is_logs_post(request) \
|
||||
or self.is_process_get(request):
|
||||
|
@ -95,21 +95,6 @@ class GitHub(Upload, HttpUpload):
|
||||
with path.open("rb") as archive:
|
||||
self.make_request("POST", url, params=[("name", path.name)], data=archive, headers=headers)
|
||||
|
||||
def get_local_files(self, path: Path) -> dict[Path, str]:
|
||||
"""
|
||||
get all local files and their calculated checksums
|
||||
|
||||
Args:
|
||||
path(Path): local path to sync
|
||||
|
||||
Returns:
|
||||
dict[Path, str]: map of path objects to its checksum
|
||||
"""
|
||||
return {
|
||||
local_file: self.calculate_hash(local_file)
|
||||
for local_file in walk(path)
|
||||
}
|
||||
|
||||
def files_remove(self, release: dict[str, Any], local_files: dict[Path, str], remote_files: dict[str, str]) -> None:
|
||||
"""
|
||||
remove files from GitHub
|
||||
@ -140,6 +125,21 @@ class GitHub(Upload, HttpUpload):
|
||||
continue
|
||||
self.asset_upload(release, local_file)
|
||||
|
||||
def get_local_files(self, path: Path) -> dict[Path, str]:
|
||||
"""
|
||||
get all local files and their calculated checksums
|
||||
|
||||
Args:
|
||||
path(Path): local path to sync
|
||||
|
||||
Returns:
|
||||
dict[Path, str]: map of path objects to its checksum
|
||||
"""
|
||||
return {
|
||||
local_file: self.calculate_hash(local_file)
|
||||
for local_file in walk(path)
|
||||
}
|
||||
|
||||
def release_create(self) -> dict[str, Any]:
|
||||
"""
|
||||
create empty release
|
||||
|
@ -87,6 +87,20 @@ class S3(Upload):
|
||||
suffix = f"-{len(md5s)}" if len(md5s) > 1 else ""
|
||||
return f"{checksum.hexdigest()}{suffix}"
|
||||
|
||||
@staticmethod
|
||||
def files_remove(local_files: dict[Path, str], remote_objects: dict[Path, Any]) -> None:
|
||||
"""
|
||||
remove files which have been removed locally
|
||||
|
||||
Args:
|
||||
local_files(dict[Path, str]): map of local path object to its checksum
|
||||
remote_objects(dict[Path, Any]): map of remote path object to the remote s3 object
|
||||
"""
|
||||
for local_file, remote_object in remote_objects.items():
|
||||
if local_file in local_files:
|
||||
continue
|
||||
remote_object.delete()
|
||||
|
||||
@staticmethod
|
||||
def get_bucket(configuration: Configuration, section: str) -> Any:
|
||||
"""
|
||||
@ -105,20 +119,6 @@ class S3(Upload):
|
||||
aws_secret_access_key=configuration.get(section, "secret_key"))
|
||||
return client.Bucket(configuration.get(section, "bucket"))
|
||||
|
||||
@staticmethod
|
||||
def files_remove(local_files: dict[Path, str], remote_objects: dict[Path, Any]) -> None:
|
||||
"""
|
||||
remove files which have been removed locally
|
||||
|
||||
Args:
|
||||
local_files(dict[Path, str]): map of local path object to its checksum
|
||||
remote_objects(dict[Path, Any]): map of remote path object to the remote s3 object
|
||||
"""
|
||||
for local_file, remote_object in remote_objects.items():
|
||||
if local_file in local_files:
|
||||
continue
|
||||
remote_object.delete()
|
||||
|
||||
def files_upload(self, path: Path, local_files: dict[Path, str], remote_objects: dict[Path, Any]) -> None:
|
||||
"""
|
||||
upload changed files to s3
|
||||
|
@ -354,9 +354,9 @@ class Package(LazyLogging):
|
||||
Args:
|
||||
path(Path): path to package sources directory
|
||||
|
||||
Returns:
|
||||
Generator[Path, None, None]: list of paths of files which belong to the package and distributed together
|
||||
with this tarball. All paths are relative to the ``path``
|
||||
Yields:
|
||||
Path: list of paths of files which belong to the package and distributed together with this tarball.
|
||||
All paths are relative to the ``path``
|
||||
|
||||
Raises:
|
||||
PackageInfoError: if there are parsing errors
|
||||
|
@ -34,16 +34,6 @@ class RepositoryId:
|
||||
architecture: str
|
||||
name: str
|
||||
|
||||
@property
|
||||
def is_empty(self) -> bool:
|
||||
"""
|
||||
check if all data is supplied for the loading
|
||||
|
||||
Returns:
|
||||
bool: True in case if architecture or name are not set and False otherwise
|
||||
"""
|
||||
return not self.architecture or not self.name
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
"""
|
||||
@ -56,6 +46,16 @@ class RepositoryId:
|
||||
return ""
|
||||
return f"{self.architecture}-{self.name}" # basically the same as used for command line
|
||||
|
||||
@property
|
||||
def is_empty(self) -> bool:
|
||||
"""
|
||||
check if all data is supplied for the loading
|
||||
|
||||
Returns:
|
||||
bool: True in case if architecture or name are not set and False otherwise
|
||||
"""
|
||||
return not self.architecture or not self.name
|
||||
|
||||
def query(self) -> list[tuple[str, str]]:
|
||||
"""
|
||||
generate query parameters
|
||||
|
@ -41,8 +41,8 @@ def _dynamic_routes(module_root: Path) -> dict[str, Type[View]]:
|
||||
Returns:
|
||||
dict[str, Type[View]]: map of the route to its view
|
||||
"""
|
||||
def is_base_view(clz: Any) -> TypeGuard[Type[BaseView]]:
|
||||
return isinstance(clz, type) and issubclass(clz, BaseView)
|
||||
def is_base_view(clazz: Any) -> TypeGuard[Type[BaseView]]:
|
||||
return isinstance(clazz, type) and issubclass(clazz, BaseView)
|
||||
|
||||
routes: dict[str, Type[View]] = {}
|
||||
for module_info in _modules(module_root):
|
||||
|
Reference in New Issue
Block a user