wip
This commit is contained in:
		
							parent
							
								
									ca0966a33b
								
							
						
					
					
						commit
						bd8b3fcc2d
					
				
					 2 changed files with 27 additions and 8 deletions
				
			
		| 
						 | 
					@ -31,15 +31,17 @@ actions = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hosts = {}
 | 
					hosts = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for source in node.metadata.get('apt/sources'):
 | 
					for source_string in node.metadata.get('apt/sources'):
 | 
				
			||||||
    host = repo.libs.apt.AptSource(source).url.hostname
 | 
					    source = repo.libs.apt.AptSource(source_string)
 | 
				
			||||||
    hosts\
 | 
					    hosts\
 | 
				
			||||||
        .setdefault(host, set())\
 | 
					        .setdefault(source.url.hostname, set())\
 | 
				
			||||||
        .add(source)
 | 
					        .add(source)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for host, sources in hosts.items():
 | 
					for host, sources in hosts.items():
 | 
				
			||||||
    files[f'/etc/apt/sources.list.d/{host}.list'] = {
 | 
					    files[f'/etc/apt/sources.list.d/{host}.list'] = {
 | 
				
			||||||
        'content': '\n'.join(sorted(sources)).format(
 | 
					        'content': '\n'.join(
 | 
				
			||||||
 | 
					            str(source) for source in sorted(sources)
 | 
				
			||||||
 | 
					        ).format(
 | 
				
			||||||
            release=node.metadata.get('os_release')
 | 
					            release=node.metadata.get('os_release')
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
        'triggers': {
 | 
					        'triggers': {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										25
									
								
								libs/apt.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								libs/apt.py
									
									
									
									
									
								
							| 
						 | 
					@ -1,11 +1,13 @@
 | 
				
			||||||
# https://manpages.debian.org/jessie/apt/sources.list.5.de.html
 | 
					# https://manpages.debian.org/jessie/apt/sources.list.5.de.html
 | 
				
			||||||
from urllib.parse import urlparse
 | 
					from urllib.parse import urlparse
 | 
				
			||||||
from re import match, search, sub
 | 
					from re import search, sub
 | 
				
			||||||
 | 
					from functools import total_ordering
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@total_ordering
 | 
				
			||||||
class AptSource():
 | 
					class AptSource():
 | 
				
			||||||
    def __init__(self, string):
 | 
					    def __init__(self, string):
 | 
				
			||||||
        if match(r'\[.*\]', string):
 | 
					        if search(r'\[.*\]', string):
 | 
				
			||||||
            self.options = {
 | 
					            self.options = {
 | 
				
			||||||
                k:v.split('=') for k,v in (
 | 
					                k:v.split('=') for k,v in (
 | 
				
			||||||
                    e.split('=') for e in search(r'\[(.*)\]', string)[1].split()
 | 
					                    e.split('=') for e in search(r'\[(.*)\]', string)[1].split()
 | 
				
			||||||
| 
						 | 
					@ -13,13 +15,14 @@ class AptSource():
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.options = {}
 | 
					            self.options = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parts = sub(r'\[.*\]', '', string).split()
 | 
					        parts = sub(r'\[.*\]', '', string).split()
 | 
				
			||||||
        self.type = parts[0]
 | 
					        self.type = parts[0]
 | 
				
			||||||
        self.url = urlparse(parts[1])
 | 
					        self.url = urlparse(parts[1])
 | 
				
			||||||
        self.suite = parts[2]
 | 
					        self.suite = parts[2]
 | 
				
			||||||
        self.components = parts[3:]
 | 
					        self.components = parts[3:]
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def render(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        parts = [
 | 
					        parts = [
 | 
				
			||||||
            self.type,
 | 
					            self.type,
 | 
				
			||||||
            self.url.geturl(),
 | 
					            self.url.geturl(),
 | 
				
			||||||
| 
						 | 
					@ -42,6 +45,20 @@ class AptSource():
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        return ' '.join(parts)
 | 
					        return ' '.join(parts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    def __eq__(self, other):
 | 
				
			||||||
 | 
					        return str(self) == str(other)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    def __lt__(self, other):
 | 
				
			||||||
 | 
					        return str(self) < str(other)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __hash__(self):
 | 
				
			||||||
 | 
					        return hash(str(self))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __repr__(self):
 | 
				
			||||||
 | 
					        return f"{type(self).__name__}('{str(self)}')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# source = AptSource('deb [arch=amd64 trusted=true] http://deb.debian.org/debian buster-backports main contrib non-free')
 | 
					# source = AptSource('deb [arch=amd64 trusted=true] http://deb.debian.org/debian buster-backports main contrib non-free')
 | 
				
			||||||
# print(repr(source))
 | 
					# print(repr(source))
 | 
				
			||||||
# print(source.type)
 | 
					# print(source.type)
 | 
				
			||||||
| 
						 | 
					@ -50,4 +67,4 @@ class AptSource():
 | 
				
			||||||
# print(source.url)
 | 
					# print(source.url)
 | 
				
			||||||
# print(source.suite)
 | 
					# print(source.suite)
 | 
				
			||||||
# print(source.components)
 | 
					# print(source.components)
 | 
				
			||||||
# print(source.render())
 | 
					# print(str(source))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue