Coverage for debputy/plugins/perl_openssl.py: 75%

20 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-07 12:14 +0200

1import functools 

2import os 

3import subprocess 

4from typing import Any 

5 

6from debputy.plugin.api import ( 

7 DebputyPluginInitializer, 

8 BinaryCtrlAccessor, 

9 PackageProcessingContext, 

10) 

11from debputy.util import _error 

12 

13 

14def initialize(api: DebputyPluginInitializer) -> None: 

15 api.metadata_or_maintscript_detector( 

16 "perl-openssl-abi", 

17 detect_perl_openssl_abi, 

18 ) 

19 

20 

21@functools.lru_cache 

22def _resolve_libssl_abi(cmd: str) -> str: 

23 try: 

24 return subprocess.check_output([cmd]).strip().decode("utf-8") 

25 except FileNotFoundError: 

26 _error( 

27 f"The perl-openssl plugin requires that perl-openssl-defaults + libssl-dev is installed" 

28 ) 

29 except subprocess.CalledProcessError as e: 

30 _error(f"") 

31 

32 

33def detect_perl_openssl_abi( 

34 _unused: Any, 

35 ctrl: BinaryCtrlAccessor, 

36 _context: PackageProcessingContext, 

37) -> None: 

38 cmd = os.environ.get( 

39 "_PERL_SSL_DEFAULTS_TEST_PATH", 

40 "/usr/share/perl-openssl-defaults/get-libssl-abi", 

41 ) 

42 abi = _resolve_libssl_abi(cmd) 

43 ctrl.substvars.add_dependency("perl:Depends", f"perl-openssl-abi-{abi}")