On Wed, 2022-05-04 at 12:08 +0100, Abongwa Amahnui Bonalais wrote:
> 
> +
> +def add_banner_old_docs(dir):
> +    exclude = []
> +    for root, dirs, filenames in os.walk(dir):
> +         # exclude banner for 3.1.x upward as it is an LTS release and is 
> still supported
> +        exclude = [ name for name in os.listdir(dir) if 
> name.startswith('3.1') ]
> +        for d in dirs:
> +            if d in exclude:
> +                dirs.remove(d)
> +        for filename in filenames:
> +            if filename.endswith('.html'):
> +                with open(os.path.join(root, filename), 'r', 
> encoding="ISO-8859-1") as f:
> +                    current_content = f.read()
> +                with open(os.path.join(root, filename), 'w') as f:

This is definitely getting there, thanks!

One small thing, shouldn't we write the files with the same encoding as we read
them?

> +                    f.write(current_content.replace('<body>', '<body>' + 
> html_content))
> +                    f.write(current_content.replace('</body>', last_div + 
> '</body>'))
> +            if filename.endswith('.css'):
> +                with open(os.path.join(root, filename), 'r', 
> encoding="ISO-8859-1") as f:
> +                    css_content = f.read()
> +                with open(os.path.join(root, filename), 'w') as f:
> +                    
> f.write(css_content.replace(css_content[css_content.find('body 
> {'):css_content.find('}'[0])], 'body {' + css_replacement_content ))
> +add_banner_old_docs('.')
> +
> +
> +
> +
> +def dunfell_docs(dir):
> +    dunfell_banners = []
> +    for root, dirs, filenames in os.walk(dir):
> +        dunfell_banners = [ name for name in os.listdir(dir) if not 
> name.startswith('3.1') ]
> +        for d in dirs:
> +            if d in dunfell_banners:
> +                dirs.remove(d)
> +        for filename in filenames:
> +            if filename.endswith('.html'):
> +                with open(os.path.join(root, filename), 'r', 
> encoding="ISO-8859-1") as f:
> +                    current_content = f.read()
> +                with open(os.path.join(root, filename), 'w') as f:
> +                    f.write(current_content.replace('<body>', '<body>' + 
> html_content_dunfell))
> +                    f.write(current_content.replace('</body>', last_div + 
> '</body>'))
> +            if filename.endswith('.css'):
> +                with open(os.path.join(root, filename), 'r', 
> encoding="ISO-8859-1") as f:
> +                    css_content = f.read()
> +                with open(os.path.join(root, filename), 'w') as f:
> +                    
> f.write(css_content.replace(css_content[css_content.find('body 
> {'):css_content.find('}'[0])], 'body {' + css_replacement_content ))

I think Quentin also mentioned that these two loop functions can be merged
together to form simpler code with a condition in the centre section?

> +dunfell_docs('.')
> \ No newline at end of file

We can add a newline at the end to avoid that.

Cheers,

Richard


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#57007): https://lists.yoctoproject.org/g/yocto/message/57007
Mute This Topic: https://lists.yoctoproject.org/mt/90884595/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to