Exemplo n.º 1
0
 def test_update_library(self):
     service = Service([
         Stanza('package://boot', {}),
     ])
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertEqual(len(installed_packages), 1)
     self.assertEqual(installed_packages[0], 'boot')
     self.assertEqual(r_packages.get_package_state('boot'), r_packages.metadata_package_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertEqual(len(installed_packages), 1)
     self.assertEqual(installed_packages[0], 'boot')
     self.assertEqual(r_packages.get_package_state('boot'), r_packages.metadata_package_installed)
     r_packages.add(service, 'forecast')
     self.assertEqual(r_packages.get_package_state('forecast'), r_packages.metadata_package_not_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertTrue('boot' in installed_packages)
     self.assertTrue('forecast' in installed_packages)
     self.assertEqual(r_packages.get_package_state('boot'), r_packages.metadata_package_installed)
     self.assertEqual(r_packages.get_package_state('forecast'), r_packages.metadata_package_installed)
     r_packages.remove(service, 'boot')
     self.assertEqual(r_packages.get_package_state('boot'), r_packages.metadata_package_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertFalse('boot' in installed_packages)
     self.assertTrue('timeDate' in installed_packages)
     self.assertTrue('forecast' in installed_packages)
     self.assertEqual(r_packages.get_package_state('boot'), r_packages.metadata_package_not_installed)
     self.assertEqual(r_packages.get_package_state('timeDate'), r_packages.metadata_package_installed)
     self.assertEqual(r_packages.get_package_state('forecast'), r_packages.metadata_package_installed)
Exemplo n.º 2
0
 def test_update_library(self):
     service = Service([
         Stanza('package://boot', {}),
     ])
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertEqual(len(installed_packages), 1)
     self.assertEqual(installed_packages[0], 'boot')
     self.assertEqual(r_packages.get_package_state('boot'),
                      r_packages.metadata_package_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertEqual(len(installed_packages), 1)
     self.assertEqual(installed_packages[0], 'boot')
     self.assertEqual(r_packages.get_package_state('boot'),
                      r_packages.metadata_package_installed)
     r_packages.add(service, 'forecast')
     self.assertEqual(r_packages.get_package_state('forecast'),
                      r_packages.metadata_package_not_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertTrue('boot' in installed_packages)
     self.assertTrue('forecast' in installed_packages)
     self.assertEqual(r_packages.get_package_state('boot'),
                      r_packages.metadata_package_installed)
     self.assertEqual(r_packages.get_package_state('forecast'),
                      r_packages.metadata_package_installed)
     r_packages.remove(service, 'boot')
     self.assertEqual(r_packages.get_package_state('boot'),
                      r_packages.metadata_package_installed)
     r_packages.update_library(service)
     installed_packages = os.listdir(r_packages.get_library_path())
     self.assertFalse('boot' in installed_packages)
     self.assertTrue('timeDate' in installed_packages)
     self.assertTrue('forecast' in installed_packages)
     self.assertEqual(r_packages.get_package_state('boot'),
                      r_packages.metadata_package_not_installed)
     self.assertEqual(r_packages.get_package_state('timeDate'),
                      r_packages.metadata_package_installed)
     self.assertEqual(r_packages.get_package_state('forecast'),
                      r_packages.metadata_package_installed)
Exemplo n.º 3
0
def packages(request):
    add_package_action = 'add_package'
    add_package_field_name = 'add_package_name'
    delete_package_action_prefix = 'delete_package_'
    upload_package_action = 'upload_package'
    upload_package_field_name = 'package_file'

    if request.method == 'POST':
        try:
            # raise errors.Error(packagelib.get_packages_path())
            # add package stanza
            if add_package_action in request.POST:
                package_name = request.POST[add_package_field_name]
                packagelib.get_package_description_lines(package_name)
                packagelib.add(request.service, package_name)
            # upload package and add package stanza
            elif upload_package_action in request.POST:
                if upload_package_field_name in request.FILES:
                    archive_file = request.FILES[upload_package_field_name]
                    package_name = packagelib.get_package_name_from_archive_file(archive_file.name, archive_file)
                    target_archive_path = os.path.join(packagelib.get_packages_path(),
                                                       packagelib.get_local_package_filename(package_name))
                    archive_file.seek(0)
                    data = archive_file.read()
                    with open(target_archive_path, 'w') as f:
                        f.write(data)
                    packagelib.add(request.service, package_name)
                else:
                    raise r_errors.Error('File missing')
            # delete package stanza
            else:
                for key in request.POST:
                    if key.startswith(delete_package_action_prefix):
                        package_name = key[len(delete_package_action_prefix):]
                        packagelib.remove(request.service, package_name)
        except r_errors.Error as e:
            return HttpResponseRedirect('./?add_error=%s' % str(e))
        except Exception as e:
            return HttpResponseRedirect('./?add_fatal_error=%s' % str(e))
        return HttpResponseRedirect('./')

    # scan for package stanzas
    r_packages = []
    for stanza, package_name in packagelib.iter_stanzas(request.service):
        r_packages.append({
            'name': package_name,
            'is_removable': stanza.access['removable'] == '1',
            'owner': stanza.access['owner'],
            'state': packagelib.get_package_state(package_name),
        })

    return {
        'packages': r_packages,
        'app_label': request.service.apps[app_id].label,
        'request': request,
        'can_add': packagelib.can_add(request.service),
        'add_package_field_name': add_package_field_name,
        'add_package_action': add_package_action,
        'delete_package_action_prefix': delete_package_action_prefix,
        'add_error': request.GET.get('add_error', ''),
        'add_fatal_error': request.GET.get('add_fatal_error', ''),
        'not_installed': packagelib.metadata_package_not_installed,
        'upload_package_action': upload_package_action,
        "upload_package_field_name": upload_package_field_name
    }
Exemplo n.º 4
0
def packages(request):
    add_package_action = 'add_package'
    add_package_field_name = 'add_package_name'
    delete_package_action_prefix = 'delete_package_'
    upload_package_action = 'upload_package'
    upload_package_field_name = 'package_file'

    if request.method == 'POST':
        try:
            # raise errors.Error(packagelib.get_packages_path())
            # add package stanza
            if add_package_action in request.POST:
                package_name = request.POST[add_package_field_name]
                packagelib.get_package_description_lines(package_name)
                packagelib.add(request.service, package_name)
            # upload package and add package stanza
            elif upload_package_action in request.POST:
                if upload_package_field_name in request.FILES:
                    archive_file = request.FILES[upload_package_field_name]
                    package_name = packagelib.get_package_name_from_archive_file(
                        archive_file.name, archive_file)
                    target_archive_path = os.path.join(
                        packagelib.get_packages_path(),
                        packagelib.get_local_package_filename(package_name))
                    archive_file.seek(0)
                    data = archive_file.read()
                    with open(target_archive_path, 'w') as f:
                        f.write(data)
                    packagelib.add(request.service, package_name)
                else:
                    raise r_errors.Error('File missing')
            # delete package stanza
            else:
                for key in request.POST:
                    if key.startswith(delete_package_action_prefix):
                        package_name = key[len(delete_package_action_prefix):]
                        packagelib.remove(request.service, package_name)
        except r_errors.Error as e:
            return HttpResponseRedirect('./?add_error=%s' % str(e))
        except Exception as e:
            return HttpResponseRedirect('./?add_fatal_error=%s' % str(e))
        return HttpResponseRedirect('./')

    # scan for package stanzas
    r_packages = []
    for stanza, package_name in packagelib.iter_stanzas(request.service):
        r_packages.append({
            'name': package_name,
            'is_removable': stanza.access['removable'] == '1',
            'owner': stanza.access['owner'],
            'state': packagelib.get_package_state(package_name),
        })

    return {
        'packages': r_packages,
        'app_label': request.service.apps[app_id].label,
        'request': request,
        'can_add': packagelib.can_add(request.service),
        'add_package_field_name': add_package_field_name,
        'add_package_action': add_package_action,
        'delete_package_action_prefix': delete_package_action_prefix,
        'add_error': request.GET.get('add_error', ''),
        'add_fatal_error': request.GET.get('add_fatal_error', ''),
        'not_installed': packagelib.metadata_package_not_installed,
        'upload_package_action': upload_package_action,
        "upload_package_field_name": upload_package_field_name
    }