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.
- Arnaldo
It's conversion config <-> filesystem. Direct access is bad. Tuna can
use config ONLY over this class. I don't know where can use this
conversion directly. Class method protect to potential bad use.
Just my opinion, if you still think, use as global is better, i will do
it.
Regards,
-Petr
> > > ---
> > > tuna/config.py | 26 ++++++++++++++++----------
> > > 1 file changed, 16 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/tuna/config.py b/tuna/config.py
> > > index 77cc4d8..02c730e 100644
> > > --- a/tuna/config.py
> > > +++ b/tuna/config.py
> > > @@ -30,6 +30,12 @@ class Config:
> > > self.config[option] = value
> > > self.cacheFileName = ''
> > >
> > > + def FileNameToConfigPath(self, filename):
> > > + return filename.replace(".",
> > > "\\.").replace("/", ".")
> > > +
> > > + def ConfigPathToFileName(self, configpath):
> > > + return configpath.replace(".",
> > > "/").replace("\\/", ".")
> > > +
> > > def updateDefault(self, filename):
> > > if filename.replace("", "temp-direct
> > > -load.conf") != filename:
> > > self.temp =
> > > ConfigParser.RawConfigParser()
> > > @@ -154,9 +160,9 @@ class Config:
> > > tempCfg = []
> > > for index in
> > > range(len(oldTempCfg)):
> > > if
> > > self.isFnString(oldTempCfg[index][0]):
> > > - expand
> > > ed = self.getFilesByFN("/proc/sys",
> > > oldTempCfg[index][0].replace(".", "/"))
> > > + expand
> > > ed = self.getFilesByFN("/proc/sys",
> > > self.ConfigPathToFileName(oldTempCfg[index][0]))
> > > for
> > > index2 in range(len(expanded)):
> > > - > >
> > expandedData = (expanded[index2].replace("/",
> > > "."),
> > > oldTempCfg[index][1])
> > > + > >
> > expandedData =
> > > (self.FileNameToConfigPath(expanded[index2]),
> > > oldTempCfg[index][1])
> > > > >
> > tempCfg.append(expandedData)
> > > else:
> > > tempCf
> > > g.append(oldTempCfg[index])
> > > @@ -241,9 +247,9 @@ class Config:
> > > def getSystemValue(self, filename):
> > > filename = self.aliasToOriginal(filename)
> > > try:
> > > - buffer = open("/proc/sys/" +
> > > filename.replace(".", "/"), 'r').read()
> > > + buffer = open("/proc/sys/" +
> > > self.ConfigPathToFileName(filename),
> > > 'r').read()
> > > except IOError:
> > > - print _("Invalid item! file:
> > > /proc/sys/%s" %(filename.replace(".",
> > > "/")))
> > > + print _("Invalid item! file:
> > > /proc/sys/%s"
> > > %(self.ConfigPathToFileName(filename)))
> > > return ""
> > > return buffer.strip()
> > >
> > > @@ -253,10 +259,10 @@ class Config:
> > > if value == "" or old == value:
> > > return 0
> > > try:
> > > - fp = open("/proc/sys/" +
> > > filename.replace(".", "/"), 'w')
> > > + fp = open("/proc/sys/" +
> > > self.ConfigPathToFileName(filename), 'w')
> > > fp.write(value)
> > > except IOError:
> > > - print "%s%s %s %s" % (_("Cant write
to
> > > file! path: /proc/sys/"),
> > > filename.replace(".","/"), _("value:"),
value)
> > > + print "%s%s %s %s" % (_("Cant write
to
> > > file! path: /proc/sys/"),
> > > self.ConfigPathToFileName(filename), _("value:"), value)
> > > return -1
> > > return 0
> > >
> > > @@ -302,9 +308,9 @@ class Config:
> > > snapcont = []
> > > for index in
> > > range(len(snapcontPacked)):
> > > if
> > > self.isFnString(snapcontPacked[index][0]):
> > > - expanded =
> > > self.getFilesByFN("/proc/sys",snapcontPacked[index][0].replace(
> > > ".","/"))
> > > + expanded =
> > > self.getFilesByFN("/proc/sys",self.ConfigPathToFileName(snapcon
> > > tPacked[index][0]))
> > > for index2 in
> > > range(len(expanded)):
> > > - expandedData =
> > >
(expanded[index2].replace("/","."),snapcontPacked[index][1])
> > > + expandedData =
> > > (self.FileNameToConfigPath(expanded[index2]),snapcontPacked[ind
> > > ex][1])
> > > snapcont.appen
> > > d(expandedData)
> > > else:
> > > snapcont.append(snapco
> > > ntPacked[index])
> > > @@ -348,7 +354,7 @@ class Config:
> > > return msgStack
> > > current =
> > > self.checkParser.items(option)
> > > for opt,val in current:
> > > - if not
> > > os.path.exists("/proc/sys/" +
opt.replace(".","/")) and
> > >
len(self.getFilesByFN("/proc/sys/",opt.replace(".","/"))) ==
0:
> > > + if not
> > > os.path.exists("/proc/sys/" + self.ConfigPathToFileName(opt))
> > > and len(self.getFilesByFN("/proc/sys/",
> > > self.ConfigPathToFileName(opt)))
> > > == 0:
> > > msgStack =
> > > "%s%s%s\n" % (msgStack, _("Warning: File not found:
> > > /proc/sys/"),
> > > opt)
> > > self.empty = False
> > > if self.empty:
> > > @@ -367,7 +373,7 @@ class Config:
> > > self.checkParser.set('
> > > categories', '#' + option, value)
> > > current =
> > > self.checkParser.items(option)
> > > for opt,val in current:
> > > - if not
> > > os.path.exists("/proc/sys/" + opt.replace(".",
"/")) and
> > > len(self.getFilesByFN("/proc/sys/", opt.replace(".",
"/"))) ==
> > > 0:
> > > + if not
> > > os.path.exists("/proc/sys/" + self.ConfigPathToFileName(opt))
> > > and len(self.getFilesByFN("/proc/sys/",
> > > self.ConfigPathToFileName(opt)))
> > > == 0:
> > > self.checkPars
> > > er.remove_option(option, opt)
> > > self.checkPars
> > > er.set(option, '#' + opt, val)
> > > except (ConfigParser.Error, IOError) as e:
> > > --
> > > 2.4.1
> > >
> > > _______________________________________________
> > > tuna-devel mailing list
> > > tuna-devel(a)lists.fedorahosted.org
> > >
https://lists.fedorahosted.org/mailman/listinfo/tuna-devel
> >