[Git][ftp-team/dak][master] 2 commits: remove duplicated code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Git][ftp-team/dak][master] 2 commits: remove duplicated code

Ansgar Burchardt-8
GitLab

Ansgar pushed to branch master at Debian FTP Team / dak

Commits:

  • e117a079
    by Ansgar Burchardt at 2019-06-10T13:23:59Z
    remove duplicated code
    
    The only difference between the two versions was the function used to
    parse the dependency.
    
  • a25f6b67
    by Ansgar Burchardt at 2019-06-10T14:13:14Z
    BinaryCheck: stricter check for Provides and Built-Using fields
    

1 changed file:

Changes:

  • daklib/checks.py
    ... ... @@ -460,26 +460,37 @@ class BinaryCheck(Check):
    460 460
     
    
    461 461
             # check dependency field syntax
    
    462 462
     
    
    463
    -        for field in ('Breaks', 'Conflicts', 'Depends', 'Enhances', 'Pre-Depends',
    
    464
    -                      'Provides', 'Recommends', 'Replaces', 'Suggests'):
    
    463
    +        def check_dependency_field(
    
    464
    +                field, control,
    
    465
    +                dependency_parser=apt_pkg.parse_depends,
    
    466
    +                allow_alternatives=True,
    
    467
    +                require_strict_dependency=False):
    
    465 468
                 value = control.get(field)
    
    466 469
                 if value is not None:
    
    467 470
                     if value.strip() == '':
    
    468 471
                         raise Reject('{0}: empty {1} field'.format(fn, field))
    
    469 472
                     try:
    
    470
    -                    apt_pkg.parse_depends(value)
    
    473
    +                    depends = dependency_parser(value)
    
    471 474
                     except:
    
    472 475
                         raise Reject('{0}: APT could not parse {1} field'.format(fn, field))
    
    476
    +                for group in depends:
    
    477
    +                    if not allow_alternatives and len(group) != 1:
    
    478
    +                        raise Reject('{0}: {1}: alternatives are not allowed'.format(fn))
    
    479
    +                    if require_strict_dependency \
    
    480
    +                       and any(dependency[2] != '=' for dependency in group):
    
    481
    +                        raise Reject('{0}: {1}: only strict dependencies ("=") are allowed'.format(fn, field))
    
    473 482
     
    
    474
    -        for field in ('Built-Using',):
    
    475
    -            value = control.get(field)
    
    476
    -            if value is not None:
    
    477
    -                if value.strip() == '':
    
    478
    -                    raise Reject('{0}: empty {1} field'.format(fn, field))
    
    479
    -                try:
    
    480
    -                    apt_pkg.parse_src_depends(value)
    
    481
    -                except:
    
    482
    -                    raise Reject('{0}: APT could not parse {1} field'.format(fn, field))
    
    483
    +        for field in ('Breaks', 'Conflicts', 'Depends', 'Enhances', 'Pre-Depends',
    
    484
    +                      'Recommends', 'Replaces', 'Suggests'):
    
    485
    +            check_dependency_field(field, control)
    
    486
    +
    
    487
    +        check_dependency_field("Provides", control,
    
    488
    +                               allow_alternatives=False,
    
    489
    +                               require_strict_dependency=True)
    
    490
    +        check_dependency_field("Built-Using", control,
    
    491
    +                               dependency_parser=apt_pkg.parse_src_depends,
    
    492
    +                               allow_alternatives=False,
    
    493
    +                               require_strict_dependency=True)
    
    483 494
     
    
    484 495
     
    
    485 496
     class BinaryTimestampCheck(Check):