Skip to content

Commit

Permalink
Introduction of 2.0.0.
Browse files Browse the repository at this point in the history
This patch provides a major review of all files. The structure has been
changed.

A lot has been done but the focus was to fix the issue with the huge files
which hangs before being tested.

From the usage perspective, this patch does not changes anything.
  • Loading branch information
funilrys committed Mar 3, 2020
1 parent c42b49f commit 49876fb
Show file tree
Hide file tree
Showing 33 changed files with 2,420 additions and 2,010 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
colorama
domain2idna
PyFunceble
pyyaml
ultimate-hosts-blacklist-helpers>=1.20.1
ultimate-hosts-blacklist-whitelist
17 changes: 12 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ def _get_long_description(): # pragma: no cover
name=PYPI_NAME,
version=_get_version(),
install_requires=_get_requirements(),
description="The tool to update the input source repositories of the Ultimate-Hosts-Blacklist project.", # pylint: disable=line-too-long
description="The tool to update the input source "
"repositories of the Ultimate-Hosts-Blacklist project.",
long_description=_get_long_description(),
license="MIT",
url="https://github.com/Ultimate-Hosts-Blacklist/dev-center/tree/input-repo-updater",
platforms=["any"],
packages=["ultimate_hosts_blacklist.{0}".format(MODULE)],
packages=[
"ultimate_hosts_blacklist.{0}".format(MODULE),
"ultimate_hosts_blacklist.{0}.cleaner".format(MODULE),
"ultimate_hosts_blacklist.{0}.config".format(MODULE),
"ultimate_hosts_blacklist.{0}.installer".format(MODULE),
"ultimate_hosts_blacklist.{0}.tester".format(MODULE),
"ultimate_hosts_blacklist.{0}.updater".format(MODULE),
],
keywords=["Python", "hosts", "hosts file"],
classifiers=[
"Environment :: Console",
Expand All @@ -104,9 +112,8 @@ def _get_long_description(): # pragma: no cover
"uhb-input-repo-updater=ultimate_hosts_blacklist.{0}:_command_line".format(
MODULE
),
"ultimate-hosts-blacklist-input-repo-updater=ultimate_hosts_blacklist.{0}:_command_line".format( # pylint: disable=line-too-long
MODULE
),
"ultimate-hosts-blacklist-input-repo-updater="
"ultimate_hosts_blacklist.{0}:_command_line".format(MODULE),
]
},
)
31 changes: 24 additions & 7 deletions ultimate_hosts_blacklist/input_repo_updater/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
The tool to update the input repositories of the Ultimate-Hosts-Blacklist project.
The main entry of the tool.
The main entrypoint.
License:
::
Expand Down Expand Up @@ -37,10 +37,13 @@

from colorama import Fore, Style
from colorama import init as initiate_coloration
from PyFunceble import VERSION as PyFuncebleVersion

from ultimate_hosts_blacklist.input_repo_updater.core import Core
from .authorization import Authorization
from .pre_loader import PreLoader
from .tester import Tester

VERSION = "1.34.3"
VERSION = "2.0.0"


def _command_line():
Expand All @@ -52,7 +55,8 @@ def _command_line():
initiate_coloration(autoreset=True)

parser = argparse.ArgumentParser(
description="The tool to update the input repositories of the Ultimate-Hosts-Blacklist project.", # pylint: disable=line-too-long
description="The tool to update the input repositories of "
"the Ultimate-Hosts-Blacklist project.",
epilog="Crafted with %s by %s"
% (
Fore.RED + "♥" + Fore.RESET,
Expand Down Expand Up @@ -91,6 +95,19 @@ def _command_line():
else:
logging_level = logging.INFO

Core(
logging_level=logging_level, multiprocessing=arguments.multiprocess
).process()
logging.basicConfig(
format="[%(asctime)s::%(levelname)s] %(message)s", level=logging_level
)

logging.info("Launcher version: %s", VERSION)
logging.info("PyFunceble version: %s", PyFuncebleVersion)

authorization = Authorization()

if authorization.get_authorization():
PreLoader(authorization)
Tester(arguments.multiprocess)

# Core(
# logging_level=logging_level, multiprocessing=arguments.multiprocess
# ).process()
106 changes: 52 additions & 54 deletions ultimate_hosts_blacklist/input_repo_updater/administration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
The tool to update the input repositories of the Ultimate-Hosts-Blacklist project.
Provide an interface to get or edit the administration file.
Provides an interface to get or edit the administration file.
License:
::
Expand Down Expand Up @@ -32,23 +32,48 @@
SOFTWARE.
"""

from ultimate_hosts_blacklist.helpers import Command, Dict, File
from ultimate_hosts_blacklist.input_repo_updater import logging
from ultimate_hosts_blacklist.input_repo_updater.configuration import Infrastructure
import logging
from datetime import datetime

from PyFunceble.helpers import Dict, File

from ultimate_hosts_blacklist.helpers import Command

from .config import Infrastructure, Outputs


class Administration:
"""
Provide the information of the administration file.
"""

# This is the location of the administration file.
location = File(Infrastructure.administration_file)
# Saves the administration file.
location = File(Outputs.admin_destination)
data = {}

def __init__(self):
self.data.update(self.get())
self.data.update(self.__get_them_all())

def __contains__(self, item):
return item in self.data

def __getitem__(self, name):
if name in self.data:
return self.data[name]

return None

def __getattr__(self, name):
if name in self.data:
return self.data[name]

raise AttributeError(name)

def __setattr__(self, name, value):
self.data[name] = value

def __delattr__(self, name):
if name in self.data:
del self.data[name]

@classmethod
def __convert_into_understandable(cls, data):
Expand All @@ -61,24 +86,13 @@ def __convert_into_understandable(cls, data):
:rtype: dict
"""

# We initiate a variable which will save the final
# output.
result = {}

for index, value in data.items():
# We loop through the keys and values
# of the given data.

if index in Infrastructure.unneeded_indexes:
# The currenctly needed index is not needed.

# We continue the loop.
continue

if index == "name":
# The index is the name.

# We get/set the name from the repository name.
result[index] = (
Command(
"basename `git rev-parse --show-toplevel`", allow_stdout=False
Expand All @@ -87,19 +101,18 @@ def __convert_into_understandable(cls, data):
.strip()
)
elif index in Infrastructure.should_be_bool:
# The index is in the list of indexes
# which should be bool interpretted.

# We convert the value to bool and append
# the result into the result.
result[index] = bool(int(value))
elif index in Infrastructure.should_be_int:
# The index is in the list of indexes
# which should be int interpretted.

# We conver the value to int and append
# the result into the result.
result[index] = int(value)
elif index in Infrastructure.should_be_dict:
result[index] = dict(value)
elif index in Infrastructure.should_be_datetime:
try:
result[index] = datetime.fromisoformat(value)
except ValueError:
result[index] = datetime.now()
elif index in Infrastructure.should_be_epoch_datetime:
result[index] = datetime.fromtimestamp(value)
else:
result[index] = value

Expand All @@ -116,51 +129,34 @@ def __convert_into_not_understandable(cls, data):
:rtype: dict
"""

# We initiate a variable which will save the final
# output.
result = {}
for index, value in data.items():
# We loop through the keys and values
# of the given data.

if index in Infrastructure.unneeded_indexes:
# The currenctly needed index is not needed.

# We continue.
continue

if index in Infrastructure.should_be_bool:
# The index is in the list of indexes
# which should be bool interpretted.

# We convert the value to bool then to str and append
# the result into the result.
result[index] = str(int(bool(value)))
result[index] = bool(value)
elif index in Infrastructure.should_be_int:
# The index is in the list of indexes
# which should be int interpretted.

# We conver the value to int and append
# the result into the result.
result[index] = int(value)
elif index in Infrastructure.should_be_datetime:
result[index] = value.isoformat()
elif index in Infrastructure.should_be_epoch_datetime:
result[index] = value.timestamp()
else:
result[index] = value

return result

def get(self):
def __get_them_all(self):
"""
Read and return the content of teh administration file.
"""

# We get the content of the administration file.
content = self.location.read()
logging.debug("Administration file content: \n{0}".format(content))
logging.debug("Administration file content: \n%s", content)

# We convert it to a dict.
data = Dict.from_json(content)

# And we return the understable version of it.
return self.__convert_into_understandable(data)

def save(self, data=None):
Expand All @@ -171,4 +167,6 @@ def save(self, data=None):
if data is None:
data = self.data

Dict(self.__convert_into_not_understandable(data)).to_json(self.location.file)
Dict(self.__convert_into_not_understandable(data)).to_json_file(
self.location.path
)
Loading

0 comments on commit 49876fb

Please sign in to comment.