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

Details

Reference
bz55689

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:32 AM
bzimport added a project: Pywikibot-Scripts.
bzimport set Reference to bz55689.
bzimport added a subscriber: Unknown Object (????).
bzimport created this task.Oct 14 2013, 5:58 AM

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.

Xqt added a comment.Oct 14 2013, 1:08 PM

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

Xqt added a comment.Oct 14 2013, 1:12 PM

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

Xqt added a comment.Oct 14 2013, 1:14 PM

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 added a subscriber: Ninovolador.

I edited the task description to be more informative.

Omegat added a subscriber: Omegat.Jun 22 2015, 8:25 AM

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

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

Omegat claimed this task.Jun 25 2015, 4:41 PM
XZise added a subscriber: XZise.Jun 25 2015, 4:55 PM

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.

jayvdb added a comment.EditedJun 25 2015, 9:53 PM

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

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 26 2015, 4:33 PM
binbot added a subscriber: binbot.Jan 24 2016, 4:48 PM

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.

Dvorapa added a comment.EditedFeb 14 2016, 9:44 AM

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

Xqt added a comment.Feb 14 2016, 10:43 PM

@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

Xqt added a comment.Feb 15 2016, 12:26 PM

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

4nn1l2 added a subscriber: 4nn1l2.Aug 12 2016, 7:08 PM

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