Skip to content

Conversation

@X9VoiD
Copy link
Member

@X9VoiD X9VoiD commented Nov 30, 2024

Backports #3522 to 0.6.x branch.

For the cleanup, I used the following script:

import json
import os
import sys

def process_file(filepath):
    if filepath.endswith(".json"):
        try:
            with open(filepath, 'r+') as f:
                data = json.load(f)

                def remove_redundant(obj):
                    if isinstance(obj, dict):
                        return {k: remove_redundant(v) for k, v in obj.items() if v is not None and v != {} and (not isinstance(v, list) or v)}
                    elif isinstance(obj, list):
                        return [remove_redundant(item) for item in obj if item is not None and item != {} and (not isinstance(item, list) or item)]
                    else:
                        return obj

                cleaned_data = remove_redundant(data)
                f.seek(0)
                json.dump(cleaned_data, f, indent=2)
                f.truncate()

        except (FileNotFoundError, json.JSONDecodeError) as e:
            print(f"Error processing {filepath}: {e}")
            return

    with open(filepath, 'r+', encoding='utf-8') as f:
        content = f.read()
        if not content.endswith('\n'):
            f.write('\n')

def process_directory(directory):
    for root, _, files in os.walk(directory):
        for filename in files:
            process_file(os.path.join(root, filename))

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python cleanup.py <directory>")
        sys.exit(1)

    directory = sys.argv[1]
    process_directory(directory)

Will commit this to repo if desired.

@X9VoiD X9VoiD force-pushed the minimize-attribute-0.6.x branch from 468bf19 to 29436b8 Compare November 30, 2024 13:09
Copy link
Member

@gonX gonX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked code, LGTM.

@gonX gonX added enhancement New feature or request configuration Adds or modifies a tablet configuration labels Nov 30, 2024
@gonX gonX linked an issue Nov 30, 2024 that may be closed by this pull request
@gonX gonX added this to the v0.6.5 milestone Nov 30, 2024
@X9VoiD X9VoiD merged commit e0856b8 into OpenTabletDriver:0.6.x Nov 30, 2024
8 checks passed
@X9VoiD X9VoiD deleted the minimize-attribute-0.6.x branch November 30, 2024 15:11
@gonX gonX added the forward-port-not-needed Feature is already implemented, is not relevant, or is considered elsewhere for Avalonia branch label Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Adds or modifies a tablet configuration enhancement New feature or request forward-port-not-needed Feature is already implemented, is not relevant, or is considered elsewhere for Avalonia branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backport Reduce bloat of tablet configuration JSONs

2 participants