How to tell the type that Config uses?

I’m fairly new to wxPython, and have taken on my first project :slight_smile: Actually, it’s modifying some existing code.

This code was originally written for Windows, and I’m working on a Linux system. It uses Config module to store some basic information, including a bit of sensitive info.

On Linux, this means it creates a plain text file using the default umask of the user.

So I’m trying to figure out: How can I tell the ‘type’ of Config so if it’s a FileConfig, I can set the umask? The other files it generates are all fine to be readable by others, even encouraged. It’s just the Config file I need to lock down.

Or perhaps, how do I tell the ‘type’ of system, so I can switch on type?

I’m trying not to modify existing behaviour of using the system specific config type if I can help it.

This doesn’t sound like a wxPython question, rather a question for the config module usage or system platform determination in general. Try the python IRC chat room on freenode.net

···

On Wednesday, February 10, 2016 at 5:15:54 PM UTC-8, Jason Ahrens wrote:

I’m fairly new to wxPython, and have taken on my first project :slight_smile: Actually, it’s modifying some existing code.

This code was originally written for Windows, and I’m working on a Linux system. It uses Config module to store some basic information, including a bit of sensitive info.

On Linux, this means it creates a plain text file using the default umask of the user.

So I’m trying to figure out: How can I tell the ‘type’ of Config so if it’s a FileConfig, I can set the umask? The other files it generates are all fine to be readable by others, even encouraged. It’s just the Config file I need to lock down.

Or perhaps, how do I tell the ‘type’ of system, so I can switch on type?

I’m trying not to modify existing behaviour of using the system specific config type if I can help it.

Nathan McCorkle wrote:

This doesn't sound like a wxPython question, rather a question for the
config module usage

The Config module which is a part of wxPython, that is.

···

--
James Scholes
http://twitter.com/JamesScholes

Correct, this is regarding wx.Config module: http://wxpython.org/Phoenix/docs/html/ConfigBase.html (and associated wx.FileConfig)

The problem I’m having is: wx.Config ends up being a layer over the actual config type. On Windows it’s a “wx.RegConfig” (which I’ve been unable to find any direct documentation for) and on other platforms it’s a wx.FileConfig. However type(configObj) just returns it’s type ‘wx._misc.Config’ so I can’t actually tell what its behaviour is going to be. None of the wx.FileConfig specific methods are exposed.

I need to detect if wx.Config is using wx.FileConfig as the underlying config module or not so I can do necessary file system work appropriately given the different data storage medium.

···

On Thursday, February 11, 2016 at 3:34:12 AM UTC-8, James Scholes wrote:

Nathan McCorkle wrote:

This doesn’t sound like a wxPython question, rather a question for the

config module usage

The Config module which is a part of wxPython, that is.


James Scholes

http://twitter.com/JamesScholes

Take a look at the source code: https://github.com/wxWidgets/wxPython/blob/14476d72d92c44624d5754c4f1fac2e8d7bc30da/src/gtk/_misc.py

On Linux, wx.Config will use wx.FileConfig. I can’t even find RegConfig in the source code, I guess RegConfig is the same a the Windows registry.

class Config(ConfigBase):
“”"
This ConfigBase-derived class will use the registry on Windows,
and will be a wx.FileConfig on other platforms.
“”"

class FileConfig(ConfigBase):
“”“This config class will use a file for storage on all platforms.”“”
Then the base class:

class ConfigBase(object):
“”"
wx.ConfigBase class defines the basic interface of all config
classes. It can not be used by itself (it is an abstract base class)
and you will always use one of its derivations: wx.Config or
wx.FileConfig.
wx.ConfigBase organizes the items in a tree-like structure, modeled
after the Unix/Dos filesystem. There are groups that act like
directories and entries, key/value pairs that act like files. There
is always one current group given by the current path. As in the file
system case, to specify a key in the config class you must use a path
to it. Config classes also support the notion of the current group,
which makes it possible to use relative paths.
Keys are pairs “key_name = value” where value may be of string,
integer floating point or boolean, you can not store binary data
without first encoding it as a string. For performance reasons items
should be kept small, no more than a couple kilobytes.
“”"Regards,

Austin

···

On Saturday, February 13, 2016 at 2:38:10 AM UTC+1, Jason Ahrens wrote:

Correct, this is regarding wx.Config module: http://wxpython.org/Phoenix/docs/html/ConfigBase.html (and associated wx.FileConfig)

The problem I’m having is: wx.Config ends up being a layer over the actual config type. On Windows it’s a “wx.RegConfig” (which I’ve been unable to find any direct documentation for) and on other platforms it’s a wx.FileConfig. However type(configObj) just returns it’s type ‘wx._misc.Config’ so I can’t actually tell what its behaviour is going to be. None of the wx.FileConfig specific methods are exposed.

I need to detect if wx.Config is using wx.FileConfig as the underlying config module or not so I can do necessary file system work appropriately given the different data storage medium.

On Thursday, February 11, 2016 at 3:34:12 AM UTC-8, James Scholes wrote:

Nathan McCorkle wrote:

This doesn’t sound like a wxPython question, rather a question for the

config module usage

The Config module which is a part of wxPython, that is.


James Scholes

http://twitter.com/JamesScholes

Just use is instance:
In [11]: c = wx.Config("Test")

In [12]: isinstance(c, wx.Config)
Out[12]: True

In [13]: isinstance(c, wx.FileConfig)
Out[13]: False

···

On 11/02/2016 01:05, Jason Ahrens wrote:

I'm fairly new to wxPython, and have taken on my first project :slight_smile:
Actually, it's modifying some existing code.

This code was originally written for Windows, and I'm working on a Linux
system. It uses Config module to store some basic information, including
a bit of sensitive info.

On Linux, this means it creates a plain text file using the default
umask of the user.

So I'm trying to figure out: How can I tell the 'type' of Config so if
it's a FileConfig, I can set the umask? The other files it generates are
all fine to be readable by others, even encouraged. It's just the Config
file I need to lock down.

Or perhaps, how do I tell the 'type' of system, so I can switch on type?

I'm trying not to modify existing behaviour of using the system specific
config type if I can help it.

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
<mailto:wxpython-users+unsubscribe@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

Yes, that’s essentially what I posted above too, however I’m trying to find programatically what the result of this internal check/creation is.

On a Linux system, for example, you can’t tell via isinstance that it chose wx.FileConfig, because the wx.Config object doesn’t transform:

snowleopard% python2

Python 2.7.11 (default, Dec 6 2015, 15:43:46)

[GCC 5.2.0] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

import wx

app = wx.App(False)

config = wx.Config(“MyApp”)

isinstance(config, wx.FileConfig)

False

Unfortunately I start to get lost while trying to read the code to figure it out.

https://github.com/wxWidgets/wxPython/blob/14476d72d92c44624d5754c4f1fac2e8d7bc30da/src/gtk/_misc.py#L3486 is where the class Config is defined with the constructor ultimately calling misc.Config_swiginit(self,misc.new_Config(*args, **kwargs)), however misc is not python, but the CPP swig object.

Further to this, it looks like (as you’d expect of the complied portion) the decision is not ‘made’ during runtime, but at compile. (there’s both a gtk/_misc_wrap.cpp and msw/_misc_wrap.cpp that contain the code for new_Config). However so far reading through the C++ code, I’ve been unable to identify something that “flags” the underlying mechanism wx.Config is using.

Sounds like this is a lot more complicated than I thought it would be.

If this actually can’t be accomplished (which is starting to look like the case) a hacky way I could accomplish this would be (this is untested… I’ll try it out tomorrow when I get some more time) and assumes I’ll get control back from MainLoop():

import wx

import os.path

app = wx.App(False)

config = wx.Config(“MyApp”)

app.MainLoop()

filename = wx.FileConfig(“MyApp”).GetLocalFileName(“MyApp”)

if os.path.isfile(filename):

# Do the local filesystem specific stuff here

Any thoughts or opinions on that approach?

···

On Sunday, February 14, 2016 at 5:05:09 PM UTC-8, austin aigbe wrote:

Take a look at the source code: https://github.com/wxWidgets/wxPython/blob/14476d72d92c44624d5754c4f1fac2e8d7bc30da/src/gtk/_misc.py

On Linux, wx.Config will use wx.FileConfig. I can’t even find RegConfig in the source code, I guess RegConfig is the same a the Windows registry.

class Config(ConfigBase):
“”"
This ConfigBase-derived class will use the registry on Windows,
and will be a wx.FileConfig on other platforms.
“”"

class FileConfig(ConfigBase):
“”“This config class will use a file for storage on all platforms.”“”
Then the base class:

class ConfigBase(object):
“”"
wx.ConfigBase class defines the basic interface of all config
classes. It can not be used by itself (it is an abstract base class)
and you will always use one of its derivations: wx.Config or
wx.FileConfig.
wx.ConfigBase organizes the items in a tree-like structure, modeled
after the Unix/Dos filesystem. There are groups that act like
directories and entries, key/value pairs that act like files. There
is always one current group given by the current path. As in the file
system case, to specify a key in the config class you must use a path
to it. Config classes also support the notion of the current group,
which makes it possible to use relative paths.
Keys are pairs “key_name = value” where value may be of string,
integer floating point or boolean, you can not store binary data
without first encoding it as a string. For performance reasons items
should be kept small, no more than a couple kilobytes.
“”"Regards,

Austin

On Saturday, February 13, 2016 at 2:38:10 AM UTC+1, Jason Ahrens wrote:

Correct, this is regarding wx.Config module: http://wxpython.org/Phoenix/docs/html/ConfigBase.html (and associated wx.FileConfig)

The problem I’m having is: wx.Config ends up being a layer over the actual config type. On Windows it’s a “wx.RegConfig” (which I’ve been unable to find any direct documentation for) and on other platforms it’s a wx.FileConfig. However type(configObj) just returns it’s type ‘wx._misc.Config’ so I can’t actually tell what its behaviour is going to be. None of the wx.FileConfig specific methods are exposed.

I need to detect if wx.Config is using wx.FileConfig as the underlying config module or not so I can do necessary file system work appropriately given the different data storage medium.

On Thursday, February 11, 2016 at 3:34:12 AM UTC-8, James Scholes wrote:

Nathan McCorkle wrote:

This doesn’t sound like a wxPython question, rather a question for the

config module usage

The Config module which is a part of wxPython, that is.


James Scholes

http://twitter.com/JamesScholes

This is one of those modules in wxPython which I personally wouldn’t use . Most of the time, Robin Dunn (creator of wxPython) would tell you to use the standard Python module over the wxPython one, which in this case is ConfigParser - 13.2. ConfigParser — Configuration file parser — Python 2.7.18 documentation

I don’t really like that module although it works just fine. I prefer ConfigObj instead - http://www.voidspace.org.uk/python/configobj.html

Mike

···

On Wednesday, February 10, 2016 at 7:15:54 PM UTC-6, Jason Ahrens wrote:

I’m fairly new to wxPython, and have taken on my first project :slight_smile: Actually, it’s modifying some existing code.

This code was originally written for Windows, and I’m working on a Linux system. It uses Config module to store some basic information, including a bit of sensitive info.

On Linux, this means it creates a plain text file using the default umask of the user.

So I’m trying to figure out: How can I tell the ‘type’ of Config so if it’s a FileConfig, I can set the umask? The other files it generates are all fine to be readable by others, even encouraged. It’s just the Config file I need to lock down.

Or perhaps, how do I tell the ‘type’ of system, so I can switch on type?

I’m trying not to modify existing behaviour of using the system specific config type if I can help it.

Given what I see here, I would tend to agree.

Unfortunately the choice of config module is not up to me. :slight_smile:

Thanks for the pointers to alternatives though. They’ll come in useful to me in the future I’m sure!

···

On Tuesday, February 16, 2016 at 9:39:12 AM UTC-8, Mike Driscoll wrote:

On Wednesday, February 10, 2016 at 7:15:54 PM UTC-6, Jason Ahrens wrote:

I’m fairly new to wxPython, and have taken on my first project :slight_smile: Actually, it’s modifying some existing code.

This code was originally written for Windows, and I’m working on a Linux system. It uses Config module to store some basic information, including a bit of sensitive info.

On Linux, this means it creates a plain text file using the default umask of the user.

So I’m trying to figure out: How can I tell the ‘type’ of Config so if it’s a FileConfig, I can set the umask? The other files it generates are all fine to be readable by others, even encouraged. It’s just the Config file I need to lock down.

Or perhaps, how do I tell the ‘type’ of system, so I can switch on type?

I’m trying not to modify existing behaviour of using the system specific config type if I can help it.

This is one of those modules in wxPython which I personally wouldn’t use . Most of the time, Robin Dunn (creator of wxPython) would tell you to use the standard Python module over the wxPython one, which in this case is ConfigParser - https://docs.python.org/2/library/configparser.html

I don’t really like that module although it works just fine. I prefer ConfigObj instead - http://www.voidspace.org.uk/python/configobj.html

Mike

For anyone still following along, just wanted to post a final update. This did indeed work, even though it feels overly hacky.

Thanks all!

···

On Monday, February 15, 2016 at 5:52:47 PM UTC-8, Jason Ahrens wrote:

Yes, that’s essentially what I posted above too, however I’m trying to find programatically what the result of this internal check/creation is.

On a Linux system, for example, you can’t tell via isinstance that it chose wx.FileConfig, because the wx.Config object doesn’t transform:

snowleopard% python2

Python 2.7.11 (default, Dec 6 2015, 15:43:46)

[GCC 5.2.0] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

import wx

app = wx.App(False)

config = wx.Config(“MyApp”)

isinstance(config, wx.FileConfig)

False

Unfortunately I start to get lost while trying to read the code to figure it out.

https://github.com/wxWidgets/wxPython/blob/14476d72d92c44624d5754c4f1fac2e8d7bc30da/src/gtk/_misc.py#L3486 is where the class Config is defined with the constructor ultimately calling misc.Config_swiginit(self,misc.new_Config(*args, **kwargs)), however misc is not python, but the CPP swig object.

Further to this, it looks like (as you’d expect of the complied portion) the decision is not ‘made’ during runtime, but at compile. (there’s both a gtk/_misc_wrap.cpp and msw/_misc_wrap.cpp that contain the code for new_Config). However so far reading through the C++ code, I’ve been unable to identify something that “flags” the underlying mechanism wx.Config is using.

Sounds like this is a lot more complicated than I thought it would be.

If this actually can’t be accomplished (which is starting to look like the case) a hacky way I could accomplish this would be (this is untested… I’ll try it out tomorrow when I get some more time) and assumes I’ll get control back from MainLoop():

import wx

import os.path

app = wx.App(False)

config = wx.Config(“MyApp”)

app.MainLoop()

filename = wx.FileConfig(“MyApp”).GetLocalFileName(“MyApp”)

if os.path.isfile(filename):

# Do the local filesystem specific stuff here

Any thoughts or opinions on that approach?

On Sunday, February 14, 2016 at 5:05:09 PM UTC-8, austin aigbe wrote:

Take a look at the source code: https://github.com/wxWidgets/wxPython/blob/14476d72d92c44624d5754c4f1fac2e8d7bc30da/src/gtk/_misc.py

On Linux, wx.Config will use wx.FileConfig. I can’t even find RegConfig in the source code, I guess RegConfig is the same a the Windows registry.

class Config(ConfigBase):
“”"
This ConfigBase-derived class will use the registry on Windows,
and will be a wx.FileConfig on other platforms.
“”"

class FileConfig(ConfigBase):
“”“This config class will use a file for storage on all platforms.”“”
Then the base class:

class ConfigBase(object):
“”"
wx.ConfigBase class defines the basic interface of all config
classes. It can not be used by itself (it is an abstract base class)
and you will always use one of its derivations: wx.Config or
wx.FileConfig.
wx.ConfigBase organizes the items in a tree-like structure, modeled
after the Unix/Dos filesystem. There are groups that act like
directories and entries, key/value pairs that act like files. There
is always one current group given by the current path. As in the file
system case, to specify a key in the config class you must use a path
to it. Config classes also support the notion of the current group,
which makes it possible to use relative paths.
Keys are pairs “key_name = value” where value may be of string,
integer floating point or boolean, you can not store binary data
without first encoding it as a string. For performance reasons items
should be kept small, no more than a couple kilobytes.
“”"Regards,

Austin

On Saturday, February 13, 2016 at 2:38:10 AM UTC+1, Jason Ahrens wrote:

Correct, this is regarding wx.Config module: http://wxpython.org/Phoenix/docs/html/ConfigBase.html (and associated wx.FileConfig)

The problem I’m having is: wx.Config ends up being a layer over the actual config type. On Windows it’s a “wx.RegConfig” (which I’ve been unable to find any direct documentation for) and on other platforms it’s a wx.FileConfig. However type(configObj) just returns it’s type ‘wx._misc.Config’ so I can’t actually tell what its behaviour is going to be. None of the wx.FileConfig specific methods are exposed.

I need to detect if wx.Config is using wx.FileConfig as the underlying config module or not so I can do necessary file system work appropriately given the different data storage medium.

On Thursday, February 11, 2016 at 3:34:12 AM UTC-8, James Scholes wrote:

Nathan McCorkle wrote:

This doesn’t sound like a wxPython question, rather a question for the

config module usage

The Config module which is a part of wxPython, that is.


James Scholes

http://twitter.com/JamesScholes