Hi Amahnui,

On 5/10/22 18:46, Abongwa Amahnui Bonalais wrote:
Hello Richard,

Thanks for the review


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?

I'm sorry I don't understand how to implement this as I tried using a function 
in the code but then the dirs was modified constantly when it was not supposed 
and I did not succeed to prevent it from doing so.
I will continue doing more research on how to go about it, but if you have a 
method you would like me to use, I would gladly try it out.
Thank you.


In pseudo-code:

html_banner_dunfell = "this"
html_banner_not_dunfell = "that"
css_banner = "something"

for directory, files in recursive_traversal(path):
    if matches(directory, '3.1*'):
        html_banner = html_banner_dunfell
    else
        html_banner = html_banner_not_dunfell
    for file in files:
        if matches(file, '*.html'):
            replace(content(file), html_banner)
        else if matches(file, '*.css'):
            replace(content(file), css_banner)

In v12 I commented the following code if you need something closer to proper Python code:

def add_banner_old_docs(dir):
    for root, dirs, filenames in os.walk(dir):
        if root.startswith('./3.1'):
            html_replacement = html_content_dunfell
        else:
            html_replacement = html_content

        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_replacement)) 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('.')

Not tested of course, but hopefully that helps you understand what I meant with factoring out the code into one function only.

Cheers,
Quentin
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#57054): https://lists.yoctoproject.org/g/yocto/message/57054
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