Beispiel #1
0
 def test_inf(self):
     """
     Parse with requirements =<
     """
     result = requ_parser("foo=<1.0\n")
     attend = [['foo', '=<', '1.0']]
     self.assertEqual(result, attend)
Beispiel #2
0
 def test_sup(self):
     """
     Parse with requirements >=
     """
     result = requ_parser("foo>=1.0\n")
     attend = [['foo', '>=', '1.0']]
     self.assertEqual(result, attend)
Beispiel #3
0
 def test_equal(self):
     """
     Parse with requirements ==
     """
     result = requ_parser("foo==1\n")
     attend = [['foo', '==', '1']]
     self.assertEqual(result, attend)
Beispiel #4
0
def analyzereq(request, pk, dist):
    """
    Output a requirements.txt file based on distribution verison number
    """
    qryset = Package.objects.all().order_by('-pk')[:7]
    lkup = get_object_or_404(Lookup, pk=pk)
    distro = get_object_or_404(Distribution, pk=dist)
    datas = requ_parser(lkup.content)
    result = []
    for pack in datas:
        known = DisPack.objects.filter(package__name=pack[0],
                                       distribution=distro)
        if len(known) == 1:
            result.append([pack[0], known[0].package_version])
        else:
            result.append([pack[0]])

    return render(request,
                  'requirements.txt',
                  {'pk': pk,
                   'founds': result,
                   'ori': datas,
                   'distro': distro,
                   'lkup': lkup.content,
                   },
                  content_type='text/plain')
Beispiel #5
0
def analyze_post(request):
    """
    User POST a content to analyze
    """
    distros = Distribution.objects.all().order_by('-pk')
    dists = [(r.id, "%s %s" % (r.name, r.version_name)) for r in distros]
    form = ReqForm(dists, request.POST)
    pckexists = 0
    if form.is_valid():
        datas = requ_parser(form.cleaned_data['content'])
        for odist in distros:
            if odist.id == int(form.cleaned_data['distribution']):
                dist = odist
        lkup = Lookup.objects.create(content=form.cleaned_data['content'],
                                     distribution=dist,
                                     nb_line=len(datas))
        for pack in datas:
            try:
                pobj = Package.objects.get(name=pack[0])
                pckexists = 1
            except Package.DoesNotExist:
                try:
                    look4_pypi_missing.delay(pack[0])
                except:
                    logger.error("Error in lauching task look4_pypi_missing.delay(pack[0])")

            if pckexists:
                logg_pypi.delay(pobj, lkup)

        return redirect('/analyze/%s/' % lkup.id)
    else:
        logger.error("form is not valid")
        return userreq(request)
Beispiel #6
0
 def test_nover(self):
     """
     Test with no version number
     """
     result = requ_parser("foo\nDjango>=1.3.4")
     attend = [['foo'],
               ['Django', '>=', '1.3.4']]
     self.assertEqual(result, attend)
Beispiel #7
0
 def test_whitespace(self):
     """
     Whitespaces on line
     """
     result = requ_parser("foo bar\nDjango>=1.3.4\n")
     attend = [['foo'],
               ['Django', '>=', '1.3.4']]
     self.assertEqual(result, attend)
Beispiel #8
0
 def test_overlimit(self):
     """
     Test with 2 lines
     """
     result = requ_parser("foo>=1.0\nDjango>=1.3\ndateutil\argparse\n", 2)
     attend = [['foo', '>=', '1.0'],
               ['Django', '>=', '1.3']]
     self.assertEqual(result, attend)
Beispiel #9
0
 def test_2lines(self):
     """
     Test with 2 lines
     """
     result = requ_parser("foo>=1.0\nDjango>=1.3.4")
     attend = [['foo', '>=', '1.0'],
               ['Django', '>=', '1.3.4']]
     self.assertEqual(result, attend)
Beispiel #10
0
def analyze_get(request, pk):
    """
    Read an existing analyze
    """
    lkup = get_object_or_404(Lookup, pk=pk)
    datas = requ_parser(lkup.content)
    for pack in datas:
        try:
            Package.objects.get(name=pack[0])
        except Package.DoesNotExist:
            try:
                look4_pypi_missing.delay(pack[0])
            except:
                logger.error("Error in lauching task look4_pypi_missing.delay(pack[0])")

    return render(request,
                  'analyze.html',
                  {'founds': datas,
                   'lookup': lkup
                   })