• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Repository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中moneta.repository.models.Repository的典型用法代码示例。如果您正苦于以下问题:Python Repository类的具体用法?Python Repository怎么用?Python Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Repository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_repository

 def create_repository(self, repo_cls, name='test_repo', author=None, states='qualif prod'):
     assert issubclass(repo_cls, RepositoryModel)
     if author is None:
         author = User.objects.get_or_create(username='test_user')[0]
     repo = Repository(author=author, name=name, on_index=True, archive_type=repo_cls.archive_type, is_private=False)
     repo.save()
     for state in states.split():
         ArchiveState(repository=repo, name=state, author=author).save()
     return repo
开发者ID:d9pouces,项目名称:Moneta,代码行数:9,代码来源:__init__.py


示例2: xr_search

 def xr_search(request, rpc_args, self, rid, repo_slug, state_slug=None):
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.model)
     state = get_object_or_404(ArchiveState, repository=repo, name=state_slug) if state_slug else None
     global_and = len(rpc_args) == 0 or rpc_args[1] != 'or'
     if len(rpc_args) == 0 or not isinstance(rpc_args[0], dict):
         raise PermissionDenied
     filters = None
     for query_name, attr_name in (('name', 'archive'), ('version', 'version'), ('home_page', 'official_link'),
                                   ('description', 'long_description'),):
         if query_name in rpc_args[0]:
             value = rpc_args[0][query_name]
             if isinstance(value, list):
                 if value:
                     value = value[0]
                 else:
                     value = ''
             value = value.replace('-', '').replace('_', '')
             sub_query = Q(**{attr_name + '__icontains': value})
             if filters is None:
                 filters = sub_query
             elif global_and:
                 filters = filters and sub_query
             else:
                 filters = filters or sub_query
     query = Element.objects.filter(repository=repo)
     if state:
         query = query.filter(states=state)
     if filters is not None:
         query = query.filter(filters)
     res = [{'name': x.archive, 'version': x.version, 'summary': x.long_description,
             '_pypi_ordering': 1.0} for x in query]
     return res
开发者ID:d9pouces,项目名称:Moneta,代码行数:32,代码来源:pypi.py


示例3: modify_repository

def modify_repository(request: HttpRequest, rid):
    repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
    author = None if request.user.is_anonymous() else request.user

    if request.method == 'POST':
        form = RepositoryUpdateForm(request.POST)
        if form.is_valid():
            new_state_names = set(form.cleaned_data['states'].split())
            old_state_names = {x.name for x in repo.archivestate_set.all()}
            for name in new_state_names - old_state_names:  # new states
                ArchiveState(name=name, repository=repo, author=author).save()
            repo.on_index = form.cleaned_data['on_index']
            repo.is_private = form.cleaned_data['is_private']
            repo.save()
            repo.admin_group.clear()
            for group in form.cleaned_data['admin_group']:
                repo.admin_group.add(group)
            # repo.reader_group.clear()
            # for group in form.cleaned_data['reader_group']:
            #     repo.reader_group.add(group)
            removed_states = ArchiveState.objects.filter(name__in=old_state_names - new_state_names, repository=repo)
            # noinspection PyUnresolvedReferences
            Element.states.through.objects.filter(archivestate__in=removed_states).delete()
            removed_states.delete()
            messages.info(request, _('The repository %(repo)s has been modified.') % {'repo': repo.name})
            return HttpResponseRedirect(reverse('moneta:modify_repository', kwargs={'rid': rid, }))
    else:
        form = RepositoryUpdateForm(initial={'on_index': repo.on_index, 'is_private': repo.is_private,
                                             'reader_group': list(repo.reader_group.all()),
                                             'states': ' '.join([x.name for x in repo.archivestate_set.all()]),
                                             'admin_group': list(repo.admin_group.all())})
    template_values = {'form': form, 'repo': repo, 'upload_allowed': repo.upload_allowed(request)}
    return render_to_response('moneta/modify_repo.html', template_values, RequestContext(request))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:33,代码来源:views.py


示例4: index

    def index(self, request, rid, repo_slug=None, state_slug=''):
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        base_query = Element.objects.filter(repository=repo)
        if state_slug:
            state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
            base_query = base_query.filter(states=state)
        base_query = base_query.order_by('archive', 'version')
        element_infos = []
        for element in base_query:
            if not element.extra_data:
                continue
            provider = json.loads(element.extra_data)['provider']
            element_infos.append(
                (element.name,
                 reverse('vagrant:get_box',
                         kwargs={'rid': rid, 'repo_slug': repo.slug, 'eid': element.id, 'provider': provider,
                                 'archive': element.archive, 'version': element.version}),
                 element.sha1)
            )
        states = [state for state in ArchiveState.objects.filter(repository=repo).order_by('name')]
        tab_infos = [(reverse('vagrant:index', kwargs={'rid': repo.id, 'state_slug': ''}),
                      ArchiveState(name=_('All states'), slug='all-states'), states, ''), ]
        tab_infos += [(reverse('vagrant:index',
                               kwargs={'rid': repo.id, 'state_slug': state.slug}),
                       state, [state], state.slug)
                      for state in states]
        # list of (relative URL, name, list of states, state_slug)

        template_values = {'repo': repo, 'states': states, 'upload_allowed': repo.upload_allowed(request),
                           'state_slug': state_slug, 'elements': element_infos,
                           'index_url': reverse(moneta_url(repo, 'index'), kwargs={'rid': repo.id, }),
                           'tab_infos': tab_infos, 'admin_allowed': repo.admin_allowed(request), }
        return render_to_response(self.index_html, template_values, RequestContext(request))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:33,代码来源:vagrant.py


示例5: get_providers_by_version

    def get_providers_by_version(self, request, rid, state_slug, archive):
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        base_query = Element.objects.filter(repository=repo, archive=archive)
        if state_slug:
            state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
            base_query = base_query.filter(states=state)
        versions = {}
        for element in base_query:
            metadata = json.loads(element.extra_data)
            versions.setdefault(element.version, []).append({
                'name': metadata['provider'],
                'url': '%s%s' % (settings.SERVER_NAME, element.get_direct_link()),
                'checksum_type': 'sha1',

                'checksum': element.sha1})
        result = {'name': archive, 'description': _('This box contains %(name)s') % {'name': archive},
                  'versions': [{'version': k, 'status': 'active', 'providers': v} for (k, v) in versions.items()]}
        return result
# Vagrant.configure(2) do |config|
#
#   config.vm.box = "{$relativePathInfo|escape}"
#   config.vm.box_url = '<a href="{$CATALOG_URI|escape}{$pathInfo|escape}">{$CATALOG_URI|escape}{$pathInfo|escape}</a>'
#
#   # Whatever other config stuff you want to do
# end
开发者ID:wagnerwar,项目名称:Moneta,代码行数:25,代码来源:vagrant.py


示例6: browse_repository

    def browse_repository(self, request: HttpRequest, rid, repo_slug, query_string='', state_slug=None) -> HttpResponse:
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        result = self.browse_repo_inner(rid, query_string, state_slug=state_slug)
        if isinstance(result, str):  # sha1/sha256/md5
            return HttpResponse(result)
        elif isinstance(result, Element):
            return get_file(request, eid=result.pk, element=result)
        assert isinstance(result, dict)

        new_query_string = ''
        bread_crumbs = [(_('Root'), self.get_browse_url(repo, new_query_string, state_slug=state_slug))]
        while len(result) == 1 and isinstance(result, dict):
            path_component, result = result.popitem()
            new_query_string += path_component + '/'
            bread_crumbs.append((path_component, self.get_browse_url(repo, new_query_string, state_slug=state_slug)))
        if isinstance(result, set):
            url_list = []
            for elt in result:
                new_gavf_elt_filename = new_query_string + elt.filename
                elt_url = self.get_browse_url(repo, new_gavf_elt_filename, state_slug=state_slug)
                url_list += [(new_gavf_elt_filename, elt_url, elt.id),
                             (new_gavf_elt_filename + '.sha1', elt_url + '.sha1', None),
                             (new_gavf_elt_filename + '.sha256', elt_url + '.sha256', None),
                             (new_gavf_elt_filename + '.md5', elt_url + '.md5', None),
                             ]
        else:
            assert isinstance(result, dict)
            url_list = [(new_query_string + key,
                         self.get_browse_url(repo, new_query_string + key, state_slug=state_slug), None)
                        for key in result]
        template_values = {'repo': repo, 'upload_allowed': repo.upload_allowed(request), 'repo_slug': repo_slug,
                           'admin': True, 'paths': url_list, 'request_path': new_query_string, 'state_slug': state_slug,
                           'bread_crumbs': bread_crumbs, }
        status_code = 200 if url_list else 404
        return TemplateResponse(request, 'repositories/maven3/browse.html', template_values, status=status_code)
开发者ID:d9pouces,项目名称:Moneta,代码行数:35,代码来源:maven3.py


示例7: add_element

def add_element(request: HttpRequest, rid):
    repo = get_object_or_404(Repository.upload_queryset(request), id=rid)

    class ElementForm(forms.Form):
        package = forms.FileField(label=_('Package'))
        states = forms.ModelMultipleChoiceField(repo.archivestate_set.all(), label=_('States'))

        def clean(self):
            data_ = super().clean()
            if 'package' in self.cleaned_data:
                if not repo.get_model().is_file_valid(self.cleaned_data['package']):
                    raise ValidationError(_('This repository is unable to handle this file.'))
            return data_

    if request.method == 'POST':
        form = ElementForm(request.POST, files=request.FILES)
        if form.is_valid():
            try:
                element = generic_add_element(request, repo, form.cleaned_data['package'],
                                              [x.name for x in form.cleaned_data['states']])
                messages.info(request, _('The package %(n)s has been successfully uploaded.') % {'n': element.filename})
            except InvalidRepositoryException as e:
                messages.error(request, _('Unable to add the package to this repository: %(msg)s.') % {'msg': str(e)})
            return HttpResponseRedirect(reverse('moneta:add_element', kwargs={'rid': rid}))
    else:
        form = ElementForm()
    template_values = {'form': form, 'repo': repo, 'upload_allowed': repo.upload_allowed(request)}
    return render_to_response('moneta/add_package.html', template_values, RequestContext(request))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:28,代码来源:views.py


示例8: plugin_index

 def plugin_index(self, request: HttpRequest, rid, repo_slug, state_slug=None):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         base_query = base_query.filter(states=state)
     return TemplateResponse(request, 'repositories/jetbrains/updatePlugins.xml', {'elements': base_query},
                             content_type='application/xml')
开发者ID:d9pouces,项目名称:Moneta,代码行数:10,代码来源:jetbrains.py


示例9: index

    def index(self, request, rid):
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        states = [state for state in ArchiveState.objects.filter(repository=repo).order_by('name')]
        tab_infos = [(states, ArchiveState(name=_('All states'), slug='all-states')), ]
        tab_infos += [([state], state) for state in states]

        template_values = {'repo': repo, 'states': states, 'upload_allowed': repo.upload_allowed(request),
                           'index_url': reverse(moneta_url(repo, 'index'), kwargs={'rid': repo.id, }),
                           'tab_infos': tab_infos, 'admin_allowed': repo.admin_allowed(request), }
        return TemplateResponse(request, self.index_html, template_values)
开发者ID:d9pouces,项目名称:Moneta,代码行数:10,代码来源:aptitude.py


示例10: specs

 def specs(self, request, rid, repo_slug, state_slug=None, filename='specs.4.8.gz'):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     if state_slug:
         filename = 'specs/%(slug)s/%(filename)s' % {'slug': state_slug, 'filename': filename, }
     else:
         filename = 'specs/%(filename)s' % {'filename': filename, }
     uid = self.storage_uid % repo.pk
     key = storage(settings.STORAGE_CACHE).uid_to_key(uid)
     return sendpath(settings.STORAGE_CACHE, key, filename, 'application/gzip')
开发者ID:wagnerwar,项目名称:Moneta,代码行数:11,代码来源:ruby.py


示例11: download

 def download(self, request, rid, repo_slug, state_slug=None, filename=None):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         base_query = base_query.filter(states=state)
     element = get_object_or_404(base_query, filename=filename)
     from moneta.views import get_file
     return get_file(request, element.pk)
开发者ID:wagnerwar,项目名称:Moneta,代码行数:11,代码来源:ruby.py


示例12: xr_package_releases

 def xr_package_releases(request, rpc_args, self, rid, repo_slug, state_slug=None):
     if len(rpc_args) == 0:
         raise PermissionDenied
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.model)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         query = Element.objects.filter(repository=repo, states=state, archive=rpc_args[0])
     else:
         query = Element.objects.filter(repository=repo, archive=rpc_args[0])
     versions = [LooseVersion(x.version) for x in query]
     versions.sort()
     return [str(x) for x in versions]
开发者ID:d9pouces,项目名称:Moneta,代码行数:12,代码来源:pypi.py


示例13: index

def index(request: HttpRequest):
    repositories = Repository.index_queryset(request).annotate(package_count=Count('element'))
    if not request.user.has_perm('repository.add_repository'):
        form = None
    elif request.method == 'POST':
        form = get_repository_form()(request.POST)
        if form.is_valid():
            author = None if request.user.is_anonymous() else request.user
            repo = Repository(author=author, name=form.cleaned_data['name'], on_index=form.cleaned_data['on_index'],
                              archive_type=form.cleaned_data['archive_type'],
                              is_private=form.cleaned_data['is_private'])
            repo.save()
            for group in form.cleaned_data['admin_group']:
                repo.admin_group.add(group)
            for state in set(form.cleaned_data['states'].split()):
                ArchiveState(repository=repo, name=state, author=author).save()
            messages.info(request, _('Your new repository has been created.'))
            return HttpResponseRedirect(reverse('moneta:index'))
    else:
        form = get_repository_form()()
    # compute repos with admin rights
    upload_ids = {x.id for x in Repository.upload_queryset(request)}
    admin_ids = {x.id for x in Repository.admin_queryset(request)}
    template_values = {'repositories': repositories, 'form': form, 'request': request,
                       'upload_ids': upload_ids, 'admin_ids': admin_ids, }
    return render_to_response('moneta/index.html', template_values, RequestContext(request))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:26,代码来源:views.py


示例14: gem_specs

 def gem_specs(self, request, rid, repo_slug, state_slug=None, filename=None):
     name, sep, version = filename.rpartition('-')
     if sep != '-':
         raise Http404
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         base_query = base_query.filter(states=state)
     element = get_object_or_404(base_query, name=name, version=version)
     return HttpResponse(self.yaml_data(element), content_type='text/yaml')
开发者ID:wagnerwar,项目名称:Moneta,代码行数:13,代码来源:ruby.py


示例15: repodata_file

 def repodata_file(self, request, rid, repo_slug, state_slug, arch, filename, compression):
     if filename not in ('comps.xml', 'primary.xml', 'other.xml', 'filelists.xml', 'repomd.xml', ):
         return HttpResponse(_('File not found'), status=404)
     if compression and filename == 'repomd.xml':
         return HttpResponse(_('File not found'), status=404)
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     filename = self.index_filename(state_slug, arch, filename + compression)
     mimetype = 'text/xml'
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     uid = self.storage_uid % repo.id
     key = storage(settings.STORAGE_CACHE).uid_to_key(uid)
     return sendpath(settings.STORAGE_CACHE, key, filename, mimetype)
开发者ID:wagnerwar,项目名称:Moneta,代码行数:13,代码来源:yum.py


示例16: get_file

 def get_file(self, request, rid, repo_slug, state_slug, folder, filename):
     """
     Return a HttpResponse
     :param request: HttpRequest
     :raise:
     """
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     q = Element.objects.filter(repository__id=rid, filename=filename)[0:1]
     q = list(q)
     if len(q) == 0:
         raise Http404
     element = q[0]
     return get_file(request, element.id, compression=None, path='', element=element, name=None)
开发者ID:wagnerwar,项目名称:Moneta,代码行数:13,代码来源:aptitude.py


示例17: simple

 def simple(self, request, rid, repo_slug, state_slug=None, search_pattern=''):
     search_pattern = search_pattern.replace('-', '').replace('_', '')
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         base_query = base_query.filter(states=state)
     if search_pattern:
         base_query = base_query.filter(archive__iexact=search_pattern)
     view_name = moneta_url(repo, 'get_file')
     elements = [(x.filename, x.md5, reverse(view_name, kwargs={'eid': x.id, })) for x in base_query[0:1000]]
     template_values = {'elements': elements, 'rid': rid, }
     return TemplateResponse(request, 'repositories/pypi/simple.html', template_values)
开发者ID:d9pouces,项目名称:Moneta,代码行数:13,代码来源:pypi.py


示例18: get_box

 def get_box(self, request: HttpRequest, rid, repo_slug, eid, archive, version, provider):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     # noinspection PyUnusedLocal
     archive = archive
     # noinspection PyUnusedLocal
     provider = provider
     # noinspection PyUnusedLocal
     version = version
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     elements = list(Element.objects.filter(repository=repo, pk=eid)[0:1])
     if not elements:
         return JsonResponse({'errors': ['Not found', ], })
     return get_file(request, eid, element=elements[0])
开发者ID:d9pouces,项目名称:Moneta,代码行数:14,代码来源:vagrant.py


示例19: xr_list_packages

 def xr_list_packages(request, rpc_args, self, rid, repo_slug, state_slug=None):
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.model)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         query = Element.objects.filter(repository=repo, states=state).order_by('name')
     else:
         query = Element.objects.filter(repository=repo).order_by('name')
     results = []
     prev = None
     for value in query:
         if value.name != prev:
             results.append(value.name)
             prev = value.name
     return results
开发者ID:d9pouces,项目名称:Moneta,代码行数:14,代码来源:pypi.py


示例20: delete_element

def delete_element(request: HttpRequest, rid, eid):
    from moneta.repository.forms import DeleteRepositoryForm

    repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
    element = get_object_or_404(Element.objects.filter(repository=repo, id=eid))
    if request.method == 'POST':
        form = DeleteRepositoryForm(request.POST)
        if form.is_valid():
            element.delete()
            messages.warning(request, _('The package %(repo)s has been deleted.') % {'repo': element.full_name})
            return HttpResponseRedirect(reverse('moneta:index'))
    else:
        form = DeleteRepositoryForm()
    template_values = {'form': form, 'repo': repo, 'element': element}
    return render_to_response('moneta/delete_element.html', template_values, RequestContext(request))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:15,代码来源:views.py



注:本文中的moneta.repository.models.Repository类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python money.Money类代码示例发布时间:2022-05-27
下一篇:
Python helpers.create_notification函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap