Bug 128463 - New undocumented and faulty Python scripts
Summary: New undocumented and faulty Python scripts
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
6.2.8.2 release
Hardware: All All
: medium trivial
Assignee: Kevin Suo
URL:
Whiteboard: target:7.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-29 14:58 UTC by LibreOfficiant
Modified: 2021-08-14 05:50 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
updated SetCellColor.py (2.33 KB, text/x-python)
2020-12-31 03:31 UTC, Kevin Suo
Details
updated NamedRanges.py (6.18 KB, text/x-python)
2020-12-31 03:35 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description LibreOfficiant 2019-10-29 14:58:16 UTC
Description:
With the advent of 6.2, two new Python scripts examples have been bundled with LibreOffice inside <install>/share/scripts/python folder.
They lack: 
- Licensing header - SetCellColor.py
- parcel-descriptor.xml translation file - SetCellColor.py
They malfunction.
They are not documented in local/online help.


Steps to Reproduce:
1. Open <install>/Share/scripts/python folder
2. Check folder content

1. Select Tools-Macros-Run macro..
2. Scroll the list and notice NamedRanges.py & SetCellColor.py are lacking a description within 'macro selector' dialog.

Actual Results:
With the advent of 6.2, two new Python scripts examples have been bundled with LibreOffice inside <install>/share/scripts/python folder.
They lack: 
- Licensing header - SetCellColor.py
- parcel-descriptor.xml translation file - SetCellColor.py
They are not documented in local/online help.

Both scripts should check for a valid active Calc document before processing: SetCellColor.py is raising an exception!


Expected Results:
There should be a parcel-descriptor file for SetCellColor.py
SetCellColor.py should have a license header



Both files should be documented in local/online help.


Reproducible: Always


User Profile Reset: No



Additional Info:
Categorized bug component is 'Documentation as I could not identify the appropriate one.
Comment 2 Kevin Suo 2020-10-26 01:19:48 UTC
I have already made some improvements to the example python scripts, in the following commit:

commit 5fb0e0f68bc9d37d43e0782b903919630852904c
Improve example python code in scripting.
* Modified the code to be more pythonic.
* If "len(theString) == 0", then "not theString" evaluates to True.
* "theString[0].isupper()" and "theString[1].isupper()" can be combined.
* Remove unused imported string module
* Wrap long lines
* run autopep8 to prettify
* ...

Also, SetCellColor.py is updated to actually do something (instead of showing an exception), in the following patch in gerrit awaiting for review:
https://gerrit.libreoffice.org/c/core/+/104720

By the way, what is a "parcel-descriptor file" and how can I create it?
Comment 3 Alain Romedenne 2020-10-28 15:35:40 UTC
Hi Kevin,

Parcel descriptor files are .xml files that exhibit translatable script/macro descriptions when using " Tools - Macros - Run macro… " menu.

You can find such examples in beanshell, java and javascript folders inside <INSTALLPATH>/Share/Scripts directory.

Unfortunately Python script descriptions do not show up in my tests. This is most probably inherited from OOo. Providing this is fixed, I would happily document Python scripts examples in local/online help.
Comment 4 Alain Romedenne 2020-10-28 16:13:38 UTC
About parcel descriptor files, see also:
https://wiki.openoffice.org/w/images/0/0a/DevelopersGuide_OOo3.1.0_18Scripting.odt
Comment 5 sdc.blanco 2020-11-20 13:57:40 UTC
(In reply to Kevin Suo from comment #2)
> showing an exception), in the following patch in gerrit awaiting for review:
> https://gerrit.libreoffice.org/c/core/+/104720
You need to add reviewers in gerrit.
Comment 6 Kevin Suo 2020-11-20 17:31:53 UTC
(In reply to sdc.blanco from comment #5)
Yes I am aware of this. Currently we have much more important bugs to test - so this minor issue should be put behind and will come to this in a later day.
Comment 7 Kevin Suo 2020-11-22 13:08:29 UTC
Alain Romedenne: I don't think the parcel descriptor files works with python macros. Could you try?
Comment 8 Alain Romedenne 2020-11-22 13:22:12 UTC
(In reply to Kevin Suo from comment #7)
> Alain Romedenne: I don't think the parcel descriptor files works with python
> macros. Could you try?

I have tried already. Thanks for having tried your side as well
Comment 9 Alain Romedenne 2020-11-22 13:27:52 UTC
Basic and Python scripts deserve an enhancement request to permit macro descriptions in the 'Run macro' dialog. You can skip that point …
Comment 10 Kevin Suo 2020-12-31 03:31:44 UTC
Created attachment 168585 [details]
updated SetCellColor.py
Comment 11 Kevin Suo 2020-12-31 03:35:08 UTC
Created attachment 168586 [details]
updated NamedRanges.py

These are the updated python examples which are also on gerrit for review. 

Others who do not have access to gerrit can also help to test. To test, place these two files in: <your_home_dir/.config/libreoffice/4/user/Scripts/python 
and then run from the Run Macros dialog > My Macros.
Comment 12 Commit Notification 2020-12-31 07:46:59 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/97d51446052acb5465c7ebe0ba3ce4d4570d25b0

tdf#128463: Make SetCellColor python example actually do sth

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Commit Notification 2020-12-31 07:48:10 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/8c9cc54bd7b6f3ba723d7a42ccc6a5372a80f970

tdf#128463: Rewrite NamedRanges.py to make it work when run from UI

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Kevin Suo 2020-12-31 08:07:39 UTC
The script is now updated on master. If you have time, you may update it on local/online help.
Comment 15 How can I remove my account? 2020-12-31 11:08:13 UTC
Nobody claimed the script was supposed to be usable except for a very specific demo purpose, from what is now https://github.com/CollaboraOnline/online/blob/master/loleaflet/html/framed.html (but back then was part of what used to be called "LibreOffice Online").

I am a bit sad that nobody bothered to ask the person who committed the script (me) what its purpose is when filing this bug. Now the script presumably no longer is usable from that demo thing, but oh well, whatever.
Comment 16 How can I remove my account? 2020-12-31 11:12:42 UTC
As for the "Both files should be documented" claim I disagree. They were not documented on purpose because they are not supposed to be usable in general. Doesn't the word "examples" give a strong hint that they are not supposed to be some bloody documented stable API etc?
Comment 17 How can I remove my account? 2020-12-31 11:13:40 UTC
Probably it would be best now to just remove these two scripts.
Comment 18 How can I remove my account? 2020-12-31 11:23:48 UTC
I wonder why the Apache part ("This file incorporates work covered by the following license notice")  was added to the license blurb of NamedRanges.py in 8c9cc54bd7b6f3ba723d7a42ccc6a5372a80f970 ? As far as I recall, I created the script from scratch in e32b4c8a079e4b51b1028d2467b872ff5b8cdd3a . But if you Kevin have better information, that the script is based on something from OO.o, please say so.
Comment 19 Commit Notification 2021-01-01 06:39:00 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6b57cfb71a9546c32c03848751181b2db4f47176

tdf#128463: Revert the change to license information

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 flywire 2021-08-14 05:33:23 UTC
(In reply to Tor Lillqvist from comment #15)
> Nobody claimed the script was supposed to be usable

Pretty well a guarantee for anything to do with python. Working examples are much better demonstrations.
Comment 21 flywire 2021-08-14 05:50:25 UTC
I was confused why supplied examples didn't work. Examples now work well demonstrating functionality much better providing a framework for user experimentation. Thank you for the community effort.