bugGNU Octave - Bugs: bug #48221, prefdir should not be a private...

 
 

bug #48221: prefdir should not be a private function

Submitter:  Guillaume <gyom>
Submitted:  Tue 14 Jun 2016 09:22:16 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 15 Jun 2016 04:07:48 PM UTC, comment #6: 

I fixed this on the default branch with the following simpler change:

http://hg.savannah.gnu.org/hgweb/octave/rev/e0952881e051

You can now call prefdir, and passing any argument to it will create the directory if it doesn't exist (tested with a bogus HOME variable).

This in no way guarantees that all preferences or settings related to Octave are actually stored in said directory, or that it can be safely removed to clean up all Octave preferences. That would be a separate, much larger undertaking.

Mike Miller <mtmiller>
Group Member
Wed 15 Jun 2016 09:37:54 AM UTC, comment #5: 

Sorry, there was a typo - new version below:


## -*- texinfo -*-
## @deftypefn {} {} prefdir
## @deftypefnx {} {@var{D} =} prefdir
## @deftypefnx {} {@var{D} =} prefdir (1)
## Return the name of the directory containing Octave's preferences.
##
## @var{D} is a string containing the name of the directory containing
## Octave's preferences. The directory may or may not exist.
##
## If 1 is provided as an input, the preference directory is created if
## it does not yet exist.
##
## @seealso{addpref, getpref, setpref, ispref, rmpref}
## @end deftypefn

function retval = prefdir (varargin)

if (ispc ())
  d = fullfile ('AppData', 'Roaming', 'Octave'); % or Documents\Octave
else
  d = '.octave';
endif

retval = fullfile (get_home_directory (), d, version ());

if (nargin ~= 0)
  if ((isnumeric (varargin{1}) || islogical (varargin{1})) && ...
     numel (varargin{1}) == 1)
    if (logical (varargin{1}) && ~exist (retval, 'dir'))
      mkdir (retval);
    endif
  else
    error ('Input must be 1 to create the preference directory.');
  endif
endif

endfunction


Guillaume <gyom>
Wed 15 Jun 2016 09:25:13 AM UTC, comment #4: 

Thanks for the feedbacks. It would be great to move prefdir.m from octave/scripts/prefs/private/ to octave/scripts/prefs/.

I still think it would also be an improvement to let the preference directory have its own folder (eg ~/.octave/ instead of ~/) in case, as Mike mentions, we end up storing more than a single file (Matlab seems to store many files there).

It is also possible that, on Windows, a file or folder starting with '.' is not allowed or recommended. I made a change to my proposed code - I'm just not sure what get_home_directory () returns on this platform.


## -*- texinfo -*-
## @deftypefn {} {} prefdir
## @deftypefnx {} {@var{D} =} prefdir
## @deftypefnx {} {@var{D} =} prefdir (1)
## Return the name of the directory containing Octave's preferences.
##
## @var{D} is a string containing the name of the directory containing
## Octave's preferences. The directory may or may not exist.
##
## If 1 is provided as an input, the preference directory is created if
## it does not yet exist.
##
## @seealso{addpref, getpref, setpref, ispref, rmpref}
## @end deftypefn

function retval = prefdir (varargin)

if ispc
  d = fullfile ('AppData', 'Roaming', 'Octave'); % or Documents\Octave
else
  d = '.octave';
endif

retval = fullfile (get_home_directory (), d, version ());

if (nargin ~= 0)
  if (isnumeric (varargin{1}) || islogical (varargin{1})) && ...
     numel (varargin{1}) == 1 && logical (varargin{1}))
    if ~exist (retval, 'dir')
      mkdir (retval);
    endif
  else
    error ('Input must be 1 to create the preference directory.');
  endif
endif

endfunction


Guillaume <gyom>
Tue 14 Jun 2016 04:29:20 PM UTC, comment #3: 

Yes, I am completely ignoring what the preferences directory or file actually are, and just thinking about supporting the syntax to create the directory. Granted in most cases the user's home directory will already exist, so it's a no-op, but maybe not all cases.

And maybe some day we will have a configuration directory that combines all settings for Octave, including installed packages, startup commands, prefs, and what are currently GUI preferences (using QSettings). There are other open bug reports about these things though.

Mike Miller <mtmiller>
Group Member
Tue 14 Jun 2016 04:08:12 PM UTC, comment #2: 

At some point Matlab may have moved this around.  It is certainly dead simple to move it up from the private directory into the 'prefs' directory where it will be visible.

I don't know that we need to bother to support prefdir(1) syntax.  Octave automatically creates the file '.octave_prefs' as necessary.  Of course, we could always just  document that you can call it that way.

Also, Octave supports preferences, but we support them in a UNIX way which is to have an rc file in the user's home directory.  We don't use a separate folder, ~/.octave/, to hold that rc file.

Rik <rik5>
Group administrator
Tue 14 Jun 2016 03:56:11 PM UTC, comment #1: 

The linked page says "prefdir(1)" should create the directory. Does "prefdir(0)" also create it? Or "prefdir([])"?

Mike Miller <mtmiller>
Group Member
Tue 14 Jun 2016 09:22:16 AM UTC, original submission:  

At the moment, prefdir is implemented in scripts/prefs/private/prefdir.m and is therefore not accessible from the command line while it should be for Matlab compatibility, see:

http://www.mathworks.com/help/matlab/ref/prefdir.html

Before I noticed this file in Octave, I also implemented my own version that might provide a better compatibility with Matlab:


## -*- texinfo -*-
## @deftypefn {} {} prefdir
## @deftypefnx {} {@var{D} =} prefdir
## @deftypefnx {} {@var{D} =} prefdir (1)
## Return the name of the directory containing Octave's preferences.
##
## @var{D} is a string containing the name of the directory containing
## Octave's preferences. The directory may or may not exist.
##
## If 1 is provided as an input, the preference directory is created if
## it does not yet exist.
##
## @seealso{addpref, getpref, setpref, ispref, rmpref}
## @end deftypefn

function retval = prefdir (varargin)

retval = fullfile (get_home_directory (), '.octave', version ());

if (nargin ~= 0 && ~exist (retval, 'dir'))
  mkdir (retval);
endif

endfunction


Guillaume <gyom>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-06-15 mtmiller StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2016-06-14 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code