Esempio n. 1
0
    def test_init(self):
        command_item_1 = CommandItem("command_item_1", "exit")
        command_item_2 = CommandItem("command_item_2", "ls", ["-l", "-a", "~"],
                                     self.menu, True)
        command_item_3 = CommandItem(text="command_item_3",
                                     command="rm",
                                     menu=self.menu,
                                     arguments=["-r", "-f", "./test"],
                                     should_exit=False)

        self.assertEqual(command_item_1.text, "command_item_1")
        self.assertEqual(command_item_2.text, "command_item_2")
        self.assertEqual(command_item_3.text, "command_item_3")
        self.assertEqual(command_item_1.menu, None)
        self.assertEqual(command_item_2.menu, self.menu)
        self.assertEqual(command_item_3.menu, self.menu)
        self.assertFalse(command_item_1.should_exit)
        self.assertTrue(command_item_2.should_exit)
        self.assertFalse(command_item_3.should_exit)
        self.assertEqual(command_item_1.command, "exit")
        self.assertEqual(command_item_2.command, "ls")
        self.assertEqual(command_item_3.command, "rm")
        self.assertEqual(command_item_1.arguments, [])
        self.assertEqual(command_item_2.arguments, ["-l", "-a", "~"])
        self.assertEqual(command_item_3.arguments, ["-r", "-f", "./test"])
Esempio n. 2
0
class InstallSoft:
    """
    #
    # Модуль встановлення програм
    #
    """

    # Основне меню
    menu = CursesMenu("Install software", "DEPENDENCES!!!")

    # Пункти меню
    _menu_items = [
        CommandItem("All software", "bash bash/install.sh"),
        CommandItem("ssh", "sudo apt install ssh"),
        CommandItem("Gparted", "sudo apt install gparted"),
        CommandItem("VLC", "sudo apt install vlc"),
        CommandItem("screenfetch", "sudo apt install screenfetch"),
        CommandItem("f.lux", "bash bash/f.lux.sh"),
        CommandItem("gimp", "sudo apt install gimp"),
        CommandItem("Kdenlive", "sudo apt install kdenlive"),
        CommandItem("Wine", "sudo apt install wine"),
        CommandItem("Rhythmbox", "sudo apt install rhythmbox")
    ]

    # Додавання пунктів до меню
    for item in _menu_items:
        menu.append_item(item)
Esempio n. 3
0
class RemoveProgram:
    """
    #
    # Видалення програм
    #
    """

    # Основне меню
    menu = CursesMenu("Remove software", "YOU DELETE SOFT!!!")

    # Пункти меню
    _menu_items = [
        CommandItem("All software", "bash bash/remove.sh"),
        CommandItem("ssh", "sudo apt autoremove ssh"),
        CommandItem("Gparted", "sudo apt autoremove gparted"),
        CommandItem("VLC", "sudo apt autoremove vlc"),
        CommandItem("screenfetch", "sudo apt autoremove screenfetch"),
        CommandItem("f.lux", "sudo apt autoremove flux"),
        CommandItem("gimp", "sudo apt autoremove gimp"),
        CommandItem("Kdenlive", "sudo apt autoremove kdenlive"),
        CommandItem("Wine", "sudo apt autoremove wine"),
        CommandItem("Rhythmbox", "sudo apt autoremove rhythmbox")
    ]
    # Додавання пунктів до меню
    for item in _menu_items:
        menu.append_item(item)
Esempio n. 4
0
class Xfce:
    """
    #
    # Модуль налаштувань для XFCE
    #
    """

    # Основне меню
    menu = CursesMenu("XFCE soft")

    # Пункти меню
    _menu_items = [
        CommandItem("All remove", "bash bash/xfce.sh"),
        CommandItem("Remove XFCE4-Notes", "sudo apt autoremove xfce4-notes"),
        CommandItem("Remove Pidgin", "sudo apt autoremove pidgin"),
        CommandItem("Remove Thunderbird", "sudo apt autoremove thunderird"),
        CommandItem("Remove Parole", "sudo apt autoremove parole"),
        CommandItem("Remove Sudoku", "sudo apt autoremove gnome-sudoku"),
        CommandItem("Remove Mines", "sudo apt autoremove gnome-mines"),
        CommandItem("Remove firefox", "sudo apt autoremove firefox")
    ]

    # Додавання пунктів до меню
    for item in _menu_items:
        menu.append_item(item)
Esempio n. 5
0
def parse_old_menu(menu_data):
    """
    Take an old-style menuData dictionary and return a CursesMenu

    :param dict menu_data:
    :return: A new CursesMenu
    :rtype: CursesMenu
    """
    menu_title = menu_data['title']
    menu = CursesMenu(menu_title)
    for item in menu_data["options"]:
        item_type = item["type"]
        item_title = item["title"]
        if item_type == menuItem.COMMAND:
            item_command = item["command"]
            menu.append_item(CommandItem(item_title, item_command, menu))
        elif item_type == menuItem.FUNCTION:
            item_function = item["function"]
            menu.append_item(FunctionItem(item_title, item_function, menu))
        elif item_type == menuItem.EXITMENU:
            menu.append_item(ExitItem(item_title, menu))
        elif item_type == menuItem.NUMBER:
            menu.append_item(SelectionItem(item_title, menu))
        elif item_type == menuItem.MENU:
            new_menu = parse_old_menu(item)
            menu.append_item(SubmenuItem(item_title, menu, new_menu))

    return menu
Esempio n. 6
0
    def test_return(self):
        if platform.system().lower() == "windows":
            return_command_item = CommandItem("return_command_item", "exit 1")
        else:
            return_command_item = CommandItem("return_command_item", "return 1")

        return_command_item.action()

        self.assertEqual(return_command_item.get_return(), 1)
Esempio n. 7
0
def step_impl(context):
    context.menu = CursesMenu("Test Menu", "Subtitle")
    context.menu_item = MenuItem("NORMAL", "Menu Item")
    context.menu.append_item(context.menu_item)
    context.function_item = FunctionItem("NORMAL", "Call a Python function",
                                         input, ["Enter an input"])
    context.menu.append_item(context.function_item)
    context.command_item = CommandItem("NORMAL", "Run a console command",
                                       "ipconfig /all")
    context.menu.append_item(context.command_item)
    pass
Esempio n. 8
0
class SshX:
    """
    #
    # Модуль підключення SSH з підтримкою запуска програм з графічним інтерфейсом
    #
    """

    menu = CursesMenu("SSH connect with X-window support")

    # Пункти
    _menu_items = [
        CommandItem("Home ms-7519(ivan)", "ssh -X [email protected]"),
        CommandItem("Acer-aspire V5-131(ivan)", "ssh -X [email protected]"),
        CommandItem("Lenovo B560(diana)", "ssh -X [email protected]"),
        CommandItem("Server(home)", "ssh -X [email protected]")
    ]

    #  Додаваня пунктів до меню
    for item in _menu_items:
        menu.append_item(item)
Esempio n. 9
0
class SSH:
    """
   #
   # SSH підключення
   #
    """

    # Основне меню
    menu = CursesMenu("SSH Connect")

    # Пунктии меню
    _menu_items = [
        CommandItem("DIR 615-E4", "ssh [email protected]"),
        CommandItem("Home ms-7519(ivan)", "ssh [email protected]"),
        CommandItem("Acer-aspire V5-131(ivan)", "ssh [email protected]"),
        CommandItem("Lenovo B560(diana)", "ssh [email protected]"),
        CommandItem("Server(home)", "ssh [email protected]")
    ]

    # Додавання пунктів до меню
    for item in _menu_items:
        menu.append_item(item)
Esempio n. 10
0
 def test_call(self, mock_class):
     command_item = CommandItem("command_item", "ls", ["-l", "-a", "~"])
     command_item.action()
     mock_class.run.assert_called_with("ls -l -a ~", shell=True)
Esempio n. 11
0
    def test_run(self):
        create_item = CommandItem("create_item", 'echo hello>test.txt')
        if platform.system().lower() == "windows":
            delete_item = CommandItem("delete_item", "del test.txt")
            expected_contents = "hello \n"
        else:
            delete_item = CommandItem("delete_item", "rm test.txt")
            expected_contents = "hello\n"
        create_item.action()
        self.assertEqual(create_item.get_return(), 0)
        self.assertTrue(os.path.isfile("test.txt"))

        with open("test.txt", 'r') as text:
            self.assertEqual(text.read(), expected_contents)

        delete_item.action()
        self.assertEqual(delete_item.get_return(), 0)
        self.assertFalse(os.path.isfile("test.txt"))
Esempio n. 12
0
# Класи для створення меню
from cursesmenu import CursesMenu
from cursesmenu.items import CommandItem, SubmenuItem
import platform

from modules import InstallSoft as soft
from modules import RemoveProgram as remove
from modules import SSH as ssh
from modules import SshX as ssh_X
from modules import Xfce as xfce

# Створення основного меню
menu = CursesMenu("Ubuntu universal script", platform.version())
# Створення основних пунктів
_menu_items = [
    CommandItem("Update paсkages", "sudo apt update"),
    CommandItem("Upgrade paсkages", "sudo apt upgrade"),
    CommandItem("Autoremove paсkages", "sudo apt autoremove"),
    CommandItem("Remove other kernel`s", "bash bash/remove_kernel.sh"),
    CommandItem(
        "Cleaning pickings removed paсkages",
        "sudo dpkg -l | awk '/^rc/ {print $2}' | xargs sudo dpkg --purge"),

    # Відображення підменю
    SubmenuItem("Install soft", soft.menu, menu),
    SubmenuItem("Remove software", remove.menu, menu),
    SubmenuItem("Xfce soft", xfce.menu, menu),
    SubmenuItem("SSH Connect", ssh.menu, menu),
    SubmenuItem("SSH connect with X-window support", ssh_X.menu, menu)
]
Esempio n. 13
0
def step_impl(context):
    context.command_item = CommandItem("NORMAL", "Run a console command",
                                       "ipconfig /all")
    context.menu.append_item(context.command_item)
    pass
Esempio n. 14
0
from cursesmenu.items import MenuItem, FunctionItem, CommandItem, SubmenuItem

# Create the menu
menu = CursesMenu("Title", "Subtitle")

# Create some items

# MenuItem is the base class for all items, it doesn't do anything when selected
menu_item = MenuItem("Menu Item")

# A FunctionItem runs a Python function when selected
function_item = FunctionItem("Call a Python function", input,
                             ["Enter an input"])

# A CommandItem runs a console command
command_item = CommandItem("Run a console command", "touch hello.txt")

# A SelectionMenu constructs a menu from a list of strings
selection_menu = SelectionMenu(["item1", "item2", "item3"])

# A SubmenuItem lets you add a menu (the selection_menu above, for example)
# as a submenu of another menu
submenu_item = SubmenuItem("Submenu item", selection_menu, menu)

# Once we're done creating them, we just add the items to the menu
menu.append_item(menu_item)
menu.append_item(function_item)
menu.append_item(command_item)
menu.append_item(submenu_item)

# Finally, we call show to show the menu and allow the user to interact