def package_(self, instance): """ Give a special url redirecting to Version model which shows all versions under this package. :type instance: Package """ if instance.c_package is None: return "-" return mark_safe('<a href="' + Version.get_change_list_url() + '?c_package__exact=' + instance.c_package + '" target="_blank">' + instance.c_package + '</a>')
def handle_uploaded_package(path): """ :param path: Package Uploaded Path :type path: str :return: Result Dict :rtype: dict """ result_dict = {} try: uploaded_package = DebianPackage(path) control = uploaded_package.control version_dir = os.path.join(settings.MEDIA_ROOT, 'versions') if not os.path.isdir(version_dir): mkdir_p(version_dir) target_dir = os.path.join(version_dir, str(uuid.uuid1())) if not os.path.isdir(target_dir): mkdir_p(target_dir) target_path = os.path.join( target_dir, control.get('Package', 'undefined') + '_' + control.get('Version', 'undefined') + '_' + control.get('Architecture', 'undefined') + '.deb') with transaction.atomic(): p_section = Section.objects.filter( name=control.get('Section', None)).last() if p_section: pass else: # create a new section p_section_name = control.get('Section', None) if p_section_name: p_section = Section(name=p_section_name) p_section.save() # search version p_version = Version.objects.filter( c_package=control.get('Package', None), c_version=control.get('Version', None)).last() if p_version: # version conflict result_dict.update({ "success": False, "exception": _("Version Conflict: %s") % p_version.c_version }) else: # os.rename(path, target_path) shutil.move(path, target_path) p_version = Version() p_version.c_package = control.get('Package', None) p_version.c_version = control.get('Version', None) p_version.storage = os.path.relpath(target_path, settings.MEDIA_ROOT) p_version.maintainer_name = DebianPackage.value_for_field( control.get('Maintainer', None)) p_version.maintainer_email = DebianPackage.detail_for_field( control.get('Maintainer', None)) p_version.c_description = control.get('Description', "") p_version.c_section = p_section p_version.c_tag = control.get('Tag', None) p_version.c_architecture = control.get('Architecture', None) p_version.c_name = control.get('Name', None) p_version.author_name = DebianPackage.value_for_field( control.get('Author', None)) p_version.author_email = DebianPackage.detail_for_field( control.get('Author', None)) p_version.sponsor_name = DebianPackage.value_for_field( control.get('Sponsor', None)) p_version.sponsor_site = DebianPackage.detail_for_field( control.get('Sponsor', None)) p_version.c_depiction = control.get('Depiction', None) p_version.c_homepage = control.get('Homepage', None) p_version.c_priority = control.get('Priority', None) p_version.c_installed_size = control.get( 'Installed-Size', None) p_version.c_essential = control.get('Essential', None) p_version.c_depends = control.get('Depends', None) p_version.c_pre_depends = control.get('Pre-Depends', None) p_version.c_recommends = control.get('Recommends', None) p_version.c_suggests = control.get('Suggests', None) p_version.c_breaks = control.get('Breaks', None) p_version.c_conflicts = control.get('Conflicts', None) p_version.c_replaces = control.get('Replaces', None) p_version.c_provides = control.get('Provides', None) p_version.c_build_essential = control.get( 'Build-Essential', None) p_version.c_origin = control.get('Origin', None) p_version.c_bugs = control.get('Bugs', None) p_version.c_multi_arch = control.get('Multi-Arch', None) p_version.c_source = control.get('Source', None) p_version.c_subarchitecture = control.get( 'Subarchitecture', None) p_version.c_kernel_version = control.get( 'Kernel-Version', None) p_version.c_installer_menu_item = control.get( 'Installer-Menu-Item', None) p_version.c_built_using = control.get('Built-Using', None) p_version.c_built_for_profiles = control.get( 'Built-For-Profiles', None) p_version.c_icon = control.get('Icon', None) p_version.update_hash() p_version.save() # move resource result_dict.update({"success": True, "version": p_version.id}) except Exception as e: # error handler result_dict.update({ "success": False, # TODO: fix unicode bug "exception": str(e) }) return result_dict