mail_deduplicate.strategy module¶
Strategy definitions.
- mail_deduplicate.strategy.log_selection(message_template)[source]¶
Decorator to log selection criteria.
The template reads the duplicate set as
d, and the other arguments of the selection function by their name.
- mail_deduplicate.strategy.select_older(duplicates)[source]¶
Select all older duplicates.
Discards the newests, i.e. the subset sharing the most recent timestamp.
- Return type:
- mail_deduplicate.strategy.select_oldest(duplicates)[source]¶
Select all the oldest duplicates.
Discards the newers, i.e. all mail of the duplicate set but those sharing the oldest timestamp.
- Return type:
- mail_deduplicate.strategy.select_newer(duplicates)[source]¶
Select all newer duplicates.
Discards the oldest, i.e. the subset sharing the most ancient timestamp.
- Return type:
- mail_deduplicate.strategy.select_newest(duplicates)[source]¶
Select all the newest duplicates.
Discards the olders, i.e. all mail of the duplicate set but those sharing the newest timestamp.
- Return type:
- mail_deduplicate.strategy.select_smaller(duplicates)[source]¶
Select all smaller duplicates.
Discards the biggests, i.e. the subset sharing the biggest size.
- Return type:
- mail_deduplicate.strategy.select_smallest(duplicates)[source]¶
Select all the smallest duplicates.
Discards the biggers. i.e. all mail of the duplicate set but those sharing the smallest size.
- Return type:
- mail_deduplicate.strategy.select_bigger(duplicates)[source]¶
Select all bigger duplicates.
Discards the smallests, i.e. the subset sharing the smallest size.
- Return type:
- mail_deduplicate.strategy.select_biggest(duplicates)[source]¶
Select all the biggest duplicates.
Discards the smallers, i.e. all mail of the duplicate set but those sharing the biggest size.
- Return type:
- mail_deduplicate.strategy.select_matching_path(duplicates, regexp)[source]¶
Select all duplicates whose file path matches the –regexp expression.
With several expressions, the first one that splits the set decides.
- Return type:
- mail_deduplicate.strategy.select_non_matching_path(duplicates, regexp)[source]¶
Select all duplicates whose file path doesn’t match the –regexp expression.
With several expressions, the first one that splits the set decides.
- Return type:
- mail_deduplicate.strategy.first_by_path(duplicates)[source]¶
The mail of a set that
select_one()keeps andselect_all_but_one()drops.Neither strategy compares the mails, so the order of their paths decides: the order the action trail lists them in. Both strategies then rule on the same mail at every run. A dry run names the copy that the real run acts on, and a
--jobsworker picks the copy that the main process would.- Return type:
- mail_deduplicate.strategy.select_one(duplicates)[source]¶
Select the duplicate whose path sorts first, and discard all others.
- Return type:
- mail_deduplicate.strategy.select_all_but_one(duplicates)[source]¶
Discard the duplicate whose path sorts first, and select all others.
- Return type:
- class mail_deduplicate.strategy.Strategy(*values)[source]¶
Bases:
EnumSelection strategies to apply on a set of duplicate mails.
Each strategy in the
Enumpoints to the function implementing the selection logic, by way of thefunctionproperty.Strategies whose member value is a string are simply aliases to other strategies, pointing to the name of the function implementing the logic. The other members have integer values, to indicate their function ID is to be derived from the member name. This arrangement lets each member exist on its own instead of being hidden by the aliasing mechanism of
Enum.Aliases are great usability features to represent inverse operations. They help users reason about the selection operators in whichever direction matches their mental model.
Note
True
Enumaliases (DISCARD_NEWEST = SELECT_OLDER) were considered and turned down. An alias is then the very same object as its canonical member, so it cannot be told apart at runtime, and three properties go away:str()stops round-tripping the spelling the user typed: a run started with--strategy=discard-newestwould reportselect-olderin its logs.PATH_STRATEGIESincli.pycollapses from four members to two, so the--regexphelp line and theAnyValueInerror message would name only half the strategies that require it.tests/test_strategy.pyfeedsf"--strategy={strategy_id}", so pairs like[SELECT_OLDER, DISCARD_NEWEST]would stringify identically and the alias spellings would no longer be exercised end to end.
Python 3.13 adds
Enum._add_alias_(), which accepts the CLI spelling as a name:SELECT_OLDER._add_alias_("discard-newest"). click-extra 8.9.0 givesEnumChoiceatransformargument, which kebab-cases the names of plain aliases. Neither changes the above: an alias made either way is still the same object as its member.- SELECT_OLDER = 1¶
- SELECT_OLDEST = 2¶
- SELECT_NEWER = 3¶
- SELECT_NEWEST = 4¶
- DISCARD_NEWEST = 'select_older'¶
- DISCARD_NEWER = 'select_oldest'¶
- DISCARD_OLDEST = 'select_newer'¶
- DISCARD_OLDER = 'select_newest'¶
- SELECT_SMALLER = 5¶
- SELECT_SMALLEST = 6¶
- SELECT_BIGGER = 7¶
- SELECT_BIGGEST = 8¶
- DISCARD_BIGGEST = 'select_smaller'¶
- DISCARD_BIGGER = 'select_smallest'¶
- DISCARD_SMALLEST = 'select_bigger'¶
- DISCARD_SMALLER = 'select_biggest'¶
- SELECT_MATCHING_PATH = 9¶
- SELECT_NON_MATCHING_PATH = 10¶
- DISCARD_NON_MATCHING_PATH = 'select_matching_path'¶
- DISCARD_MATCHING_PATH = 'select_non_matching_path'¶
- SELECT_ONE = 11¶
- SELECT_ALL_BUT_ONE = 12¶
- DISCARD_ALL_BUT_ONE = 'select_one'¶
- DISCARD_ONE = 'select_all_but_one'¶
- property function: Callable[..., set[DedupMailMixin]]¶
The selection function this member stands for.
Alias members carry the function’s name as their value; canonical members derive it from their own name.