Saving/reloading report options

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving/reloading report options

Patrick Gerlier

I am studying code for saving report dialog options into report_options.xml and the way they are reloaded by method load_previous_values().

The report dialog presents a field for the output report file containing the full path. This path is extracted  from the dialog with ….target_fileentry.get_full_path(0) and store unaltered into output of  an instance of OptionList. When saving the options,  the XML element <output> is built with os.path.basename(option_list.get_output()), in effect erasing the directory, leaving only a filename in the XML.

(gramps/gen/plug/report/_options.py; class OptionListCollection method write_module_common)

Upon reload, the OptionParser instance uses self.option_list.set_output(<<the string from the XML>>). When this filename is put back into target_fileentry with ….target_fileentry.set_filename(option_list.get_output()), the set_filename() method sees a relative path (does not start with a /). The method will then make an absolute path by using the current directory.

(gramps/gen/plug/report/_options.py; class OptionParser method startElement)

Under frequent circumstances, the current directory is not the directory in the original path. Consequently, the roundtrip does not preserve the file designation.

What was the rationale behind this design decision (extracting the basename from the full path)?

Note that this behaviour is invisible in standard Gramps usage because reloading occurs only once when the dialog is opened. I am trying to implement a selective save/reload module-specific mechanism to quickly configure the report dialog for repetitive reports. I'm trying to do this with minimal patches using existing methods as much as possible.

I did not pay enough attention to this mishap (bug?) and files got overwritten with wrong content (it presently does not matter as I am in the test phase but I want a reliable and safe feature).

Patrick



_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving/reloading report options

prculley
I cannot say why it was done this way.  The individual reports save only the base filename as you noted.  The directory name used is supposed to be the 'report-directory' from the [paths] section of gramps.ini, which is set each time you use a report.  So if you are in the habit of storing reports in the same place all the time, this works great.  However if you want to store reports in specific directories, potentially different for each report, this doesn't work at all.

Paul C.

On Sat, Apr 18, 2020 at 10:16 AM Patrick Gerlier <[hidden email]> wrote:

I am studying code for saving report dialog options into report_options.xml and the way they are reloaded by method load_previous_values().

The report dialog presents a field for the output report file containing the full path. This path is extracted  from the dialog with ….target_fileentry.get_full_path(0) and store unaltered into output of  an instance of OptionList. When saving the options,  the XML element <output> is built with os.path.basename(option_list.get_output()), in effect erasing the directory, leaving only a filename in the XML.

(gramps/gen/plug/report/_options.py; class OptionListCollection method write_module_common)

Upon reload, the OptionParser instance uses self.option_list.set_output(<<the string from the XML>>). When this filename is put back into target_fileentry with ….target_fileentry.set_filename(option_list.get_output()), the set_filename() method sees a relative path (does not start with a /). The method will then make an absolute path by using the current directory.

(gramps/gen/plug/report/_options.py; class OptionParser method startElement)

Under frequent circumstances, the current directory is not the directory in the original path. Consequently, the roundtrip does not preserve the file designation.

What was the rationale behind this design decision (extracting the basename from the full path)?

Note that this behaviour is invisible in standard Gramps usage because reloading occurs only once when the dialog is opened. I am trying to implement a selective save/reload module-specific mechanism to quickly configure the report dialog for repetitive reports. I'm trying to do this with minimal patches using existing methods as much as possible.

I did not pay enough attention to this mishap (bug?) and files got overwritten with wrong content (it presently does not matter as I am in the test phase but I want a reliable and safe feature).

Patrick

_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel


_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving/reloading report options

Patrick Gerlier

Thanks Paul for your answer, but the situation is a bit more complex.

Patrick G.

Le 18/04/2020 à 22:54, Paul Culley a écrit :
I cannot say why it was done this way.  The individual reports save only the base filename as you noted.  The directory name used is supposed to be the 'report-directory' from the [paths] section of gramps.ini, which is set each time you use a report.
Configuration has a parameter 'paths.report-directory' which is initially set to USER_HOME. It can be changed by method ReportDialog.set_default_directory(self, value). This is done in ReportDialog.parse_target_frame(self) when the OK button is pressed, hence just before generating the report.
 So if you are in the habit of storing reports in the same place all the time, this works great.

Yes and no. In "standard" usage (i.e. out-of-the-box Gramps), the report file name is created when the report dialog is opened. The name is made of 'paths.report-directory' and a generic name derived from the report category. This is an absolute path and FileEntry.set_filename(self, path) takes it without modification.

In my present experimentation, I reload options AFTER the dialog has been initialised and displayed. I thus change options dynamically in code. I take the saved <output name=…> to stuff it where it "belongs" with a FileEntry.set_filename(…). But class FileEntry is a general purpose class which can be used anywhere in Gramps, not only when configuring reports. Consequently when faced with a relative path, there is no reason to use 'paths.report-directory' rather than another one.

For my tests, I have the release version of Gramps installed in its "production" location (as determined by the distro) and the experimental Gramps in a user directory. This experimental Gramps is launched a bit specially so that Python can find all the needed code files and libraries. This means the working directory is set on this experimental directory.

When FileEntry converts from relative to absolute paths, it does use any of the 'paths.xxx' parameters. Instead, it takes the current working directory which is not likely to be related to Gramps document directories.

I'll make myself an absolute path before sending back <output> to the dialog.

However if you want to store reports in specific directories, potentially different for each report, this doesn't work at all.
Thank you for drawing my attention on 'paths.report-directory'.

Paul C.

On Sat, Apr 18, 2020 at 10:16 AM Patrick Gerlier <[hidden email]> wrote:

I am studying code for saving report dialog options into report_options.xml and the way they are reloaded by method load_previous_values().

The report dialog presents a field for the output report file containing the full path. This path is extracted  from the dialog with ….target_fileentry.get_full_path(0) and store unaltered into output of  an instance of OptionList. When saving the options,  the XML element <output> is built with os.path.basename(option_list.get_output()), in effect erasing the directory, leaving only a filename in the XML.

(gramps/gen/plug/report/_options.py; class OptionListCollection method write_module_common)

Upon reload, the OptionParser instance uses self.option_list.set_output(<<the string from the XML>>). When this filename is put back into target_fileentry with ….target_fileentry.set_filename(option_list.get_output()), the set_filename() method sees a relative path (does not start with a /). The method will then make an absolute path by using the current directory.

(gramps/gen/plug/report/_options.py; class OptionParser method startElement)

Under frequent circumstances, the current directory is not the directory in the original path. Consequently, the roundtrip does not preserve the file designation.

What was the rationale behind this design decision (extracting the basename from the full path)?

Note that this behaviour is invisible in standard Gramps usage because reloading occurs only once when the dialog is opened. I am trying to implement a selective save/reload module-specific mechanism to quickly configure the report dialog for repetitive reports. I'm trying to do this with minimal patches using existing methods as much as possible.

I did not pay enough attention to this mishap (bug?) and files got overwritten with wrong content (it presently does not matter as I am in the test phase but I want a reliable and safe feature).

Patrick

_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel


_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel