Utility scripts

pwb wrapper script

Wrapper script to invoke pywikibot-based scripts.

Run scripts with pywikibot in directory mode using:

python pwb.py <pwb options> <name_of_script> <options>

This wrapper script uses the package directory to store all user files, will fix up search paths so the package does not need to be installed, etc.

Currently <pwb options> are Global Options. This can be used for tests to set the default site (see T216825):

python pwb.py -lang:de bot_tests -v
pwb.abspath(path)[source]

Convert path to absolute path, with uppercase drive letter on win32.

pwb.check_modules(script=None)[source]

Check whether mandatory modules are present.

This also checks Python version when importing deptendencies from setup.py

Parameters

script (str or None) – The script name to be checked for dependencies

Returns

True if all dependencies are installed

Return type

bool

Raises

RuntimeError – wrong Python version found in setup.py

pwb.check_pwb_versions(package)[source]

Validate package version and scripts version.

Rules:
  • Pywikibot version must not be older than scrips version

  • Scripts version must not be older than previous Pyvikibot version due to deprecation policy

pwb.find_alternates(filename, script_paths)[source]

Search for similar filenames in the given script paths.

pwb.find_filename(filename)[source]

Search for the filename in the given script paths.

pwb.handle_args(pwb_py, *args)[source]

Handle args and get filename.

Returns

filename, script args, local args for pwb.py

Return type

tuple

pwb.main()[source]

Command line entry point.

pwb.run_python_file(filename, argv, argvu, package=None)[source]

Run a python file as if it were the main program on the command line.

filename is the path to the file to execute, it need not be a .py file. args is the argument array to present as sys.argv, as unicode strings.

generate_family_file script

This script generates a family file from a given URL.

Usage:

generate_family_file.py [<url>] [<name>] [<dointerwiki>] [<verify>]

Parameters are optional. They must be given consecutively but may be omitted if there is no successor parameter. The parameters are:

<url>:         an url from where the family settings are loaded
<name>:        the family name without "_family.py" tail.
<dointerwiki>: predefined answer (y|n) to add multiple language
<verify>:      disable certificate validaton `(y|n)

Example:

generate_family_file.py https://www.mywiki.bogus/wiki/Main_Page mywiki

This will create the file mywiki_family.py in pywikibot/families folder

class generate_family_file.FamilyFileGenerator(url: Optional[str] = None, name: Optional[str] = None, dointerwiki: Optional[str] = None, verify: Optional[str] = None)[source]

Bases: object

Family file creator object.

Parameters are optional. If not given the script asks for the values.

Parameters
  • url – an url from where the family settings are loaded

  • name – the family name without “_family.py” tail.

  • dointerwiki – Predefined answer to add multiple language codes. Pass Y or y for yes N or n for no and E or e if you want to edit the collection of sites.

  • verify – If a certificate verification failes, you may pass Y or y to disable certificate validaton N or n to keep it enabled.

get_params()[source]

Ask for parameters if necessary.

get_wiki()[source]

Get wiki from base_url.

getapis()[source]

Load other language pages.

getlangs(w)[source]

Determine language of a site.

run()[source]

Main method, generate family file.

writefile(verify)[source]

Write the family file.

generate_family_file.main()[source]

Process command line arguments and generate a family file.

generate_user_files script

Script to create user-config.py.

generate_user_files.ask_for_dir_change(force)[source]

Ask whether the base directory is has to be changed.

Only give option for directory change if user-config.py or user-password already exists in the directory. This will repeat if user-config.py also exists in the requested directory.

Parameters

force (bool) – Skip asking for directory change

Returns

whether user file or password file exists already

Return type

tuple of bool

generate_user_files.change_base_dir()[source]

Create a new user directory.

generate_user_files.copy_sections()[source]

Take config sections and copy them to user-config.py.

Returns

config text of all selected sections.

Return type

str

generate_user_files.create_user_config(main_family, main_code, main_username, force=False)[source]

Create a user-config.py in base_dir.

Create a user-password.py if necessary.

generate_user_files.file_exists(filename)[source]

Return whether the file exists and print a message if it exists.

generate_user_files.get_site_and_lang(default_family: Optional[str] = 'wikipedia', default_lang: Optional[str] = 'en', default_username: Optional[str] = None, force=False)[source]

Ask the user for the family, language and username.

Parameters
  • default_family – The default family which should be chosen.

  • default_lang – The default language which should be chosen, if the family supports this language.

  • default_username – The default username which should be chosen.

Returns

The family, language and username

Return type

tuple of three str

generate_user_files.main(*args: tuple)[source]

Process command line arguments and generate user-config.

If args is an empty list, sys.argv is used.

Parameters

args – command line arguments

generate_user_files.parse_sections()[source]

Parse sections from config.py file.

config.py will be in the pywikibot/ directory relative to this generate_user_files script.

Returns

a list of ConfigSection named tuples.

Return type

list

generate_user_files.save_botpasswords(botpasswords, _fncpass)[source]

Write botpasswords to file.