Skip to content
Snippets Groups Projects
Commit a82d96f1 authored by Frede H's avatar Frede H :speech_balloon:
Browse files

refactored app folder structure

parent 3dc028a8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#
# This file is part of pacman-mirrors.
#
# pacman-mirrors is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pacman-mirrors is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pacman-mirrors. If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Frede Hundewadt <frede@hundewadt.dk>
"""Pacman-Mirrors Mirror"""
class Mirror:
"""Mirror Class"""
def __init__(self):
self.countrylist = []
self.mirrorlist = []
def add(self, country, url, protocols,
branches=None, last_sync="00:00", resp_time="00.00"):
"""Append mirror
:param country:
:param url:
:param protocols:
:param branches: optional from status.json
:param last_sync: optional from status.json
:param resp_time: optional from status.json
"""
if branches is None:
branches = [-1, -1, -1]
if country not in self.countrylist:
self.countrylist.append(country)
# translate negative integer in status.json
if last_sync == -1:
last_sync = "9999:99"
resp_time = "9999.99"
# sort protocols in reversed order https,http,ftps,ftp
protocols = sorted(protocols, reverse=True)
mirror = {
"branches": branches,
"country": country,
"last_sync": last_sync,
"protocols": protocols,
"resp_time": resp_time,
"url": url
}
self.mirrorlist.append(mirror)
def seed(self, mirrors, status=False, custom=False):
"""Seed mirrorlist
:param mirrors:
:param status:
:param custom:
"""
if custom: # clear previous data
self.countrylist = []
self.mirrorlist = []
for server in mirrors:
if status:
self.add(server["country"],
server["url"],
server["protocols"],
server["branches"],
server["last_sync"])
else:
self.add(server["country"],
server["url"],
server["protocols"])
...@@ -23,10 +23,10 @@ import datetime ...@@ -23,10 +23,10 @@ import datetime
import os import os
import sys import sys
from pacman_mirrors.functions import miscfn
from pacman_mirrors.constants import txt
from pacman_mirrors.constants import colors as color from pacman_mirrors.constants import colors as color
from pacman_mirrors.constants import txt
from pacman_mirrors.functions import jsonfn from pacman_mirrors.functions import jsonfn
from pacman_mirrors.functions import miscfn
def check_file(file, dir=False): def check_file(file, dir=False):
......
...@@ -34,8 +34,8 @@ from urllib.request import urlopen ...@@ -34,8 +34,8 @@ from urllib.request import urlopen
from pacman_mirrors import __version__ from pacman_mirrors import __version__
from pacman_mirrors.config import configuration as conf from pacman_mirrors.config import configuration as conf
from pacman_mirrors.functions import filefn
from pacman_mirrors.constants import txt from pacman_mirrors.constants import txt
from pacman_mirrors.functions import filefn
from pacman_mirrors.functions import jsonfn from pacman_mirrors.functions import jsonfn
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
"""Pacman-Mirrors Niscellaneous Functions""" """Pacman-Mirrors Niscellaneous Functions"""
import shutil import shutil
from pacman_mirrors.constants import txt
from pacman_mirrors.constants import colors as color from pacman_mirrors.constants import colors as color
from pacman_mirrors.constants import txt
def debug(where, what, value): def debug(where, what, value):
......
...@@ -26,8 +26,9 @@ gi.require_version("Gtk", "3.0") ...@@ -26,8 +26,9 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk from gi.repository import Gtk
from operator import itemgetter from operator import itemgetter
from random import shuffle from random import shuffle
from pacman_mirrors.translation import i18n
from pacman_mirrors.constants import txt from pacman_mirrors.constants import txt
from pacman_mirrors.translation import i18n
_ = i18n.language.gettext _ = i18n.language.gettext
......
...@@ -33,18 +33,18 @@ from operator import itemgetter ...@@ -33,18 +33,18 @@ from operator import itemgetter
from random import shuffle from random import shuffle
from pacman_mirrors import __version__ from pacman_mirrors import __version__
from pacman_mirrors.classes.mirror import Mirror
from pacman_mirrors.config import configuration as conf
from pacman_mirrors.config import configfn from pacman_mirrors.config import configfn
from pacman_mirrors.config import configuration as conf
from pacman_mirrors.constants import colors as color from pacman_mirrors.constants import colors as color
from pacman_mirrors.functions import jsonfn from pacman_mirrors.constants import txt
from pacman_mirrors.functions import apifn from pacman_mirrors.functions import apifn
from pacman_mirrors.functions import filefn from pacman_mirrors.functions import filefn
from pacman_mirrors.functions import httpfn from pacman_mirrors.functions import httpfn
from pacman_mirrors.functions import mirrorfn from pacman_mirrors.functions import jsonfn
from pacman_mirrors.functions import miscfn from pacman_mirrors.functions import miscfn
from pacman_mirrors.constants import txt
from pacman_mirrors.functions import validfn from pacman_mirrors.functions import validfn
from pacman_mirrors.mirrors.mirror import Mirror
from pacman_mirrors.mirrors import mirrorfn
from pacman_mirrors.translation import i18n from pacman_mirrors.translation import i18n
from pacman_mirrors.translation.custom_help_formatter import CustomHelpFormatter from pacman_mirrors.translation.custom_help_formatter import CustomHelpFormatter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment