Esempio n. 1
0
def main():
    """Main entry point of the program"""

    parser = argparse.ArgumentParser(
        description=_(
            "Deploy and setup developers environment easily on ubuntu"),
        epilog=_(
            "Note that you can also configure different debug logs behaviors using "
            "LOG_CFG pointing to a log yaml profile."),
        add_help=False)
    parser.add_argument('--help', action=_HelpAction,
                        help=_('Show this help'))  # add custom help
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help=_("Increase output verbosity (2 levels)"))

    parser.add_argument('-r',
                        '--remove',
                        action="store_true",
                        help=_("Remove specified framework if installed"))

    # set logging ignoring unknown options
    set_logging_from_args(sys.argv, parser)

    mainloop = MainLoop()

    # load frameworks and initialize parser
    load_frameworks()
    cli.main(parser)

    mainloop.run()
Esempio n. 2
0
def main():
    """Main entry point of the program"""

    if "udtc" in sys.argv[0]:
        print(_("WARNING: 'udtc' command is the previous name of Ubuntu Make. Please use the 'umake' command from now "
                "on providing the exact same features. The 'udtc' command will be removed soon."))

    parser = argparse.ArgumentParser(description=_("Deploy and setup developers environment easily on ubuntu"),
                                     epilog=_("Note that you can also configure different debug logging behavior using "
                                              "LOG_CFG that points to a log yaml profile."),
                                     add_help=False)
    parser.add_argument('--help', action=_HelpAction, help=_('Show this help'))  # add custom help
    parser.add_argument("-v", "--verbose", action="count", default=0, help=_("Increase output verbosity (2 levels)"))

    parser.add_argument('-r', '--remove', action="store_true", help=_("Remove specified framework if installed"))

    parser.add_argument('--version', action="store_true", help=_("Print version and exit"))

    # set logging ignoring unknown options
    set_logging_from_args(sys.argv, parser)

    mainloop = MainLoop()

    # load frameworks and initialize parser
    load_frameworks()
    cli.main(parser)

    mainloop.run()
Esempio n. 3
0
def main():
    """Main entry point of the program"""

    if "udtc" in sys.argv[0]:
        print(
            _("WARNING: 'udtc' command is the previous name of Ubuntu Make. Please use the 'umake' command from now "
              "on providing the exact same features. The 'udtc' command will be removed soon."
              ))

    parser = argparse.ArgumentParser(
        description=_(
            "Deploy and setup developers environment easily on ubuntu"),
        epilog=_(
            "Note that you can also configure different debug logging behavior using "
            "LOG_CFG that points to a log yaml profile."),
        add_help=False)
    parser.add_argument('--help', action=_HelpAction,
                        help=_('Show this help'))  # add custom help
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help=_("Increase output verbosity (2 levels)"))

    parser.add_argument('-r',
                        '--remove',
                        action="store_true",
                        help=_("Remove specified framework if installed"))

    list_group = parser.add_argument_group(
        "List frameworks").add_mutually_exclusive_group()
    list_group.add_argument('-l',
                            '--list',
                            action="store_true",
                            help=_("List all frameworks"))
    list_group.add_argument('--list-installed',
                            action="store_true",
                            help=_("List installed frameworks"))
    list_group.add_argument('--list-available',
                            action="store_true",
                            help=_("List installable frameworks"))

    parser.add_argument('--version',
                        action="store_true",
                        help=_("Print version and exit"))

    # set logging ignoring unknown options
    set_logging_from_args(sys.argv, parser)

    mainloop = MainLoop()

    # load frameworks
    load_frameworks(force_loading=should_load_all_frameworks(sys.argv))

    # initialize parser
    cli.main(parser)

    mainloop.run()
Esempio n. 4
0
 def setUp(self):
     super().setUp()
     self.mockUIPlug = Mock()
     self.mockUIPlug._display.side_effect = self.display_UIPlug
     self.contentType = Mock()
     self.ui = UI(self.mockUIPlug)
     self.mainloop_object = MainLoop()
     self.mainloop_thread = None
     self.function_thread = None
     self.display_thread = None
     self.time_display_call = 0
Esempio n. 5
0
 def _display(self, contentType):
     # print depending on the content type
     while True:
         try:
             if isinstance(contentType, InputText):
                 contentType.run_callback(result=rlinput(
                     contentType.content, contentType.default_input))
             elif isinstance(contentType, LicenseAgreement):
                 print(contentType.content)
                 contentType.choose(answer=input(contentType.input))
             elif isinstance(contentType, TextWithChoices):
                 contentType.choose(answer=input(contentType.prompt))
             elif isinstance(contentType, DisplayMessage):
                 print(contentType.text)
             elif isinstance(contentType, UnknownProgress):
                 if not contentType.bar:
                     contentType.bar = ProgressBar(widgets=[BouncingBar()])
                 with suppress(StopIteration, AttributeError):
                     # pulse and add a timeout callback
                     contentType.bar(contentType._iterator()).next()
                     UI.delayed_display(contentType)
                 # don't recall the callback
                 return False
             else:
                 logger.error(
                     "Unexcepted content type to display to CLI UI: {}".
                     format(contentType))
                 MainLoop().quit(status_code=1)
             break
         except InputError as e:
             logger.error(str(e))
             continue
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     self.mockUIPlug = Mock()
     self.mockUIPlug._display.side_effect = self.display_UIPlug
     self.contentType = Mock()
     self.ui = UI(self.mockUIPlug)
     self.mainloop_object = MainLoop()
     self.mainloop_thread = None
     self.function_thread = None
     self.display_thread = None
     self.time_display_call = 0
Esempio n. 7
0
def main():
    """Main entry point of the program"""

    parser = argparse.ArgumentParser(description=_("Deploy and setup developers environment easily on ubuntu"),
                                     epilog=_("Note that you can also configure different debug logs behaviors using "
                                              "LOG_CFG pointing to a log yaml profile."),
                                     add_help=False)
    parser.add_argument('--help', action=_HelpAction, help=_('Show this help'))  # add custom help
    parser.add_argument("-v", "--verbose", action="count", default=0, help=_("Increase output verbosity (2 levels)"))

    parser.add_argument('-r', '--remove', action="store_true", help=_("Remove specified framework if installed"))

    # set logging ignoring unknown options
    set_logging_from_args(sys.argv, parser)

    mainloop = MainLoop()

    # load frameworks and initialize parser
    load_frameworks()
    cli.main(parser)

    mainloop.run()
Esempio n. 8
0
    def setup(self):
        """Method call to setup the Framework"""
        if not self.is_installable:
            logger.error(_("You can't install that framework on this machine"))
            UI.return_main_screen(status_code=1)

        if self.need_root_access and os.geteuid() != 0:
            logger.debug("Requesting root access")
            cmd = ["sudo", "-E", "env", "PATH={}".format(os.getenv("PATH"))]
            cmd.extend(sys.argv)
            MainLoop().quit(subprocess.call(cmd))

        # be a normal, kind user as we don't want normal files to be written as root
        switch_to_current_user()
Esempio n. 9
0
    def setup(self):
        """Method call to setup the Framework"""
        if not self.is_installable:
            logger.error(_("You can't install that framework on this machine"))
            UI.return_main_screen(status_code=2)

        if self.need_root_access and os.geteuid() != 0:
            logger.debug("Requesting root access")
            cmd = ["sudo", "-E", "env"]
            for var in ["PATH", "LD_LIBRARY_PATH", "PYTHONUSERBASE", "PYTHONHOME"]:
                if os.getenv(var):
                    cmd.append("{}={}".format(var, os.getenv(var)))
            if os.getenv("SNAP"):
                logger.debug("Found snap environment. Running correct python version")
                cmd.extend(["{}/usr/bin/python3".format(os.getenv("SNAP"))])
            cmd.extend(sys.argv)
            MainLoop().quit(subprocess.call(cmd))

        # be a normal, kind user as we don't want normal files to be written as root
        switch_to_current_user()
Esempio n. 10
0
class TestUI(LoggedTestCase):
    """This will test the UI generic module"""
    def setUp(self):
        super().setUp()
        self.mockUIPlug = Mock()
        self.mockUIPlug._display.side_effect = self.display_UIPlug
        self.contentType = Mock()
        self.ui = UI(self.mockUIPlug)
        self.mainloop_object = MainLoop()
        self.mainloop_thread = None
        self.function_thread = None
        self.display_thread = None
        self.time_display_call = 0

    def tearDown(self):
        Singleton._instances = {}
        super().tearDown()

    # function that will complete once the mainloop is started
    def wait_for_mainloop_function(self):
        timeout_time = time() + 5
        while not self.mainloop_object.mainloop.is_running():
            if time() > timeout_time:
                raise (BaseException("Mainloop not started in 5 seconds"))

    def wait_for_mainloop_shutdown(self):
        timeout_time = time() + 5
        while self.mainloop_object.mainloop.is_running():
            if time() > timeout_time:
                raise (BaseException("Mainloop not stopped in 5 seconds"))

    def get_mainloop_thread(self):
        self.mainloop_thread = threading.current_thread().ident

    def start_glib_mainloop(self):
        # quit after 5 seconds if nothing made the mainloop to end
        GLib.timeout_add_seconds(5, self.mainloop_object.mainloop.quit)
        GLib.idle_add(self.get_mainloop_thread)
        self.mainloop_object.run()

    def display_UIPlug(self, contentType):
        """handler to mock _display and save the current thread"""
        self.time_display_call = time()
        self.assertEqual(self.contentType, contentType)
        self.display_thread = threading.current_thread().ident
        self.mainloop_object.quit(raise_exception=False)

    def test_singleton(self):
        """Ensure we are delivering a singleton for UI"""
        other = UI(self.mockUIPlug)
        self.assertEqual(self.ui, other)

    def test_return_to_mainscreen(self):
        """We call the return to main screen on the UIPlug"""
        UI.return_main_screen()
        self.assertTrue(self.mockUIPlug._return_main_screen.called)

    @patch("umake.tools.sys")
    def test_call_display(self, mocksys):
        """We call the display method from the UIPlug"""
        UI.display(self.contentType)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)

    @patch("umake.tools.sys")
    def test_call_display_other_thread(self, mocksys):
        """We call the display method on UIPlug in the main thread from another thread"""
        def run_display(future):
            self.function_thread = threading.current_thread().ident
            UI.display(self.contentType)

        executor = futures.ThreadPoolExecutor(max_workers=1)
        future = executor.submit(self.wait_for_mainloop_function)
        future.add_done_callback(run_display)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.function_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertNotEqual(self.mainloop_thread, self.function_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)

    @patch("umake.tools.sys")
    def test_call_delayed_display(self, mocksys):
        """We call the display method from the UIPlug in delayed_display with 50ms waiting"""
        UI.delayed_display(self.contentType)
        now = time()
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)
        self.assertTrue(self.time_display_call - now > 0.05)

    @patch("umake.tools.sys")
    def test_call_delayed_display_from_other_thread(self, mocksys):
        """We call the display method from the UIPlug in delayed_display with 50ms waiting, even on other thread"""
        now = 0

        def run_display(future):
            nonlocal now
            self.function_thread = threading.current_thread().ident
            now = time()
            UI.delayed_display(self.contentType)

        executor = futures.ThreadPoolExecutor(max_workers=1)
        future = executor.submit(self.wait_for_mainloop_function)
        future.add_done_callback(run_display)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.function_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertNotEqual(self.mainloop_thread, self.function_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)
        self.assertTrue(self.time_display_call - now > 0.05)
Esempio n. 11
0
 def _return_main_screen(self, status_code=0):
     # quit the shell
     MainLoop().quit(status_code=status_code)
Esempio n. 12
0
class TestUI(LoggedTestCase):
    """This will test the UI generic module"""

    def setUp(self):
        super().setUp()
        self.mockUIPlug = Mock()
        self.mockUIPlug._display.side_effect = self.display_UIPlug
        self.contentType = Mock()
        self.ui = UI(self.mockUIPlug)
        self.mainloop_object = MainLoop()
        self.mainloop_thread = None
        self.function_thread = None
        self.display_thread = None
        self.time_display_call = 0

    def tearDown(self):
        Singleton._instances = {}
        super().tearDown()

    # function that will complete once the mainloop is started
    def wait_for_mainloop_function(self):
        timeout_time = time() + 5
        while not self.mainloop_object.mainloop.is_running():
            if time() > timeout_time:
                raise(BaseException("Mainloop not started in 5 seconds"))

    def wait_for_mainloop_shutdown(self):
        timeout_time = time() + 5
        while self.mainloop_object.mainloop.is_running():
            if time() > timeout_time:
                raise(BaseException("Mainloop not stopped in 5 seconds"))

    def get_mainloop_thread(self):
        self.mainloop_thread = threading.current_thread().ident

    def start_glib_mainloop(self):
        # quit after 5 seconds if nothing made the mainloop to end
        GLib.timeout_add_seconds(5, self.mainloop_object.mainloop.quit)
        GLib.idle_add(self.get_mainloop_thread)
        self.mainloop_object.run()

    def display_UIPlug(self, contentType):
        """handler to mock _display and save the current thread"""
        self.time_display_call = time()
        self.assertEqual(self.contentType, contentType)
        self.display_thread = threading.current_thread().ident
        self.mainloop_object.quit(raise_exception=False)

    def test_singleton(self):
        """Ensure we are delivering a singleton for UI"""
        other = UI(self.mockUIPlug)
        self.assertEqual(self.ui, other)

    def test_return_to_mainscreen(self):
        """We call the return to main screen on the UIPlug"""
        UI.return_main_screen()
        self.assertTrue(self.mockUIPlug._return_main_screen.called)

    @patch("umake.tools.sys")
    def test_call_display(self, mocksys):
        """We call the display method from the UIPlug"""
        UI.display(self.contentType)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)

    @patch("umake.tools.sys")
    def test_call_display_other_thread(self, mocksys):
        """We call the display method on UIPlug in the main thread from another thread"""
        def run_display(future):
            self.function_thread = threading.current_thread().ident
            UI.display(self.contentType)

        executor = futures.ThreadPoolExecutor(max_workers=1)
        future = executor.submit(self.wait_for_mainloop_function)
        future.add_done_callback(run_display)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.function_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertNotEqual(self.mainloop_thread, self.function_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)

    @patch("umake.tools.sys")
    def test_call_delayed_display(self, mocksys):
        """We call the display method from the UIPlug in delayed_display with 50ms waiting"""
        UI.delayed_display(self.contentType)
        now = time()
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)
        self.assertTrue(self.time_display_call - now > 0.05)

    @patch("umake.tools.sys")
    def test_call_delayed_display_from_other_thread(self, mocksys):
        """We call the display method from the UIPlug in delayed_display with 50ms waiting, even on other thread"""
        now = 0

        def run_display(future):
            nonlocal now
            self.function_thread = threading.current_thread().ident
            now = time()
            UI.delayed_display(self.contentType)

        executor = futures.ThreadPoolExecutor(max_workers=1)
        future = executor.submit(self.wait_for_mainloop_function)
        future.add_done_callback(run_display)
        self.start_glib_mainloop()
        self.wait_for_mainloop_shutdown()

        self.assertTrue(self.mockUIPlug._display.called)
        self.assertIsNotNone(self.mainloop_thread)
        self.assertIsNotNone(self.function_thread)
        self.assertIsNotNone(self.display_thread)
        self.assertNotEqual(self.mainloop_thread, self.function_thread)
        self.assertEqual(self.mainloop_thread, self.display_thread)
        self.assertTrue(self.time_display_call - now > 0.05)