Maintenance scripts#
This page contains documentation of the scripts.maintenance
module:
Maintenance scripts
Removed in version 3.0.20190430: diff_checker
script was removed (T221462).
Removed in version 6.1: compat2core
script was removed.
Removed in version 7.3: update_linktrails
script (T89451) and update_script
script were removed.
Removed in version 8.0: sorting_order
script was removed (T325426).
Removed in version 9.0: wikimedia_sites
script was removed (T78396).
Maintenance submodules#
scripts.maintenance.addwikis#
Script that adds new wikis to the codes set in Wikimedia family files
Usage:
python pwb.py addwikis [-family:<family>] {<wiki>}
Added in version 9.2.
scripts.maintenance.cache#
This script runs commands on each entry in the API caches
Syntax:
python pwb.py cache [-password] [-delete] [-c "..."] [-o "..."] [dir ...]
If no directory are specified, it will detect the API caches.
If no command is specified, it will print the filename of all entries. If only -delete is specified, it will delete all entries.
The following parameters are supported:
-delete Delete each command filtered. If that option is set the
default output will be nothing.
-c Filter command in python syntax. It must evaluate to True to
output anything.
-o Output command which is output when the filter evaluated to
True. If it returns None it won't output anything.
Examples
Print the filename of any entry with ‘wikidata’ in the key:
-c "wikidata" in entry._uniquedescriptionstr()
Customised output if the site code is ‘ar’:
-c entry.site.code == "ar"
-o uniquedesc(entry)
Or the state of the login:
-c entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED
-o uniquedesc(entry)
If the function only uses one parameter for the entry it can be omitted:
-c has_password
-o uniquedesc
Available filter commands:
has_password(entry)
is_logout(entry)
empty_response(entry)
not_accessed(entry)
incorrect_hash(entry)
older_than_one_day(entry)
recent(entry)
There are helper functions which can be part of a command:
older_than(entry, interval)
newer_than(entry, interval)
Available output commands:
uniquedesc(entry)
- class scripts.maintenance.cache.CacheEntry(directory, filename)[source]#
Bases:
CachedRequest
A Request cache entry.
- Parameters:
directory (str)
filename (str)
- scripts.maintenance.cache.process_entries(cache_path, func, use_accesstime=None, output_func=None, action_func=None, *, tests=None)[source]#
Check the contents of the cache.
This program tries to use file access times to determine whether cache files are being used. However file access times are not always usable. On many modern filesystems, they have been disabled. On Unix, check the filesystem mount options. You may need to remount with ‘strictatime’.
Changed in version 9.0: default cache path to ‘apicache’ without Python main version.
- Parameters:
use_accesstime (bool | None) – Whether access times should be used.
None
for detect,False
for don’t use andTrue
for always use.tests (int | None) – Only process a test sample of files
scripts.maintenance.colors#
Utility to show pywikibot colors
scripts.maintenance.make_i18n_dict#
Generate an i18n file from a given script
run IDLE at topmost level:
>>> import pwb
>>> from scripts.maintenance.make_i18n_dict import i18nBot
>>> bot = i18nBot('<scriptname>', '<msg dict>')
>>> bot.run()
If you have more than one message dictionary, give all these names to the bot:
>>> bot = i18nBot('<scriptname>', '<msg dict1>', '<msg dict2>', '<msg dict3>')
If you want to rename the message index use keyword arguments. This may be mixed with preleading positonal arguments:
>>> bot = i18nBot('<scriptname>', '<msg dict1>', the_other_msg='<msg dict2>')
If you have the messages as instance constants you may call the bot as follows:
>>> bot = i18nBot('<scriptname>.<class name>', '<msg dict1>', '<msg dict2>')
It’s also possible to make json files too by using to_json method after
instantiating the bot. It also calls bot.run()
to create the dictionaries:
>>> bot.to_json()
scripts.maintenance.unidata#
Script to update :mod:`pywikibot.tools._unidata`
This script is for updating _first_upper_exception_dict
.
Note
I seems that running under the latest version of Python gives a superse of the older version and should be enough. But this is not tested completely.
Added in version 8.4.
- scripts.maintenance.unidata.chars_uppers_wikilinks()[source]#
Retrieve upper chars from MediaWiki using page titles.