开发者

Dynamic change in Configuration to reflect in user defined Data structures

In my program, I read a "configuration file" and from that I initialize many classes. I need a way so that Dynamic changes in the configuration开发者_运维知识库 file, can successfully update all the classes. What is the best way this can be achived in Python ?

As an example: The /etc/passwd file consists of

Username:Password:User ID:Group ID:User ID Info:Home directory:Shell

My program Initializes User Defined classes for each user based on the input in /etc/passwd file. If one or more attributes in a user entry changes in the file dynamically, how could this be transparently applied to re-initialze the User Defined Classes ?

PS - The actual program is much complex than the above example. So transparently propagating the configuration chnages to User Defined classes is not possible.


You can watch the changes to the file using e.g. pyinotify (Linux) or watchdog (cross-platform). Once the change is detected, you can update your data structures.

Updating username (or other "derived" information stored elsewhere) is better done by storing (and using) not it but some invariants that never change (e.g. UID), getting the "derived" information on demand with relevant API and using it for display purposes only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜