Find unused resource keys in properties files in a Salesforce Commerce Cloud project and get rid of them.

Overview

Find Unused Resource Keys

Find unused resource keys in properties files in a Salesforce Commerce Cloud project and get rid of them.

It looks through all *.properties files in a specified directory and sub-directories and then proceeds to look through all specified file types in the project looking for each resource key in each line, taking note of each one that is not found. Only found keys are included in the final output, so as a result you have the properties files minus the unused keys.

Preamble

This tool is meant as a one-time check to weed out unused keys before transitioning to the excellent https://github.com/SalesforceCommerceCloud/resource-manager, so that there isn't too much overhead and bloat in terms of unused keys. You might adopt it for use in automatic processes, but I didn't write it with that intention - so do your own tests accordingly before using it.

Since this might touch thousands of keys in hundreds of files, you are advised to sanity check results and always keep backups. I don't want to be responsible for you losing translations over this. :) Though in my tests, no errors of any kind came to my attention.

How to

  1. Install jprops Python package. pip3 install jprops
  2. Clone repository or direct-download the delete-unused-resource-keys.py file from Github.
  3. Put it into a directory above or within the directory containing your properties files. It can only go down on the folder hierarchy, never up.
  4. Open the help page of the tool by executing, on a CLI: delete-unused-resource-keys.py -h. All arguments are explained so you can see what you need.
  5. Example command: python3 delete-unused-resource-keys.py -sd cartridges -td cleaned_properties -l -v, looking through all resource files in the 'cartridges' folder, putting cleaned versions of those into 'cleaned_properties' folder. It also writes a logfile (put in the target directory if given, else next to script file) called 'cleaning_report.txt'. It is also set to verbose, so outputting additional information during runtime.

Notes:

Currently, the tool does not handle duplicate files very well. If you have overloaded properties files in cartridge, i.e. with exact same name but differing contents, the last processed one will win. In this case I recommend using the tool in each cartridge separately. This should also be possible with multiple instances of the script simultaneously, with no issues - just use a different output directory for each instance.

Thanks for the hint, Daniel Anechitoaie

Having -v/--verbose flag lengthens the runtime considerably. If you want to just see what happens, before the actual final run, this is fine. During final run, it makes sense to either not set verbose flag or reroute the output to another file via python3 delete-unused-resource-keys.py -sd some_dir -td another_dir -v > console_output.txt.

Some folders are ignored during lookup. Those are defined in the is_ignored_folder function. There is a simple array inside that function containing folder name fragments. Feel free to change them to suit your needs.

The file types where the script is looking for resource keys is also described in an array called 'lookup_files', defined at the top of the script for convenience. You can just edit the array.

Running this on a multi-language/multi-brand project with hundreds of properties-files (averaging 300-500 lines each) may take 1-2 hrs.

Contribution

If you have a feasible idea for improvement, find my code horrible and want to improve it or just find an error or edge-case that isn't handled yet, feel free to either create a bug ticket here in Github or a pull request fixing the problem. Your contribution will be listed (except you don't want that).

Owner
Noël
Noël
A collection of custom scripts for working with Quake assets.

Custom Quake Tools A collection of custom scripts for working with Quake assets. Features Script to list all BSP files in a Quake mod

Jason Brownlee 3 Jul 05, 2022
Simple collection of GTPS Flood in Python.

GTPS Flood Simple collection of GTPS Flood in Python. NOTE Give me credit if you use this source, don't trade/sell this tool, And USE AT YOUR OWN RISK

PhynX 6 Dec 07, 2021
A Python script that parses and checks public proxies. Multithreading is supported.

A Python script that parses and checks public proxies. Multithreading is supported.

LevPrav 7 Nov 25, 2022
Password generator

Password generator technologies used What is? It is Password generator How to Download? Download on releases Clone repo git clone https://github.com/m

Miek 1 Nov 02, 2021
A morse code encoder and decoder utility.

morsedecode A morse code encoder and decoder utility. Installation Install it via pip: pip install morsedecode Alternatively, you can use pipx to run

Tushar Sadhwani 2 Dec 25, 2021
Random Number Generator Analysis With Python

Random-Number-Generator-Analysis Governor's Honors Program Project to determine

Jack Prewitt 2 Jan 23, 2022
Simple web index to use bloom filter for Pwned Passwords

pwbloom Simple web index to use bloom filter for Pwned Passwords The index.py runs a simple CGI web service checking passwords with a bloom filter for

Hanno Böck 4 Nov 23, 2021
Package that allows for validate and sanitize of string values.

py.validator A library of string validators and sanitizers Insipired by validator.js Strings only This library validates and sanitizes strings only. P

Sanel Hadzini 22 Nov 08, 2022
Pyfunctools is a module that provides functions, methods and classes that help in the creation of projects in python

Pyfunctools Pyfunctools is a module that provides functions, methods and classes that help in the creation of projects in python, bringing functional

Natanael dos Santos Feitosa 5 Dec 22, 2022
Attempts to crack the compression puzzle.

The Compression Puzzle One lovely Friday we were faced with this nice yet intriguing programming puzzle. One shall write a program that compresses str

Oto Brglez 14 Dec 29, 2022
Dependency injection lib for Python 3.8+

PyDI Dependency injection lib for python How to use To define the classes that should be injected and stored as bean use decorator @component @compone

Nikita Antropov 2 Nov 09, 2021
A utility that makes it easy to work with Python projects containing lots of packages, of which you only want to develop some.

Mixed development source packages on top of stable constraints using pip mxdev [mɪks dɛv] is a utility that makes it easy to work with Python projects

BlueDynamics Alliance 6 Jun 08, 2022
Parse URLs for DOIs, PubMed identifiers, PMC identifiers, arXiv identifiers, etc.

citation-url Parse URLs for DOIs, PubMed identifiers, PMC identifiers, arXiv identifiers, etc. This module has a single parse() function that takes in

Charles Tapley Hoyt 2 Feb 12, 2022
cssOrganizer - organize a css file by grouping them into categories

This python project was created to scan through a CSS file and produce a more organized CSS file by grouping related CSS Properties within selectors. Created in my spare time for fun and my own utili

Andrew Espindola 0 Aug 31, 2022
Script to generate a massive volume of data in sql, csv, json or xml format

DataGenerator Made with Python Open for pull requests 1. Dependencies To install required dependencies run pip install -r requirements.txt 2. Executi

icrescenti 3 Sep 20, 2022
Check username

Checker-Oukee Check username It checks the available usernames and creates a new account for them Doesn't need proxies Create a file with usernames an

4 Jun 05, 2022
Tool for generating Memory.scan() compatible instruction search patterns

scanpat Tool for generating Frida Memory.scan() compatible instruction search patterns. Powered by r2. Examples $ ./scanpat.py arm.ks:64 'sub sp, sp,

Ole André Vadla Ravnås 13 Sep 19, 2022
Application for easy configuration of swap file and swappiness priority in slackware and others linux distributions.

Swap File Program created with the objective of assisting in the configuration of swap file in Distributions such as Slackware. Required packages: pyt

Mauricio Ferrari 3 Aug 06, 2022
Python script to get some stats on nodes in a Blender material nodetree

Python script to get some stats on nodes in a Blender material nodetree. It counts the nodes, the node types and the max deep level for group nodes.

Alek Mugnozzo 2 Sep 03, 2022
Python based tool to extract forensic info from EventTranscript.db (Windows Diagnostic Data)

EventTranscriptParser EventTranscriptParser is python based tool to extract forensically useful details from EventTranscript.db (Windows Diagnostic Da

P. Abhiram Kumar 24 Nov 18, 2022