Arnaldo Carvalho de Melo píše v Út 19. 05. 2015 v 11:10 -0300:
Em Tue, May 19, 2015 at 09:29:11AM +0200, Petr Oros escreveu:
> Arnaldo Carvalho de Melo píše v Po 18. 05. 2015 v 16:37 -0300:
> > Em Mon, May 18, 2015 at 02:50:25PM -0400, John Kacur escreveu:
> > > Yeah, it was also in response to me pointing the bz out to him.
> > > I'm
> > > testing it as well, I would like to wait for your patch-review
> > > Arnaldo before
> > > I grab this fix.
> > > ----- Original Message -----
> > > > I guess this was in response to my report, right? So it would
> > > > be
> > > > nice to
> > > > have:
> > > >
> > > > Reported-by: Arnaldo Carvalho de Melo <acme(a)redhat.com>
> > > > Fixes:
https://bugzilla.redhat.com/..../bz-number
> > > >
> > > > I will review and test later, thanks for the patch!
> > > >
> > > > - Arnaldo
> >
> > Seems to work as advertised:
> >
> > > > > def ConfigPathToFileName(self, configpath):
> > ... return configpath.replace(".",
"/").replace("\\/", ".")
> > ...
> > > > > def FileNameToConfigPath(self, filename):
> > ... return filename.replace(".",
"\\.").replace("/", ".")
> > ...
> > > > > filename="/proc/sys/net/ipv4/neigh/tuna.1"
> > > > > config=FileNameToConfigPath(None, filename)
> > > > > print config
> > .proc.sys.net.ipv4.neigh.tuna\.1
> > > > > print ConfigPathToFileName(config)
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > TypeError: ConfigPathToFileName() takes exactly 2 arguments (1
> > given)
> > > > > print ConfigPathToFileName(None, config)
> > /proc/sys/net/ipv4/neigh/tuna.1
> > > > >
> >
> > But then I don't know why that has to be a class method instead
> > of a
> > global
> > function, since it is not specific to that class, see how 'self'
> > is
> > not used at
> > all, and os potentially useful for other cases dealing with
> > filenames
> > as config
> > keys.
> >
> > So I'd recommend to make those global functions, outside this
> > class.
>
> It's conversion config <-> filesystem. Direct access is bad. Tuna
> can
Why is it bad?
> use config ONLY over this class. I don't know where can use this
> conversion directly. Class method protect to potential bad use.
Can you think of one?
These helpers are related to config class code. Python is object
oriented language and, i just don't see reason why move functions
somewhere into space. I created them for better outline and for
specific usage, not globally for some magic anywhere.
Regards,
-Petr
> Just my opinion, if you still think, use as global is better, i
> will do
> it.
- Arnaldo