How to save initial configuration? (program installation)

J

Jason Zapman II

I've written a program. To install this program, I'm going to need to
initialize some stuff for the users environment, specifically the name/
location of an internal state file.

Currently, I'm hard coding the location of this file, but that's in-
elegant. What I'd like to do is just ask the user, with a suggested
default.

My question is how do I save this answer? It's kind of a chicken-and-
egg problem.

The only solution I've thought of is to write something that's self
modifying, but that's ugly (go in, grep for this variable
initialization, re-write that line with the new value, quit). Is
there a better way to do this? There almost has to be...

If not, are there some 'best practices' on how to do the self-
modification?

Thanks for any help;
Jason
 
K

kyosohma

I've written a program. To install this program, I'm going to need to
initialize some stuff for the users environment, specifically the name/
location of an internal state file.

Currently, I'm hard coding the location of this file, but that's in-
elegant. What I'd like to do is just ask the user, with a suggested
default.

My question is how do I save this answer? It's kind of a chicken-and-
egg problem.

The only solution I've thought of is to write something that's self
modifying, but that's ugly (go in, grep for this variable
initialization, re-write that line with the new value, quit). Is
there a better way to do this? There almost has to be...

If not, are there some 'best practices' on how to do the self-
modification?

Thanks for any help;
Jason

I would think you could pop-up some dialog when the program is first
run to ask where they want the file to be. On the first run though,
you can just have the config file located in the current working
directory with the script file itself. Then just move it or save a new
copy to the new location and delete the original.

Mike
 
J

Jason Zapman II

I would think you could pop-up some dialog when the program is first
run to ask where they want the file to be. On the first run though,
you can just have the config file located in the current working
directory with the script file itself. Then just move it or save a new
copy to the new location and delete the original.

The 'pop-up' is easy. The problem is how does the program know where
it's state file is the SECOND time it is run? I can't stash it in the
state file, since the program won't know where it is if it's not in
the CWD... (unless I'm missing something obvious).
 
S

Steve Holden

I would think you could pop-up some dialog when the program is first
run to ask where they want the file to be. On the first run though,
you can just have the config file located in the current working
directory with the script file itself. Then just move it or save a new
copy to the new location and delete the original.

Mike
Or, better still, leave it in place to act as the defaults for the next
user who wants to start using this package?

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
S

Steve Holden

Jason said:
The 'pop-up' is easy. The problem is how does the program know where
it's state file is the SECOND time it is run? I can't stash it in the
state file, since the program won't know where it is if it's not in
the CWD... (unless I'm missing something obvious).
The traditional choices are the registry for Windows, and the /etc
subtree for the various, almost uncountable, flavors of Unix and
nixalikes. You're right, it's much more difficult per-system than
per-user, since there are so many conventions.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
J

Jason Zapman II

The traditional choices are the registry for Windows, and the /etc
subtree for the various, almost uncountable, flavors of Unix and
nixalikes. You're right, it's much more difficult per-system than
per-user, since there are so many conventions.

I forgot to mention that this is for Unix environments, so the
registry isn't an option, unfortunately (never thought I'd say
that... ;-) ).

Is there anything in the distutils.* stuff that would be useful? This
isn't going to be a python package (it's a standalone program).

--Jason
 
K

kyosohma

I forgot to mention that this is for Unix environments, so the
registry isn't an option, unfortunately (never thought I'd say
that... ;-) ).

Is there anything in the distutils.* stuff that would be useful? This
isn't going to be a python package (it's a standalone program).

--Jason

Well, I don't know what your user file does, but couldn't you create
a .ini type file to hold the user's choice for the other file's
location and save the ini to the current working directory?

Something like this:

<ini file>
usersChosenPath = /usr/Path/to/Config
</ini file>

Kind of redundant, but I would think it would still work.

Mike
 
J

Jason Zapman II

<ini file>
usersChosenPath = /usr/Path/to/Config
</ini file>

Kind of redundant, but I would think it would still work.

Ok... How do I tell the program where the INI file lives?

(What I want is to be able to ask the user

Where do you want the datafile to live? [/usr/local/etc]:

and save that answer somewhere, so future invocations of the program
just *KNOW* the answer.

I'm going to just have to write an 'install' program which just
substitutes the default assignment for the new one in the code...
almost a $PREFIX from ./configure or something like it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top