wmllint tutorial

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: wmllint tutorial

Post by Elvish_Hunter »

Anonymissimus wrote:E_H: Perhaps wmlscope or other python tools also have this particular bug ? If so, modifying wmltools.py is probably the way to go.
That's what I thought as well, but at the time of my answer I had no proof of this.
I did more investigations, and I found that the problem is in the getopt.getopt function: under Windows, if an argument ends with a backslash a double quote is appended. This is what modified copies of wmlindent and wmllint print:

Code: Select all

C:\Users\admin>c:\python27\python.exe "C:\Program Files (x86)\Battle for Wesnoth
 1.10.5\data\tools\wmlindent" "C:\Users\admin\Documents\My Games\Wesnoth1.10\dat
a\add-ons\The_Sojournings_of_Grog\"
C:\Users\admin\Documents\My Games\Wesnoth1.10\data\add-ons\The_Sojournings_of_Gr
og"
Options:  []
Arguments:  ['C:\\Users\\admin\\Documents\\My Games\\Wesnoth1.10\\data\\add-ons\
\The_Sojournings_of_Grog"']

C:\Users\admin>c:\python27\python.exe "C:\Program Files (x86)\Battle for Wesnoth
 1.10.5\data\tools\wmlindent" "C:\Users\admin\Documents\My Games\Wesnoth1.10\dat
a\add-ons\The_Sojournings_of_Grog"
C:\Users\admin\Documents\My Games\Wesnoth1.10\data\add-ons\The_Sojournings_of_Gr
og
Options:  []
Arguments:  ['C:\\Users\\admin\\Documents\\My Games\\Wesnoth1.10\\data\\add-ons\
\The_Sojournings_of_Grog']

C:\Users\admin>c:\python27\python.exe "C:\Program Files (x86)\Battle for Wesnoth
 1.10.5\data\tools\wmllint" --dryrun "C:\Program Files (x86)\Battle for Wesnoth
1.10.5\data\core" "C:\Users\admin\Documents\My Games\Wesnoth1.10\data\add-ons\Th
e_Sojournings_of_Grog\"
Argument:  C:\Program Files (x86)\Battle for Wesnoth 1.10.5\data\core
Argument:  C:\Users\admin\Documents\My Games\Wesnoth1.10\data\add-ons\The_Sojour
nings_of_Grog"
At this point, my idea is to dump my previous fix, and instead check if a string terminates with a double quote, and remove said quote if so:

Code: Select all

    for i,arg in enumerate(arguments):
        if arg.endswith('"'):
            arguments[i] = arg[:-1]
It looks like the same fix will need to be applied to all the three main Python tools, inside the if __name__=="__main__" block.
An alternative may be replacing getopt with argparse or optparse, but at the moment I don't have enough knowledge of these two libraries to decide in this direction.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: wmllint tutorial

Post by Elvish_Hunter »

Double post to announce a commit.
I just committed in trunk, [rev]56380[/rev], a bugfix for wmllint, wmlscope and wmlindent. It is the enumerate() block mentioned in my former post. In case that no issue is found, I'll backport the fix to 1.10 as well.
Also, since the 1.4 series has ceased its development a lot of time ago, here there is a fixed copy of wmllint 1.4.
Attachments
wmllint_1.4.zip
(21.82 KiB) Downloaded 156 times
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Iris
Site Administrator
Posts: 6800
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: wmllint tutorial

Post by Iris »

Elvish_Hunter wrote:Also, since the 1.4 series has ceased its development a lot of time ago, here there is a fixed copy of wmllint 1.4.
There is nothing wrong with committing changes to an otherwise unmaintained legacy branch.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: wmllint tutorial

Post by Elvish_Hunter »

shadowmaster wrote:There is nothing wrong with committing changes to an otherwise unmaintained legacy branch.
Whew, finally I found some time to answer.
Of course there is nothing wrong :wink: But I'm unsure if it may be worth the effort for three reasons:
1) I'd have to checkout the 1.4 branch only for one commit, although I should be able to checkout only the tools directory.
2) Even on the non fixed wmllint, there is a simple way to avoid triggering the bug: be sure that every parameter does not end with a backslash.
3) There are only a few people porting from 1.4 and before, and I'm sure that all of them are skilled enough to download the patched version above and paste it in their tools directory, while using their administrator permissions.
Please correct me if I'm wrong. :)
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Groggy_Dice
Inactive Developer
Posts: 165
Joined: February 4th, 2011, 6:19 am
Contact:

Re: wmllint tutorial

Post by Groggy_Dice »

As long as we're talking about wmllint Windows problems, I'll note that my patch #3751 deals with Windows refusing to let a rename overwrite an existing file, which blocks wmllint from reverting, or converting a second time when there is a previous cfg-bak.
Ports:
Prudence (Josh Roby) | By the Sword (monochromatic) | The Eight of Cembulad (Lintana~ & WYRMY)
Resources:
UMC Timeline (Dec) | List of Unported UMC (Dec) | wmllint++ (Feb)
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: wmllint tutorial

Post by Elvish_Hunter »

As I already anticipated some posts above, I just backported the wmllint/scope/indent fix to 1.10, [rev]56436[/rev].
Groggy_Dice wrote:As long as we're talking about wmllint Windows problems, I'll note that my patch #3751 deals with Windows refusing to let a rename overwrite an existing file, which blocks wmllint from reverting, or converting a second time when there is a previous cfg-bak.
Thanks, I'll take a look at it.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Post Reply