Exemplo n.º 1
0
    def test_enable_apt_run(self):
        apt_run = AptRun()
        apt_run.set_folder(AptRunTests.TEST_FOLDER)

        apt_run.enable()
        result = apt_run.is_enable()

        self.assertTrue(result)
Exemplo n.º 2
0
    def test_dont_enable_apt_run_if_already_enabled(self):
        apt_run = AptRun()
        apt_run.set_folder(AptRunTests.TEST_FOLDER)

        apt_run.enable()
        result = apt_run.enable()

        self.assertFalse(result)
Exemplo n.º 3
0
    def test_post_invoke(self, mock_user_pkgs):
        mock_user_pkgs.return_value = ['vim', 'gedit']

        apt_run = AptRun()
        apt_run.set_folder(AptRunTests.TEST_FOLDER)
        apt_run.enable()

        with open(apt_run.installed_pkgs_file, 'w') as text:
            text.write('gedit')

        installed_pkgs = apt_run.post_invoke()

        self.assertEqual(['vim'], installed_pkgs)
Exemplo n.º 4
0
    def test_pre_install_pkgs(self):
        apt_run = AptRun()
        apt_run.set_folder(AptRunTests.TEST_FOLDER)
        apt_run.enable()
        apt_run.pre_install_pkgs()

        user = LocalSystem()
        assert_pkgs = user.pkg_profile

        pkgs = []
        with open(apt_run.installed_pkgs_file, 'r') as text:
            pkgs = [line.strip() for line in text]

        self.assertListEqual(assert_pkgs, pkgs)
Exemplo n.º 5
0
def run(args):
    if args['update']:
        init_result = run_initialize()

        if init_result != SUCCESS:
            return init_result

        train_result = run_train()

        if train_result != SUCCESS:
            return train_result

        return SUCCESS
    elif args['init']:
        return run_initialize()
    elif args['train']:
        return run_train()
    elif args['contribute']:
        collect_user_data.main()
    elif args['show_classifications']:
        show_classifications.main()
    elif args['enable_apt']:
        try:
            apt_run = AptRun()
            if apt_run.enable():
                print 'AppRecommender now makes recommendations when you ' \
                      ' install new packages with apt'
            else:
                print 'This is already enabled'

            return SUCCESS
        except OSError:
            return PERMISSION_DENIED
    elif args['disable_apt']:
        try:
            apt_run = AptRun()
            if apt_run.disable():
                print 'AppRecommender now dont makes recommendations when' \
                      'you install new packages with apt'
            else:
                print 'This is already disabled'

            return SUCCESS
        except OSError:
            return PERMISSION_DENIED
    else:
        config = Config()
        parse_options(args, config)
        reference_pkgs = args['packages']
        return run_apprecommender(reference_pkgs)