Skip to content

Commit

Permalink
Simplified implementation, updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Sep 3, 2024
1 parent 17b4f77 commit 5ee1148
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,17 @@ public static void load(String location) throws Exception {
location.substring(0, 8).equalsIgnoreCase("https://")) {
loadFromRemoteURL(location);
} else {
// Assume location is absolute
// Assume location is absolute or a file is in current directory
if (new File(location).exists()) {
load(new FileInputStream(location));
}
// If not absolute, try current directory
else if (new File(new File("."), location).exists()){
load(new File(new File("."), location).getAbsolutePath());
}
// If not absolute or current directory, try user's home
else {
else if(new File(new File(System.getProperty("user.home")), location).exists()){
load(new File(new File(System.getProperty("user.home")), location).getAbsolutePath());
}
else {
throw new RuntimeException("Unable to locate settings file: " + location);
}
}
}

Expand Down
26 changes: 18 additions & 8 deletions docs/source/preferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Preference Settings
When you run Phoebus, you may find that it cannot connect to your control system
because for example the EPICS Channel Access address list is not configured.

To locate available preferences, refer to the complete
To locate available preferences, refer to the complete
:ref:`preference_settings`
or check the source code for files named ``*preferences.properties``,
for example in the ``core-pv`` sources::
Expand All @@ -15,11 +15,11 @@ for example in the ``core-pv`` sources::

# Show a "Description" column that reads xxx.DESC?
show_description=true

# -------------------------
# Package org.phoebus.pv.ca
# -------------------------

# Channel Access address list
addr_list=

Expand Down Expand Up @@ -49,9 +49,19 @@ In addition, Java properties or environment variables can be used like this::

Start Phoebus like this to import the settings from your file::

phoebus.sh -settings <location>

Where <location> can be specified as either absolute path::

phoebus.sh -settings /path/to/settings.ini

Start Phoebus like this to import the settings from a remote URL::
Or as a file name only::

phoebus.sh -settings settings.ini

In this case the current directory is checked for presence of the file, then user's home directory.

<location> may also point to a remote URL::

phoebus.sh -settings http://mysite.com/settings.ini

Expand Down Expand Up @@ -114,7 +124,7 @@ In that file, list the available settings, with explanatory comments::
# Explain what each setting means,
# what values are allowed etc.
my_setting=SomeValue

# Enable some feature, allowed values are true or false
my_other_setting=true

Expand Down Expand Up @@ -149,12 +159,12 @@ If more elaborate settings need to be handled, ``AnnotatedPreferences.initialize
returns a ``PreferencesReader``, or you could directly use that lower level API like this::

package org.phoebus.applications.my_app

import org.phoebus.framework.preferences.PreferencesReader;

# The class that you pass here determines the package name for your preferences
final PreferencesReader prefs = new PreferencesReader(getClass(), "/my_app_preferences.properties");

String pref1 = prefs.get("my_setting");
Boolean pref2 = prefs.getBoolean("my_other_setting");
// .. use getInt, getDouble as needed.
Expand All @@ -163,5 +173,5 @@ returns a ``PreferencesReader``, or you could directly use that lower level API

The ``PreferencesReader`` loads defaults from the property file,
then allows overrides via the ``java.util.prefs.Preferences`` API
that is used when loading a ``settings.ini`` in the installation location
that is used when loading a ``settings.ini`` in the installation location
and by the ``-settings ..`` provided on the command line.

0 comments on commit 5ee1148

Please sign in to comment.