Coverage for linuxpy/codegen/magic.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2025-05-27 13:54 +0200

1# 

2# This file is part of the linuxpy project 

3# 

4# Copyright (c) 2023 Tiago Coutinho 

5# Distributed under the GPLv3 license. See LICENSE for more info. 

6 

7import pathlib 

8 

9from .base import CEnum, run 

10 

11HEADERS = [ 

12 "/usr/include/linux/magic.h", 

13] 

14 

15 

16TEMPLATE = """\ 

17# 

18# This file is part of the linuxpy project 

19# 

20# Copyright (c) 2023 Tiago Coutinho 

21# Distributed under the GPLv3 license. See LICENSE for more info. 

22 

23# This file has been generated by {name} 

24# Date: {date} 

25# System: {system} 

26# Release: {release} 

27# Version: {version} 

28 

29import enum 

30 

31 

32{enums_body}""" 

33 

34 

35this_dir = pathlib.Path(__file__).parent 

36 

37 

38class MagicEnum(CEnum): 

39 def __init__(self): 

40 super().__init__("Magic", "", filter=lambda name, _: "MAGIC_STRING" not in name) 

41 

42 def add_item(self, name, value): 

43 name = name.replace("_MAGIC", "") 

44 return super().add_item(name, value) 

45 

46 

47# macros from #define statements 

48MACRO_ENUMS = [MagicEnum()] 

49 

50 

51def main(output=this_dir.parent / "magic.py"): 

52 run(__name__, HEADERS, TEMPLATE, MACRO_ENUMS, output=output) 

53 

54 

55if __name__ == "__main__": 

56 main()