Created
September 10, 2024 05:29
-
-
Save planetis-m/a4ed1fca5aabc2f9107744fbac165c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def process_file(file_path, pattern_length=100): | |
try: | |
with open(file_path, 'r', encoding='utf-8') as file: | |
content = file.read() | |
if len(content) <= pattern_length: | |
print(f"Skipping {file_path}: File is too short.") | |
return | |
pattern = content[:pattern_length] | |
start_index = pattern_length | |
repeat_index = content.find(pattern, start_index) | |
if repeat_index != -1: | |
# Found a repetition, trim the file | |
trimmed_content = content[:repeat_index] | |
# Write the trimmed content back to the file | |
with open(file_path, 'w', encoding='utf-8') as file: | |
file.write(trimmed_content) | |
chars_removed = len(content) - len(trimmed_content) | |
print(f"Processed {file_path}: Removed {chars_removed} characters.") | |
else: | |
print(f"No repetition found in {file_path}. File left unchanged.") | |
except Exception as e: | |
print(f"Error processing {file_path}: {str(e)}") | |
def process_item(item, base_path=''): | |
full_path = os.path.join(base_path, item) | |
if item.endswith('.po'): | |
process_file(full_path) | |
elif os.path.isdir(full_path): | |
traverse_directory(full_path) | |
else: | |
print(f"Skipping {full_path} (not a .po file or directory)") | |
def traverse_directory(directory): | |
for root, dirs, files in os.walk(directory): | |
for file in files: | |
if file.endswith('.po'): | |
process_file(os.path.join(root, file)) | |
def main(): | |
file_list = [ | |
"accessibility-inspector", | |
"accessibility-inspector._desktop_.po", | |
"accessibility-inspector._desktop_.po.orig", | |
"akonadi/akonadi-db-migrator.po", | |
"akonadiclient", | |
"akonadiconsole/akonadiconsole.po", | |
"alkimia", | |
"alligator", | |
"alpaka", | |
"amor", | |
"arianna", | |
"arkade", | |
"atlantik", | |
"audex", | |
"audiotube", | |
"aura-browser", | |
"baloo/baloo_file6.po", | |
"baloo/baloo_file_extractor6.po", | |
"bigscreen-debos-image-rpi4", | |
"buho", | |
"clazy", | |
"dolphin-plugins/makefileactions.po", | |
"dolphin-plugins/mountisoaction.po", | |
"dolphin-plugins/org.kde.dolphin-plugins.metainfo.po", | |
"dragon/dragon._json_.po", | |
"ffmpegthumbs", | |
"flatpak-kcm", | |
"haruna", | |
"kcm-grub2", | |
"kcolorscheme", | |
"kconfig/kconfig._desktop_.po", | |
"kdesdk-devenv-dependencies", | |
"kdesdk-thumbnailers", | |
"kglobalacceld", | |
"kguiaddons", | |
"kio-admin", | |
"kpeoplevcard", | |
"kpipewire", | |
"ksvg", | |
"kwin/kcm_kwin_effects.po", | |
"kwindowsystem/kwindowsystem5_qt.po", | |
"libkipi", | |
"libkscreen", | |
"libplasma/libplasma._desktop_.po", | |
"mauiman", | |
"mycroft-skill-installer", | |
"neochat/neochat._json_.po", | |
"neon-neon-repositories", | |
"ocean-sound-theme", | |
"output.patch", | |
"oxygen-sounds", | |
"peertube-voice-application", | |
"phonon-vlc", | |
"pico-wizard", | |
"plasma-desktop/kcm_gamecontroller.po", | |
"plasma-desktop/kcm_keys.po", | |
"plasma-desktop/kcm_landingpage.po", | |
"plasma-desktop/kcm_recentFiles.po", | |
"plasma-desktop/kcm_tablet.po", | |
"plasma-desktop/kcm_touchscreen.po", | |
"plasma-desktop/kcmqtquicksettings.po", | |
"plasma-desktop/org.kde.plasma.emojier.po", | |
"plasma-desktop/plasma-desktop-sddm-theme.po", | |
"plasma-desktop/plasma_applet_org.kde.panel.po", | |
"plasma-desktop/plasma_applet_org.kde.plasma.keyboardlayout.po", | |
"plasma-desktop/plasma_toolbox_org.kde.paneltoolbox.po", | |
"plasma-mobile-sounds", | |
"plasma-settings/mobile.plasmasettings.po", | |
"plasma-systemmonitor", | |
"plasma-welcome", | |
"plasma-workspace/kcm_feedback.po", | |
"plasma-workspace/kcm_nightlight.po", | |
"plasma-workspace/kcm_notifications.po", | |
"plasma-workspace/kcm_regionandlang.po", | |
"plasma-workspace/kcm_soundtheme.po", | |
"plasma-workspace/kcm_users.po", | |
"plasma-workspace/kded_devicenotifications.po", | |
"plasma-workspace/kded_donationmessage.po", | |
"plasma-workspace/libkmpris.po", | |
"plasma-workspace/libnotificationmanager.po", | |
"plasma-workspace/plasma_applet_org.kde.plasma.activitybar.po", | |
"plasma-workspace/plasma_applet_org.kde.plasma.cameraindicator.po", | |
"plasma-workspace/plasma_applet_org.kde.plasma.manageinputmethod.po", | |
"plasma-workspace/plasma_applet_org.kde.plasma.systemmonitor.po", | |
"plasma-workspace/plasma_containmentactions_applauncher.po", | |
"plasma-workspace/plasma_engine_hotplug.po", | |
"plasma-workspace/plasma_interactiveconsole.po", | |
"plasma-workspace/plasma_runner_appstream.po", | |
"plasma-workspace/plasmawindowed.po", | |
"plasma-workspace/session-shortcuts-kded.po", | |
"plasma-workspace-wallpapers/plasma-workspace-wallpapers._desktop_.po", | |
"rattlesnake", | |
"soundcloud-voice-application", | |
"ubiquity-slideshow-neon", | |
"washipad", | |
"wikidata-voice-application", | |
"xdg-portal-test-kde", | |
"youtube-voice-application" | |
] | |
for item in file_list: | |
process_item(item) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment