Commit 51efed03 authored by Frede H's avatar Frede H Committed by Ramon Buldó

Console UI (#41)

add console ui
consolidated texts in separate file
pep8 recommendations fixed
ui classes renamed
generated pot-file
parent 2895142d
......@@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: pacman-mirrors 3.1.0\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2017-01-19 15:16+0100\n"
"POT-Creation-Date: 2017-01-29 15:15+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -18,223 +18,251 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.3.4\n"
#: pacman_mirrors/pacman_mirrors.py:80
#: pacman_mirrors/txt.py:33
msgid "Error"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:81
#: pacman_mirrors/txt.py:34
msgid "Info"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:82
#: pacman_mirrors/txt.py:35
msgid "Warning"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:84
#: pacman_mirrors/txt.py:37
msgid "Timeout"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:85
#: pacman_mirrors/txt.py:38
msgid "HTTPException"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:87
#: pacman_mirrors/txt.py:40
msgid "PATH"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:88
#: pacman_mirrors/txt.py:41
msgid "FILE"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:89
#: pacman_mirrors/txt.py:42
msgid "SECONDS"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:91
#: pacman_mirrors/txt.py:44
msgid "Branch name"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:92
#: pacman_mirrors/txt.py:45
msgid "Comma separated list of countries, from which mirrors will be used"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:93
#: pacman_mirrors/txt.py:47
msgid "Output file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:94
#: pacman_mirrors/txt.py:48
msgid "Generate mirrorlist"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:95
#: pacman_mirrors/txt.py:49
msgid "Get current country using geolocation. Ignored if"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:96
#: pacman_mirrors/txt.py:50
msgid "is supplied"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:97
#: pacman_mirrors/txt.py:51
msgid "Generate custom mirrorlist"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:98
#: pacman_mirrors/txt.py:52
msgid "Generation method"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:99
#: pacman_mirrors/txt.py:53
msgid "Don't generate mirrorlist if"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:100
#: pacman_mirrors/txt.py:54
msgid "in the configuration file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:101
#: pacman_mirrors/txt.py:55
msgid "Mirrors list path"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:102
#: pacman_mirrors/txt.py:56
msgid "Quiet mode - less verbose output"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:103
#: pacman_mirrors/txt.py:57
msgid "Maximum waiting time for server response"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:104
#: pacman_mirrors/txt.py:58
msgid "Print the pacman-mirrors version"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:106
#: pacman_mirrors/txt.py:60
msgid "Cannot read file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:107
#: pacman_mirrors/txt.py:61
msgid "Cannot update file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:108
#: pacman_mirrors/txt.py:62
msgid "Cannot write file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:109
#: pacman_mirrors/txt.py:63
msgid "Must have root privileges"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:110
#: pacman_mirrors/txt.py:64
msgid "Cannot read server response"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:111
msgid "No server available"
#: pacman_mirrors/txt.py:65
msgid "server not available"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:112
#: pacman_mirrors/txt.py:66
msgid "Failed to reach server"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:113
#: pacman_mirrors/txt.py:67
msgid "The server did not complete the request"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:115
#: pacman_mirrors/txt.py:69
msgid "Available countries are"
msgstr ""
#: pacman_mirrors/txt.py:70
msgid "Custom mirrors file"
msgstr ""
#: pacman_mirrors/txt.py:71
msgid "doesn't exist."
msgstr ""
#: pacman_mirrors/txt.py:72
msgid "User generated mirror list"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:116
#: pacman_mirrors/txt.py:73
msgid "Saved personalized list of mirrors in"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:117
msgid "Custom mirrors file"
#: pacman_mirrors/txt.py:74
msgid "is missing"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:118
msgid "doesn't exist. Querying all servers"
#: pacman_mirrors/txt.py:75
msgid "Use `pacman-mirrors -c all` to reset list"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:119
msgid "Writing custom mirror file"
#: pacman_mirrors/txt.py:76
msgid "Mirrorlist generated and saved to"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:120
#: pacman_mirrors/txt.py:77
msgid "Writing mirror list"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:121
msgid "Mirrorlist generated and saved to"
#: pacman_mirrors/txt.py:78
msgid "No mirrors in selection"
msgstr ""
#: pacman_mirrors/txt.py:79
msgid "The mirror list is not changed"
msgstr ""
#: pacman_mirrors/txt.py:80
msgid "Option"
msgstr ""
#: pacman_mirrors/txt.py:81
msgid "Writing custom mirror file"
msgstr ""
#: pacman_mirrors/txt.py:82
msgid "Querying all servers"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:122
#: pacman_mirrors/txt.py:83
msgid "Querying servers, this may take some time"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:123
#: pacman_mirrors/txt.py:84
msgid "Using custom mirror list"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:124
#: pacman_mirrors/txt.py:85
msgid "Testing mirrors in"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:125
#: pacman_mirrors/txt.py:86
msgid "Wrong date format in state file"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:126
#: pacman_mirrors/txt.py:87
msgid "Randomizing server list"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:127
msgid "Option"
#: pacman_mirrors/txt.py:88
msgid "unknown country"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:128
msgid "unknown country"
#: pacman_mirrors/txt.py:89
msgid "Using all servers"
msgstr ""
#: pacman_mirrors/pacman_mirrors.py:129
msgid "Available countries are"
#: pacman_mirrors/txt.py:91
msgid "Manjaro mirrors by response time"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:33
msgid "Mirrors by response time"
#: pacman_mirrors/txt.py:92
msgid "Check mirrors for your personal list"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:54
#: pacman_mirrors/txt.py:93
msgid "Use"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:56
#: pacman_mirrors/txt.py:94
msgid "Country"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:56
msgid "Last sync"
#: pacman_mirrors/txt.py:95
msgid "Resp"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:56
msgid "URL"
#: pacman_mirrors/txt.py:96
msgid "Sync"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:62
msgid "Check mirrors for your personal list"
#: pacman_mirrors/txt.py:97
msgid "URL"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:63
#: pacman_mirrors/txt.py:98
msgid "Cancel"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:65
msgid "Confirm"
#: pacman_mirrors/txt.py:99
msgid "OK"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:103
#: pacman_mirrors/txt.py:100
msgid "Confirm selections"
msgstr ""
#: pacman_mirrors/pacman_mirrors_gui.py:110
#: pacman_mirrors/txt.py:101
msgid "I want to use these mirrors"
msgstr ""
#!/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
Utilities Module
"""
import json
class ConsoleHelpers:
"""
Console Helpers class
"""
@staticmethod
def list_to_tuple(list_data, named_tuple):
"""
Comvert list to a list with named tuples
:param list_data: the list to convert
:param named_tuple: tuple list item converts to
:return data: list of named tuples
"""
tdata = json.dumps(list_data)
data = json.loads(tdata, object_hook=lambda x: named_tuple(**x))
return data
@staticmethod
def rows_from_tuple(servers, joiner=" | "):
"""
Generates equal formatted lines
:param servers: named tuples
:param joiner: string used to join tuple items
:param cols: column names
:return lines: list of nicely formatted lines
"""
lines = []
if not servers:
return lines
# calculate max col width
col_width = [max(len(x) for x in col) for col in zip(*servers)]
# generate linies
for line in servers:
lines.append(joiner.join("{:{}}".format(x, col_width[i])
for i, x in enumerate(line)))
return lines
#!/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
Console UI Module
"""
from collections import namedtuple
import npyscreen
from . import txt
from . console_helpers import ConsoleHelpers
from . import i18n
Util = ConsoleHelpers
_ = i18n.language.gettext
class ConsoleUI(npyscreen.NPSAppManaged):
"""
App
"""
def __init__(self, server_list):
npyscreen.NPSAppManaged.__init__(self)
# Server lists
self.server_list = server_list
self.custom_list = []
self.is_done = False
def main(self):
"""
Main
"""
main_server_list = []
server = namedtuple("Server", ["country",
"response_time",
"last_sync",
"url"])
header_cols = ({"country": txt.I_COUNTRY,
"response_time": txt.I_RESPONSE,
"last_sync": txt.I_LAST_SYNC,
"url": txt.I_URL})
main_server_list.append(header_cols)
main_server_list.extend(self.server_list)
servers = Util.list_to_tuple(main_server_list, server)
server_rows = Util.rows_from_tuple(servers)
header_row = ("{:<5}".format(txt.I_USE) +
(server_rows[0].replace("|", " ").strip()))
del server_rows[0]
# setup form
mainform = npyscreen.Form(name=txt.I_TITLE)
mainform.add(npyscreen.TitleFixedText, name=txt.I_LIST_TITLE)
mainform.add(npyscreen.TitleFixedText, name=header_row)
selected_servers = mainform.add(npyscreen.MultiSelect,
max_height=0,
name=txt.I_LIST_TITLE,
value=[],
values=server_rows,
scroll_exit=True)
# activate form
mainform.edit()
# done
self.done(selected_servers.get_selected_objects())
def done(self, selection):
"""
After editing
:param selection:
"""
if selection:
for mirror in selection:
server = mirror.split("|")
self.custom_list.append({"country": server[0].strip(),
"response_time": server[1].strip(),
"last_sync": server[2].strip(),
"url": server[3].strip()})
self.is_done = True
self.setNextForm(None)
def run(server_list):
"""
Run
"""
app = ConsoleUI(server_list)
app.run()
return app
......@@ -18,30 +18,32 @@
# Authors: Esclapion
# Hugo Posnic <huluti@manjaro.org>
""" Module PacmanMirrors GUI"""
""" Module GraphicalUI GUI"""
import gi
from . import i18n
from . import txt
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from . import i18n
_ = i18n.language.gettext
class PacmanMirrors(Gtk.Window):
""" Class PacmanMirrors """
class GraphicalUI(Gtk.Window):
""" Class GraphicalUI """
def __init__(self, server_list):
Gtk.Window.__init__(self, title=_("Mirrors by response time"))
Gtk.Window.__init__(self, title=txt.I_TITLE)
self.set_size_request(700, 350)
self.set_border_width(10)
self.set_position(Gtk.WindowPosition.CENTER)
mirrors_list = []
for server in server_list:
mirrors_list.append((False,
server["country"],
"{}h {}m".format(server["last_sync"][:2],
server["last_sync"][-2:]),
server["url"][:-20]))
mirrors_list.append((
False, server["country"],
"{}h {}m".format(server["last_sync"][:2],
server["last_sync"][-2:]),
server["url"][:-20]))
self.mirrors_liststore = Gtk.ListStore(bool, str, str, str)
for mirror_ref in mirrors_list:
self.mirrors_liststore.append(list(mirror_ref))
......@@ -51,22 +53,25 @@ class PacmanMirrors(Gtk.Window):
self.treeview.set_vexpand(True)
renderer = Gtk.CellRendererToggle()
renderer.connect("toggled", self.on_toggle)
column = Gtk.TreeViewColumn(_("Use"), renderer, active=0)
column = Gtk.TreeViewColumn(txt.I_USE, renderer, active=0)
self.treeview.append_column(column)
for i, column_title in enumerate([_("Country"), _("Last sync"), _("URL")]):
for i, column_title in enumerate([txt.I_COUNTRY,
txt.I_LAST_SYNC,
txt.I_URL]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i+1)
self.treeview.append_column(column)
scrolled_tree.add(self.treeview)
header = Gtk.Label(_("Check mirrors for your personal list"))
button_cancel = Gtk.Button(_("Cancel"))
header = Gtk.Label(txt.I_LIST_TITLE)
button_cancel = Gtk.Button(txt.I_CANCEL)
button_cancel.connect("clicked", self.cancel)
self.button_done = Gtk.Button(_("Confirm"))
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)
grid = Gtk.Grid(column_homogeneous=True,
column_spacing=10,
row_spacing=10)
grid.attach(header, 0, 0, 2, 1)
grid.attach(scrolled_tree, 0, 1, 2, 1)
grid.attach(button_cancel, 0, 2, 1, 1)
......@@ -80,8 +85,8 @@ class PacmanMirrors(Gtk.Window):
self.is_done = False
def on_toggle(self, widget, path):
# Add or remove server from custom list
def on_toggle(self, path):
"""Add or remove server from custom list"""
self.mirrors_liststore[path][0] = not self.mirrors_liststore[path][0]
if self.mirrors_liststore[path][0]:
for server in self.server_list:
......@@ -94,20 +99,21 @@ class PacmanMirrors(Gtk.Window):
self.button_done.set_sensitive(bool(self.custom_list))
def cancel(self, button):
def cancel(self):
"""Cancel mirrorlist"""
self.custom_list = []
Gtk.main_quit()
def done(self, button):
# Confirm choice
dialog = Gtk.Dialog(_("Confirm selections"), None, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
def done(self):
"""Confirm choice"""
dialog = Gtk.Dialog(txt.I_CONFIRM_SELECTION, None, 0, (
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
dialog.set_transient_for(self)
dialog.set_border_width(10)
box = dialog.get_content_area()
box.set_spacing(10)
box.add(Gtk.Label(_("I want to use these mirrors")))
box.add(Gtk.Label(txt.I_USE_THESE_MIRRORS))
dialog.show_all()
response = dialog.run()
......@@ -120,8 +126,10 @@ class PacmanMirrors(Gtk.Window):
# Go back to selection
dialog.destroy()
def run(server_list):
window = PacmanMirrors(server_list)
"""Run interactive"""
window = GraphicalUI(server_list)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
......
This diff is collapsed.
#!/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
Text Module
"""
from . import i18n
_ = i18n.language.gettext
'''
BEGIN translatable
'''
# message type
ERROR = _("Error")
INFO = _("Info")
WARN = _("Warning")
# error types
TIMEOUT = _("Timeout")
HTTP_EXCEPTION = _("HTTPException")
# special words
PATH = _("PATH")
FILE = _("FILE")
SECONDS = _("SECONDS")
# help messages
HLP_ARG_BRANCH = _("Branch name")
HLP_ARG_COUNTRY = _(
"Comma separated list of countries, from which mirrors will be used")
HLP_ARG_FILE = _("Output file")
HLP_ARG_GENERATE = _("Generate mirrorlist")
HLP_ARG_GEOIP_P1 = _("Get current country using geolocation. Ignored if")
HLP_ARG_GEOIP_P2 = _("is supplied")
HLP_ARG_INTERACTIVE = _("Generate custom mirrorlist")
HLP_ARG_METHOD = _("Generation method")
HLP_ARG_NOUPDATE_P1 = _("Don't generate mirrorlist if")
HLP_ARG_NOUPDATE_P2 = _("in the configuration file")
HLP_ARG_PATH = _("Mirrors list path")
HLP_ARG_QUIET = _("Quiet mode - less verbose output")
HLP_ARG_TIMEOUT = _("Maximum waiting time for server response")
HLP_ARG_VERSION = _("Print the pacman-mirrors version")
# error messages
ERR_FILE_READ = _("Cannot read file")
ERR_FILE_UPDATE = _("Cannot update file")
ERR_FILE_WRITE = _("Cannot write file")
ERR_NOT_ROOT = _("Must have root privileges")
ERR_SERVER_HTTP_EXCEPTION = _("Cannot read server response")
ERR_SERVER_NOT_AVAILABLE = _("server not available")
ERR_SERVER_NOT_REACHABLE = _("Failed to reach server")