Page MenuHomePhabricator

Implement -save option on replace.py core
Closed, DuplicatePublic

Description

Author: arjunaraoc

Description:
Trying to save using -search or -filelinks is giving error (extract below)

arjun@arjun-945GCM-S2L:~/pwb/core$ python pwb.py replace.py -filelinks:CNREDDY.JPG -save:cnrtoc.txt "అ" "ఇ"
Traceback (most recent call last):

File "pwb.py", line 104, in <module>
  run_python_file(fn, args)
File "pwb.py", line 49, in run_python_file
  exec compile(source, filename, "exec") in main_mod.__dict__
File "scripts/replace.py", line 696, in <module>
  main()
File "scripts/replace.py", line 549, in main
  raise pywikibot.Error, 'require even number of replacements.'

pywikibot.exceptions.Error: require even number of replacements.

It is working with just the first search string. Looks like the documentation (link below) is outof date.

https://www.mediawiki.org/wiki/Manual:Pywikibot/replace.py#Example: Gathering articles


Version: core-(2.0)
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:32 AM
bzimport set Reference to bz55689.
bzimport added a subscriber: Unknown Object (????).

arjunaraoc wrote:

Search argument behavior is not as per expectations

$python pwb.py replace.py -search:CNREDDY.JPG -save:cnrtoc.txt "అ" "ఇ"
Traceback (most recent call last):

File "pwb.py", line 104, in <module>
  run_python_file(fn, args)
File "pwb.py", line 49, in run_python_file
  exec compile(source, filename, "exec") in main_mod.__dict__
File "scripts/replace.py", line 696, in <module>
  main()
File "scripts/replace.py", line 549, in main
  raise pywikibot.Error, 'require even number of replacements.'

pywikibot.exceptions.Error: require even number of replacements.

Neighter -search nor -save are valid option for replace.py on core. Please refer the documentation of the code by pwb.py replace -help

Sorry, -search option is quite right but -save option is available on compat version only (yet).

Reopened as feature request

Ninovolador renamed this task from Replace.py errors to Implement -save option on replace.py core.Jun 5 2015, 1:01 AM
Ninovolador set Security to None.
Ninovolador subscribed.

I edited the task description to be more informative.

Change 220771 had a related patch set uploaded (by Maverick):
Implemented -save option on replace.py core

https://gerrit.wikimedia.org/r/220771

To be honest I don't really understand the usage of this option. Why do you want to save a list of pages where you would've replaced something? I mean except for saving the page everything has been done. It has been searched by the generator, the text has been loaded, all replacements has been applied (and depending where @Omegat will add the code) the summary has been generated too. The only missing step would be to save it.

If I understand correctly, if replace.py uses Pywikibot-pagegenerators.py (e.g. XML generator needs to become a generic pagegen: T85334), the -save option is implemented already in listpages.py

I don't think compat's replace -save option has anything to do with XML generator as it (according to the documentation) generates a numbered list (I guess in wikitext). And it only saves pages that would've been written to the wiki so page titles from the generator but which didn't need a change are afaik not saved to the file.

The typical use of -save is first doing an -xml -save , which can take days depending on the computer, and then after a list of pages has been identified doing replacements against the live wiki using pagegenerator -file.

@XZise
Another use could be for semi-automatic bot tasks, especially for complex regular expressions that take time to process. So, you can do the process in two times. First automatically (accept all changes but don't send them online), over the night for example. Second, only work with pages that need changes and accept each one manually.

Also it's pretty useful to get list of pages for manual complex tasks or tracking edits for further fixes

There are four similar parameters in compat, and all of them are required for usability of core. I added them to trunk someday and I use all of them on a regular base. They are -save, -savenew, -saveexc and -saveexcnew. Other option is not to deprecate compat. :-)
These options are really useful and neccessary for everyday spelling correction tasks.

It looks like patch has already been prepared, so what's going on?

@Dvorapa: see review comment on patch set.

@Xqt You mean @XZise's review? I see, but listpages has got just half functionality of replace -save unfortunately

@Dvorapa: yes I meant that. The prepared patch seems not working like in compat yet.

Change 220771 abandoned by Xqt:
Implemented -save option on replace.py core

Reason:
not an appropriate implementation for T144692

https://gerrit.wikimedia.org/r/220771