Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 04:12
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Configuration file use
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
8-bit


Joined: 03 Apr 2007
Posts: 3365
Location: Oregon

PostPosted: Sun 25 Apr 2010, 21:24    Post subject:  Configuration file use
Subject description: a note on calling when writing a program.
 

When one writes a program that gets configuration from a file, and variables or text are called from the configuration file with the program by a . configfile at the start of the program, all values and text become part of the program and the configfile becomes a blank slate. So one needs to write the values and text back to the configfile upon exiting said program.
As an example, in GTK tips and tricks, there is a program under Benefits of a configuration file in section 5.
If you run it, and check the contents of the /root/.testrc file before exiting, you will find it is blank even though it was created if it did not exist at program start.
When you exit the program though, the .testrc file is written again.
If you removed the part of the last line "> /root/.testrc", you would end up with an empty configuration file.

Has anyone else noticed this?
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7796
Location: qld

PostPosted: Mon 26 Apr 2010, 00:23    Post subject:  

I don't think it becomes a blank slate, I just opened a program that uses one and while running the config file was still there .. pristine.

I have used several different methods to alter the config files though, the one in ziggy's is ok for something very simple... stdout is just overwriting whatever was there before. I have used sed if the config needs altering, actually do this from the gtkdialog formed by a loop in Startmount. Don't ask me how I figured that one out! My head was sore afterward Laughing

Cheers

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
8-bit


Joined: 03 Apr 2007
Posts: 3365
Location: Oregon

PostPosted: Mon 26 Apr 2010, 00:38    Post subject:  

I have and ran the program that is in GTK- tips and tricks in the programming section of the forum under section 5 of page 1.
I ran the program and it created a configuration file. Then, before I exited the program, I tried to open the same configuration file in a text editor.
The file showed with no contents.
But when I exited the program, the settings were written back to the file.
Try it!
Also, how would one read in a configuration file containing variables and text to be used by the program without using ". configfile"?
Wait a minute!
If a program accesses a configuration file in the above way, is the file open while the program is running and closed when the program exits and writes its settings?
Maybe that is why I am coming up with a blank file shown.
I am always trying to learn more.
I will stop learning when I die.
Then again, you never know!
Back to top
View user's profile Send private message 
DMcCunney

Joined: 02 Feb 2009
Posts: 897

PostPosted: Mon 26 Apr 2010, 19:06    Post subject:  

8-bit wrote:
I have and ran the program that is in GTK- tips and tricks in the programming section of the forum under section 5 of page 1.
I ran the program and it created a configuration file. Then, before I exited the program, I tried to open the same configuration file in a text editor.
The file showed with no contents.
But when I exited the program, the settings were written back to the file.
Try it!

It will create a blank config file when you run it. It won't actually put anything in the config file till you exit it. Part of what you are doing the first time you run the program is making the settings to be written to the config file. Until you do that, there's nothing to put in it.

What happens if you run the example program again after you have closed it and written the config file, and then open the config file in an editor while the program is running?

Quote:
Also, how would one read in a configuration file containing variables and text to be used by the program without using ". configfile"?
Wait a minute!
If a program accesses a configuration file in the above way, is the file open while the program is running and closed when the program exits and writes its settings?
Maybe that is why I am coming up with a blank file shown.

More likely, because there's nothing in it to see until you create settings to put there.

The program should be able to open the config file, read in the settings, and then close it. There's probably no reason to keep it open while the program is running. If you make config changes within the program while it's running, it can always open it, write your changes, and close it again.

But no program I know that uses a config file opens it, reads in the settings and takes them out of the config file in the process, leaving it blank, then writes them all back when you close the program. Whatever for? Once created, the config file is usually static, and only needs to be opened and read when the program is run so it knows how to set itself up.

Some programs will use a config file if one exists, but will use built-in defaults if it doesn't - the config file is only there to let you change the default behavior.
______
Dennis
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5016
Location: Arizona, U.S.A.

PostPosted: Mon 26 Apr 2010, 19:36    Post subject:  

No matter what kind of code the executable file has in it, it should never wipe itself out!
In a file I just put:
Code:
#!/bin/sh
echo '####'
A=AAA

I ran the file as:
# . z0-test
# echo `z0-test`
# AA= `z0-test`
# echo $A
AAA
All of the executions of the file worked as expected, and it never wiped itself out!
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3365
Location: Oregon

PostPosted: Mon 26 Apr 2010, 19:53    Post subject:  

When I run the Benefits of a configuration file, I am able to :
1st it makes /root/.testrc if it does not exist.
It writes the first configuration file.
If no changes are requested, it exits and writes to root/.testrc
At this point the file, root/.testrc is populated (has contents).

So I run the program again.
While the program is running and no changes are yet made, I open the /root/.testrc file in an editor.
It has NO contents shown in the text editor.
I exit the program and check it again.
The root/.testrc file now has contents.

As I said before. Cut and paste the file from GTK- tips and tricks into an editor, save it, make it executable, and run the darn thing.

Maybe you can shed some light on it.

And for sunburnt, it is not the file you use to modify the configuration file that goes blank, it is the configuration file itself.

Again, try it.

I have tried this in Puppy 431, 432, lupu-5, and 421.
Back to top
View user's profile Send private message 
DMcCunney

Joined: 02 Feb 2009
Posts: 897

PostPosted: Mon 26 Apr 2010, 20:42    Post subject:  

8-bit wrote:
As I said before. Cut and paste the file from GTK- tips and tricks into an editor, save it, make it executable, and run the darn thing.

Maybe you can shed some light on it.

What file? There are 24 pages of posts in that thread. Which one do you mean?
______
Dennis
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5016
Location: Arizona, U.S.A.

PostPosted: Mon 26 Apr 2010, 20:50    Post subject:  

The file I ran is the config. file you speak of, there is no other file I spoke of...
The file I showed has a command: "echo ###" and a variable assignment: "A=AAA" ( config.).
Running or reading a file should never wipe it out! Sourced ". (file)" or just normally "(file)".
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3365
Location: Oregon

PostPosted: Mon 26 Apr 2010, 22:43    Post subject:  

The file I am talking about uses a seperate file to save configuration and can be found here.
Look under section 5 of that first post for the program.
If you still cannot find the file, I am attaching it.
At first run, if its configuration file /root/.testrc does not exist, it will be created.
After exiting benconf by the Ok button, you can check that configuration file.
So, now you know it is populated.
Now run benconf again and while it is running, check the contents of the /root/.testrc file.

I hope that was clear enough.
benconf.tar.gz
Description  Extract to /root and run it. And be sure to try making a few changes as to checkboxes, dropdown seleection, and default text.
gz

 Download 
Filename  benconf.tar.gz 
Filesize  687 Bytes 
Downloaded  283 Time(s) 
Back to top
View user's profile Send private message 
DMcCunney

Joined: 02 Feb 2009
Posts: 897

PostPosted: Mon 26 Apr 2010, 23:02    Post subject:  

8-bit wrote:
The file I am talking about uses a seperate file to save configuration and can be found here.
Look under section 5 of that first post for the program.

Check the first section of what you have carefully.

Line 3 should create a .testrc file with the following content:
Code:
COMBOBOX="item 3"
ENTRY="default text"
RADIOBUTTON1="false"
RADIOBUTTON2="true"

Line 3 should look like this:
Code:
[ ! -s $HOME/.testrc ] && echo -e -n 'COMBOBOX="item 3"\nENTRY="default text"\nRADIOBUTTON1="false"\nRADIOBUTTON2="true"\n' > $HOME/.testrc

and be all on one line

I have a sneaking suspicion that you have a line break in there, and the
Code:
> $HOME/.testrc

segment is on a line by itself. That will cause it to be executed as a separate command, and create an empty .testrc file, without putting the default values into it. (That would produce the behavior you see.)

( "> foo" is a handy way to create a blank file called foo, or truncate it to zero length if it exists.)
______
Dennis
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3365
Location: Oregon

PostPosted: Mon 26 Apr 2010, 23:10    Post subject:  

Look two posts up in this thread. I was a little late getting the file attached.
Also, the forum for some reason kicked part of the line that writes the first configuration file to the next line.
It was supposed to be all one line.
Try it again with the one I attached.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1142s ][ Queries: 13 (0.0374s) ][ GZIP on ]