[elbe-devel] [PATCH] elbe-dump: remove LOCALMACHINE from sources.list

Olivier Dion dion at linutronix.de
Mon Aug 31 22:29:54 CEST 2020


On Mon, 31 Aug 2020, Christian Teklenborg <chris at linutronix.de> wrote:
> When LOCALMACHINE is used within an Elbe XML, a line 'deb ... http://10.0.2.2'
> is appended to /etc/apt/sources.list. Remove it so that any apt operation on
> the resulting system shall not give any warning or error.
>
> Signed-off-by: Christian Teklenborg <chris at linutronix.de>
> ---
>  elbepack/dump.py | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/elbepack/dump.py b/elbepack/dump.py
> index edc6637f..f8e20220 100644
> --- a/elbepack/dump.py
> +++ b/elbepack/dump.py
> @@ -164,6 +164,24 @@ def check_full_pkgs(pkgs, fullpkgs, cache):
>          validation.info("No Errors found")
>  
>  
> +def clean_apt_sources_list():
> +
> +    fp = open('../target/etc/apt/sources.list', 'r')
> +    sources = fp.read().split("\n")
> +    fp.close()
> +
> +    sources_list = ''
> +
> +    for source in sources:
> +        if "10.0.2.2" in source:
> +            pass
> +        else:
> +            sources_list += source + '\n'
> +
> +    fp = open('../target/etc/apt/sources.list', 'w')
> +    fp.write(sources_list)
> +    fp.close()
> +

Please use context managers for opening files:
----------------------------------------------------------------------
def clean_apt_sources_list():

    src_path = "../target/etc/apt/sources.list"
    
    with open(src_path, "r") as f:
        src_lst = f.read().split('\n')

    src_lst = [src in src_lst
               if "10.0.2.2" not in src]

    with open(src_path, "w") as f:
        f.write('\n'.join(src_lst) + '\n')
----------------------------------------------------------------------

-- 
Olivier Dion
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen


More information about the elbe-devel mailing list