Bug 161893 - Python script are not saved with .fods format
Summary: Python script are not saved with .fods format
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.6.7.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2024-07-04 02:47 UTC by lpdev
Modified: 2024-07-06 10:43 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
ods_file_with_embedded_python and basic (8.68 KB, application/vnd.oasis.opendocument.spreadsheet)
2024-07-05 16:04 UTC, Werner Tietz
Details
the same file stored as »fods« (21.93 KB, application/vnd.oasis.opendocument.spreadsheet-flat-xml)
2024-07-05 16:06 UTC, Werner Tietz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lpdev 2024-07-04 02:47:50 UTC
Description:
Hi,

I found that Python scripts can't be embedded in flat ODS files in calc at least.
I'm currently using an extension called APSO (https://extensions.libreoffice.org/en/extensions/show/apso-alternative-script-organizer-for-python).

I found that apparently, python scripts, in classical ODS .zip hierarchy, are stored in subfolder Scripts/python according to this website:

https://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html

(see section: Pack your script inside the document : the OpenDocument format)

However when creating a BASIC script, it is properly embedded in the XML file using the token <ooo:library-embedded>

After watching quickly the source code, I think it is a missing feature rather than a bug of Libreoffice calc.

I'm currently running 7.6.7.2 on Linux.

Any help on this?

Thanks!

Steps to Reproduce:
1. Install APSO extension
2. Go to Tools->Maccro->Manage Python scripts
3. Create a new Python module & scripts
4. Try to save your document as (flat) fods format

Actual Results:
Python script vanish from the fods file

Expected Results:
Python script should be embedded inside the fods file.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.6.7.2 (X86_64)
Build ID: 60(Build:2)
CPU threads: 4; OS: Linux 6.9; UI render: default; VCL: gtk3
Locale: en-GB (fr_FR.UTF-8); UI: en-GB
Calc: threaded
Comment 1 Rafael Lima 2024-07-04 18:44:15 UTC
Cross posted here:
https://gitlab.com/jmzambon/apso/-/issues/49

I would say this is an Apso issue.
Comment 2 Werner Tietz 2024-07-04 21:36:44 UTC
(In reply to Rafael Lima from comment #1)
> 
> I would say this is an Apso issue.

I would say this is nonsense!

1. Apso stores the python-code the **regular** way into the __in_memory_file_tree__, nothing else!

2. Apso can neither predict that $User will later save to "fods" format...

3. ...and even less magically deliver a possibly missing specification for "fodf"-xml and|or the missing Implementation in contrast to Basic.

@Regina: Do you know somthing about fodf-specification related to embedding-python-code?
Comment 3 Regina Henschel 2024-07-05 13:10:34 UTC
There is no formal obstacle. The existing element <office:script> (3.1, part 3, ODF 1.3) and its attribute 'script:language' (19.434, part 3, ODF 1.3) would allow to embed Python scripts.

I see a larger problem in the fact, that there is no UI for Python scripts other than to run them. From a security point of view, it should at least be possible to read the source of embedded scripts and to remove an embedded script, without the need to install an extension.
Comment 4 Werner Tietz 2024-07-05 16:02:42 UTC
(In reply to Regina Henschel from comment #3)
> There is no formal obstacle. The existing element <office:script> (3.1, part
> 3, ODF 1.3) and its attribute 'script:language' (19.434, part 3, ODF 1.3)
> would allow to embed Python scripts.

but from my observation, a file with both embedded basic *and* embedded python, stored to **fods** … the basic-code is stored in a node like:
___
 <office:scripts>
  <office:script script:language="ooo:Basic">
   <ooo:libraries xmlns:ooo="http://openoffice.org/2004/office" xmlns:xlink="http://www.w3.org/1999/xlink">
    <ooo:library-embedded ooo:name="Standard">
     <ooo:module ooo:name="Module1">
      <ooo:source-code>REM  *****  BASIC  *****

Sub Main

&apos;does nothing

End Sub

      </ooo:source-code>
     </ooo:module>
    </ooo:library-embedded>
   </ooo:libraries>
  </office:script>
 </office:scripts>

___ 

but as you can see, the python code has disappeared without a trace!
see the attached file as »ods« and as »fods«

(In reply to Regina Henschel from comment #3)
> 
> I see a larger problem in the fact, that there is no UI for Python scripts
> other than to run them. From a security point of view, it should at least be
> possible to read the source of embedded scripts and to remove an embedded
> script, without the need to install an extension.

fair enough! … from my point of view there is also a security-risk to have a ~30Kloc huge project directly in the sourcecode of LO ( … ) which cannot be disabled nor removed!
Comment 5 Werner Tietz 2024-07-05 16:04:52 UTC
Created attachment 195124 [details]
ods_file_with_embedded_python and basic
Comment 6 Werner Tietz 2024-07-05 16:06:37 UTC
Created attachment 195125 [details]
the same file stored as »fods«