Commit 9e77056a authored by FH's avatar FH

add: modules

file_functions
http_conf
http_fetchers
minor change :
gui also return is_done on cancel
import modules
parent c9bde4d5
#!/usr/bin/env python3
"""Handler module"""
import json
from collections import OrderedDict
class Handler():
"""Handler class"""
def close(self):
"""Close program"""
print("Closing ....")
exit()
def write_json(self, data, filename):
"""
Writes a named json file
:param data:
:param filename:
"""
try:
with open(filename, "w") as outfile:
json.dump(data, outfile)
return True
except OSError:
return False
def read_json(self, filename):
"""
Reads a named json file
:param filename:
:return data: OrderedDict
"""
result = list()
try:
with open(filename, "r") as infile:
result = json.loads(infile.read().decode(
"utf8"), object_pairs_hook=OrderedDict)
except OSError:
return False
return result
......@@ -74,6 +74,7 @@ class GraphicalUI(Gtk.Window):
self.button_done = Gtk.Button(txt.I_CONFIRM)
self.button_done.set_sensitive(False)
self.button_done.connect("clicked", self.done)
grid = Gtk.Grid(column_homogeneous=True,
column_spacing=10,
row_spacing=10)
......@@ -106,6 +107,7 @@ class GraphicalUI(Gtk.Window):
def cancel(self, button):
"""Cancel mirrorlist"""
self.custom_list = []
self.is_done = True
Gtk.main_quit()
def done(self, button):
......
#!/usr/bin/env python3
"""Pacman-Mirrors Web Configuration"""
MIRRORS_URL = "http://repo.manjaro.org/new/manjaro-web-repo/mirrors.json"
STATUS_URL = "http://repo.manjaro.org/new/manjaro-web-repo/docs/status.json"
BRANCHES = ("stable", "testing", "unstable")
REPO_ARCH = "$repo/$arch"
#/usr/bin/env python3
"""Manjaro Mirrors fetcher"""
import json
import urllib.request
from collections import OrderedDict
from http_conf import MIRRORS_URL, STATUS_URL
class Fetcher():
"""HTTP Fetcher"""
def get_mirror_list(self):
"""Get list of mirrors from manjaro.org"""
mirrors = list()
try:
with urllib.request.urlopen(MIRRORS_URL) as response:
mirrors = json.loads(response.read().decode(
"utf-8"), object_pairs_hook=OrderedDict)
except urllib.error.URLError:
print("Error getting mirror list from server")
return mirrors
def get_repo_states(self):
"""Get mirror states from manjaro.org"""
states = list()
try:
with urllib.request.urlopen(STATUS_URL) as response:
states = json.loads(
response.read().decode(
"utf-8"), object_pairs_hook=OrderedDict)
except urllib.error.URLError:
print("Error getting mirror states from server")
return states
......@@ -44,6 +44,8 @@ from pacman_mirrors import __version__
from .custom_help_formatter import CustomHelpFormatter
from . import i18n
from . import txt
from . import file_functions
from . import http_fetchers
# The interactive argument will be only available if Gtk is installed
try:
......@@ -251,8 +253,8 @@ class PacmanMirrors:
txt.ERROR, txt.SEP, txt.ERR_FILE_READ, txt.SEP,
err.filename, txt.SEP, err.strerror))
return config
def generate_mirror_list_common(self):
def gen_mirror_list_common(self):
"""Generate common mirrorlist"""
if len(self.good_servers) >= 3: # Avoid an empty mirrorlist
server_list = self.good_servers
......@@ -270,7 +272,7 @@ class PacmanMirrors:
self.modify_config(DEFAULT)
self.output_mirror_list(server_list, write_file=True)
def generate_mirror_list_interactive(self):
def gen_mirror_list_interactive(self):
"""
Prompt the user to select the mirrors with a gui.
......@@ -750,9 +752,9 @@ class PacmanMirrors:
self.command_line_parse()
self.load_server_lists()
if self.interactive:
self.generate_mirror_list_interactive()
self.gen_mirror_list_interactive()
else:
self.generate_mirror_list_common()
self.gen_mirror_list_common()
if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment