1
+ """
2
+ Core APT repository parsing functionality
3
+ """
4
+
5
+ class AptParser :
6
+ """
7
+ Class for parsing APT repository files
8
+ """
9
+
10
+ @staticmethod
11
+ def parse_release_file (content ):
12
+ """
13
+ Parse a Release file content into structured data
14
+ """
15
+ info = {}
16
+ lines = content .split ('\n ' )
17
+ current_key = None
18
+ current_value = []
19
+
20
+ for line in lines :
21
+ if not line .strip ():
22
+ continue
23
+
24
+ if line .startswith (' ' ):
25
+ # Continuation of previous field
26
+ if current_key :
27
+ current_value .append (line .strip ())
28
+ else :
29
+ # Save previous field if exists
30
+ if current_key :
31
+ info [current_key ] = current_value [0 ] if len (current_value ) == 1 else current_value
32
+ current_value = []
33
+
34
+ # Parse new field
35
+ parts = line .split (': ' , 1 )
36
+ if len (parts ) == 2 :
37
+ key , value = parts
38
+ current_key = key
39
+ current_value = [value .strip ()]
40
+
41
+ # Save last field
42
+ if current_key :
43
+ info [current_key ] = current_value [0 ] if len (current_value ) == 1 else current_value
44
+
45
+ # Parse special fields into arrays
46
+ if 'Architectures' in info :
47
+ info ['Architectures' ] = info ['Architectures' ].split (' ' )
48
+ info ['Architectures' ] = [arch for arch in info ['Architectures' ] if arch ]
49
+
50
+ if 'Components' in info :
51
+ info ['Components' ] = info ['Components' ].split (' ' )
52
+ info ['Components' ] = [comp for comp in info ['Components' ] if comp ]
53
+
54
+ return info
55
+
56
+ @staticmethod
57
+ def parse_packages (content ):
58
+ """
59
+ Parse a Packages file content into structured data
60
+ """
61
+ packages = []
62
+ blocks = content .split ('\n \n ' )
63
+
64
+ for block in blocks :
65
+ if not block .strip ():
66
+ continue
67
+
68
+ pkg = {}
69
+ lines = block .split ('\n ' )
70
+
71
+ for line in lines :
72
+ parts = line .split (': ' , 1 )
73
+ if len (parts ) != 2 :
74
+ continue
75
+
76
+ key , value = parts
77
+ value = value .strip ()
78
+
79
+ if key == 'Package' :
80
+ pkg ['name' ] = value
81
+ elif key == 'Version' :
82
+ pkg ['version' ] = value
83
+ elif key == 'Filename' :
84
+ pkg ['filename' ] = value
85
+
86
+ if all (k in pkg for k in ['name' , 'version' , 'filename' ]):
87
+ packages .append (pkg )
88
+
89
+ return packages
90
+
91
+ @staticmethod
92
+ def build_packages_url (base_url , codename , component , arch ):
93
+ """
94
+ Build a Packages URL from components
95
+ """
96
+ clean_base_url = base_url .rstrip ('/' )
97
+ # Check if the base URL already includes the dists directory
98
+ if '/dists/' in clean_base_url :
99
+ # Extract the base part before /dists/
100
+ base_part = clean_base_url .split ('/dists/' )[0 ]
101
+ # Check if codename is already in the URL
102
+ if f"/dists/{ codename } " in clean_base_url :
103
+ return f"{ clean_base_url } /{ component } /binary-{ arch } /Packages"
104
+ else :
105
+ return f"{ base_part } /dists/{ codename } /{ component } /binary-{ arch } /Packages"
106
+ return f"{ clean_base_url } /dists/{ codename } /{ component } /binary-{ arch } /Packages"
0 commit comments