示例#1
0
    def change_status(self):
        status = self.cleaned_data.get('status')
        module = ModDjango(self.cleaned_data.get('name'))
        if status != 'none':
            
            if status == 'uninstall':
                module.uninstall()
            
            elif status == 'on':
                try:
                    module.turn_on()
                except Exception as e:
                    if str(e) == 'not satisfied depending':
                        self.add_error(None, 'Не все зависимости удовлетворены. Включите необходимые модули.')
            
            elif status == 'off':
                try:
                    module.turn_off()
                except Exception as e:
                    if str(e) == 'depending not disabled':
                        self.add_error(None, 'У этого модуля есть включеные зависимости. Отключите их.')

            elif status == 'install':
                try:
                    module.install()
                except Exception as e:
                    if str(e) == 'full path not found':
                        self.add_error(None, 'Не найден файл модуля. Возможно в moddjango/settings не настроена папка download или файл модуля в не правильном формате')

        else:
            return False
示例#2
0
文件: tests.py 项目: pycott/moddjango
 def test_install_uninstall(self):
     installed_module_dir = os.path.join(BASE_DIR, 'fake1')
     test_utils.del_fake_modules()
     with self.assertRaises(Exception):
         ModDjango('fake1').install()
     test_utils.add_fake_modules()
     ModDjango('fake1').install()
     self.assertTrue(os.path.exists(installed_module_dir))
     status = ModDjango('fake1').module.status
     self.assertEqual(status, 'installed')
     answer = ModDjango('fake1').uninstall()
     self.assertTrue(answer)
     self.assertFalse(os.path.exists(installed_module_dir))
     status = ModDjango('fake1').module.status
     self.assertEqual(status, 'downloaded')
示例#3
0
 def clean_name(self):
     name = self.cleaned_data.get('name')
     try:
         module = ModDjango(name)
     except ObjectDoesNotExist:
         raise forms.ValidationError('данный модуль не найден в базе данных')
     return name
示例#4
0
文件: tests.py 项目: pycott/moddjango
 def test_add_downloaded_to_db(self):
     ModDjango('fake1').module.delete()
     ModDjango('fake2').module.delete()
     with self.assertRaises(ObjectDoesNotExist):
         ModDjango('fake1')
         ModDjango('fake2')
     ModDjango().add_downloaded_to_db()
     self.assertEqual(ModDjango('fake1').module.status, 'downloaded')
     self.assertEqual(ModDjango('fake2').module.status, 'downloaded')
示例#5
0
文件: views.py 项目: pycott/moddjango
def management(request):
    ModDjango().add_downloaded_to_db()
    form = ChangeStatusForm(request.POST or None)
    if request.POST:
        if form.is_valid():
            form.change_status()
    modules = Module.objects.exclude(status='none')
    return render(request, 'moddjango/management.html', {
        'modules': modules,
        'form': form
    })
示例#6
0
def del_fake_modules():
    print('destroying fake modules')
    fake1 = ModDjango('fake1')
    fake2 = ModDjango('fake2')
    fake1.module.status = 'on'
    fake2.module.status = 'on'
    fake1.module.save()
    fake2.module.save()
    fake2.turn_off()
    fake1.turn_off()
    for module_name in ['fake1', 'fake2']:
        module_arc = module_name + '.tar.gz'
        path_module_arc = os.path.join(settings.DOWNLOAD_DIR, module_arc)
        path_installed_module = os.path.join(settings.BASE_DIR, module_name)
        if os.path.exists(path_module_arc):
            os.remove(path_module_arc)
        if os.path.exists(path_installed_module):
            shutil.rmtree(path_installed_module)
示例#7
0
文件: tests.py 项目: pycott/moddjango
 def test_get_module(self):
     with self.assertRaises(ObjectDoesNotExist):
         ModDjango('asdfsdf')
     self.assertEqual(ModDjango('fake1').name, 'fake1')
示例#8
0
文件: tests.py 项目: pycott/moddjango
def setUpModule():
    test_utils.add_fake_modules()
    ModDjango().add_downloaded_to_db()
示例#9
0
文件: tests.py 项目: pycott/moddjango
 def test_turn_on_off_dependence(self):
     ModDjango('fake2').install()
     with self.assertRaises(Exception):
         ModDjango('fake2').turn_on()
     status = ModDjango('fake2').module.status
     self.assertEqual(status, 'installed')
     ModDjango('fake1').turn_on()
     status = ModDjango('fake1').module.status
     self.assertNotEqual(status, 'on')
     ModDjango('fake1').install()
     ModDjango('fake1').turn_on()
     status = ModDjango('fake1').module.status
     self.assertEqual(status, 'on')
     ModDjango('fake2').turn_on()
     status = ModDjango('fake2').module.status
     self.assertEqual(status, 'on')
     with self.assertRaises(Exception):
         ModDjango('fake1').turn_off()
     ModDjango('fake2').turn_off()
     status = ModDjango('fake2').module.status
     self.assertEqual(status, 'installed')