Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-09

Configuration data in Linux?

13 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am starting out with Lazarus now and decided to do it in Ubuntu 10.04-2, which I installed this week-end.

One thing I don't know how to convert is the way we store program configuration data in our Windows programs. We usually write all these into ini files, which we drop off in the program directory. This is not really the accepted way even in Windows, where you are supposed to store the config in a completely different location than the program folder.

I realize that on Linux it is probably the same and that there exists some agreed system for such storage so that people can find the config files...

So can I get some advice on:
- What is the common way to store config data on Linux? Ini files are probably not used since they are Windowsisms, but is there some other easily used way where one can simply store and retrieve individual values without scanning through a text file?

- Where is the agreed location for such data?

- And in fact where is the agreed location for the programs themselves?

Bo Berglund

Reply by email

Mark Morgan Lloyd
to Bo Berglund
Bo Berglund wrote 20 lines
I am starting out with Lazarus now and decided to do it in Ubuntu 10.04-2, which I installed this week-end. One thing I don't know how to convert is the way we store program configuration data in our Windows programs. We usually write all these into ini files, which we drop off in the program directory. This is not really the accepted way even in Windows, where you are supposed to store the config in a completely different location than the program folder. I realize that on Linux it is probably the same and that there exists some agreed system for such storage so that people can find the config files... So can I get some advice on: - What is the common way to store config data on Linux? Ini files are probably not used since they are Windowsisms, but is there some other easily used way where one can simply store and retrieve individual values without scanning through a text file?

Depends a lot on the app. Things written in Perl or shell might actually use Perl or shell for the configuration file, otherwise the choices are a straight text file, XML or something hacked together using YACC. Me, I use .ini files but give them a .conf extension which is a bit less unexpected.

- Where is the agreed location for such data?

Global settings in /etc or possibly /usr/local/etc (or possibly both, using a symlink). Per-user settings in the user's root directory, with the name preceded by . to limit its visibility. As a detail, when I'm coding this sort of thing I never let the program create a configuration file of its own initiative, it can write to an existing one but creation is a job for an installation script or for the user.

- And in fact where is the agreed location for the programs themselves?

/usr/local/bin or sometimes /usr/local/[app]/bin. In the latter case configuration files might be found in /usr/local/[app]/etc but again it might be worth symlinking to/from /etc.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Schnell
to Bo Berglund: I am starting out with Lazarus now and decided to do it in Ubuntu 10.04-2, which I…

AFAIK the only commonly agreed "standard" is that ini files or directories have the same name as the application prefixed by a "." but no additional ending.

They usually are placed in the home directory of the user if they contain user specific data and in /etc/ if they contain global data (in /etc/ the "." often is omitted).

As (AFAIK) there is no standard about coding the content (other than that it needs to be ASCII characters) ini format is not a bad idea. XML of course is more "modern" and more flexible, as it supports a structured layout.

-Michael

Reply by email

Žilvinas Ledas
to Bo Berglund: I am starting out with Lazarus now and decided to do it in Ubuntu 10.04-2, which I…
Bo Berglund wrote 9 lines
So can I get some advice on: - What is the common way to store config data on Linux? Ini files are probably not used since they are Windowsisms, but is there some other easily used way where one can simply store and retrieve individual values without scanning through a text file? - Where is the agreed location for such data?
In Lazarus you can use:
function GetAppConfigDirUTF8(Global: Boolean): string;
function GetAppConfigFileUTF8(Global: Boolean; SubDir: boolean = false):
string;

to get correct config dir/file name in (various versions of) windows/linux/osx.

Regards
?ilvinas

Reply by email

Sven Barth
to Bo Berglund: I am starting out with Lazarus now and decided to do it in Ubuntu 10.04-2, which I…
Bo Berglund wrote 5 lines
- What is the common way to store config data on Linux? Ini files are probably not used since they are Windowsisms, but is there some other easily used way where one can simply store and retrieve individual values without scanning through a text file?

You can basically use everything you want. If you want your user to edit them manually (using a text editor, etc) you should use a text format like XML, INI, YAML, JSON, etc.

If you don't need that your user plays around with the config you can also use binary formats like a SQLite database (might be overkill of course, but the option is there ^^)

- Where is the agreed location for such data?

As the others already said is the global config in "/etc" or "/usr/local/etc" and the per user configuration in his/her home directory as a hidden file or directory.

You can look at the following functions from SysUtils to make your life easier:

http://www.freepascal.org/docs-html/rtl/sysutils/getappconfigdir.html http://www.freepascal.org/docs-html/rtl/sysutils/getappconfigfile.html

- And in fact where is the agreed location for the programs themselves?

Normally (there are some distros which differ from this standard) the layout is the following:

/etc - the global configuration files (read only by normal users) /home/XYZ/.bla - the per user configuration files
/usr/bin - the application binary
/usr/share/bla - other shared data (like images, sounds, etc) of your application
/usr/docs/bla - the documentation for your application

Please note: "/usr" can also be replaced by "/opt". The difference is this: in "/usr" there should be all applications installed by the distros package manager while "/opt" contains applications that are installed by other means (custom installers, etc).

Please keep in mind that this layout is not necessarily set in stone. Some distros take different approaches to it.

Regards,
Sven

Reply by email

Bo Berglund
to Žilvinas Ledas: In Lazarus you can use: function GetAppConfigDirUTF8(Global: Boolean): string; function…

2010/9/28 ?ilvinas Ledas :

Show quoted text 23 lines
On 2010-09-28 09:24, Bo Berglund wrote: > > So can I get some advice on: > - What is the common way to store config data on Linux? > ? Ini files are probably not used since they are Windowsisms, > ? but is there some other easily used way where one can simply > ? store and retrieve individual values without scanning through > ? a text file? > > - Where is the agreed location for such data? > In Lazarus you can use: function GetAppConfigDirUTF8(Global: Boolean): string; function GetAppConfigFileUTF8(Global: Boolean; SubDir: boolean = false): string; to get correct config dir/file name in (various versions of) windows/linux/osx. Regards ?ilvinas

So to summarize there *is* a convention on the file location depending on if the data are user specific or global. The name of the file is the application name preceded by a period. No extension. But there is no convention regarding the format of this file apart from it being in ASCII only.

So I could create an IniFile class to handle the config and let it have methods for reading/writing private and global config data into a file which it determines by itself depending on its call. Then I would be doing the right thing? I could use the format of windows ini files (which we are accustomed to) and still be OK on Linux...

Methods could be overloaded as:
ReadIniString(section, item, default: string);
ReadIniString(section, item, default: string; global: boolean); where the first version uses the current user's private area and the second one uses the global area. Otherwise they are identical.

Bo Berglund

Reply by email

Graeme Geldenhuys
to Mark Morgan Lloyd: Depends a lot on the app. Things written in Perl or shell might actually use Perl or…
Mark Morgan Lloyd wrote
Global settings in /etc or possibly /usr/local/etc (or possibly both, using a symlink). Per-user settings in the user's root directory, with the name preceded by . to limit its visibility.

freedesktop.org (an organization trying to implement standards for Linux desktop apps) has had a recommendation for storing application config files specific to a user in the $HOME/.config/<appname>/ directory, instead of the $HOME directory. This is why FPC's GetAppConfigDir() defaults to the ~/.config/<app>/ directory.

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

Sven Barth
to Bo Berglund: 2010/9/28 ?ilvinas Ledas : So to summarize there *is* a convention on the file location…
Bo Berglund wrote
So to summarize there *is* a convention on the file location depending on if the data are user specific or global. The name of the file is the application name preceded by a period. No extension.

Not exactly.

E.g.
- FPC uses a .fpc.cfg in your home directory
- Lazarus uses the directory .lazarus by default
- Firefox has its own directory in .mozilla/firefox

You are rather free here. The functions ?ilvinas and I mentioned are returning a filename or a directory name (depending on the called function) in the .config directory (which is also used by other applications as well).

But there is no convention regarding the format of this file apart from it being in ASCII only.

Not even that is a convention. As said you can use what you see fit. You can also use UTF-8 files or binary files (altough the user can't edit the seconds ones if you don't provide the tools for them).

Show quoted text 6 lines
So I could create an IniFile class to handle the config and let it have methods for reading/writing private and global config data into a file which it determines by itself depending on its call. Then I would be doing the right thing? I could use the format of windows ini files (which we are accustomed to) and still be OK on Linux...

But don't forget that the global config in "/etc" is normally read only. You should only create it during the installation phase (which is done by a administrator/root account and thus has the needed rights.

Sidenote: You can use the GetAppConfigDir/File functions on Windows as well and they will return you the directories where an applications should put it's configuration data normally (instead of the program directory).

Regards,
Sven

Reply by email

Bo Berglund
to Mark Morgan Lloyd
Show quoted text 9 lines
From: Mark Morgan Lloyd [mailto:] Sent: Tuesday, September 28, 2010 11:05 AM Bo Berglund wrote: > So I could create an IniFile class Better to use the existing one :-)

If course! I just assumed that since IniFiles on Windows are handled by API calls and "all API specific" things supposedly will not work in FPC I had to make my own wrapper.

Should have know that someone already had....

Bo B

Reply by email

Sven Barth
to Bo Berglund
Bo Berglund wrote 15 lines
> From: Mark Morgan Lloyd [mailto:] > Sent: Tuesday, September 28, 2010 11:05 AM > > Bo Berglund wrote: > >> So I could create an IniFile class > > Better to use the existing one :-) > If course! I just assumed that since IniFiles on Windows are handled by API calls and "all API specific" things supposedly will not work in FPC I had to make my own wrapper. Should have know that someone already had....

INIFiles is implemented completely in Object Pascal. No APIs (apart from the typical Open/Close file ones) are used like Delphi might do (this is also mentioned in the disclaimer in the INIFiles unit).

Regards,
SVen

Reply by email

Mark Morgan Lloyd
to Sven Barth
Sven Barth wrote
INIFiles is implemented completely in Object Pascal. No APIs (apart from the typical Open/Close file ones) are used like Delphi might do (this is also mentioned in the disclaimer in the INIFiles unit).

Which I think is a tacit admission that even though the right way is XML or a database, sometimes there's merit in the simple way :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Thierry Bothorel
to Žilvinas Ledas: In Lazarus you can use: function GetAppConfigDirUTF8(Global: Boolean): string; function…

?ilvinas Ledas a ?crit :

Show quoted text 19 lines
On 2010-09-28 09:24, Bo Berglund wrote: > So can I get some advice on: > - What is the common way to store config data on Linux? > Ini files are probably not used since they are Windowsisms, > but is there some other easily used way where one can simply > store and retrieve individual values without scanning through > a text file? > > - Where is the agreed location for such data? > In Lazarus you can use: function GetAppConfigDirUTF8(Global: Boolean): string; function GetAppConfigFileUTF8(Global: Boolean; SubDir: boolean = false): string; to get correct config dir/file name in (various versions of) windows/linux/osx.

I find GetAppConfigDir strange on Linux :

GetAppConfigDir(True) gives /etc/project1/ for directory, it's OK, but we can assume the config file is UNDER this directory, but GetAppConfigFile(True) gives /etc/project1.cfg , not /etc/project1/project1.cfg
So we can't use this function the same way on Windows XP because GetAppConfigFile(True) gives
C:\D&S\user\Local Settings\Application Data\project1\project1.cfg , not C:\D&S\user\Local Settings\Application Data\project1.cfg

Thierry B.

Reply by email