[tor-bugs] #4913 [Stem]: Add stem.util.conf.Config.save()

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Mon Jan 16 07:47:34 UTC 2012


#4913: Add stem.util.conf.Config.save()
-------------------------+--------------------------------------------------
 Reporter:  gsathya      |          Owner:  atagar        
     Type:  enhancement  |         Status:  needs_revision
 Priority:  normal       |      Milestone:                
Component:  Stem         |        Version:                
 Keywords:               |         Parent:                
   Points:               |   Actualpoints:                
-------------------------+--------------------------------------------------

Comment(by gsathya):

 Replying to [comment:5 atagar]:
 > I've pushed a couple of your changes (6c5f020 and 451e13e) with some
 very minor tweaks.
 Thanks!

 >Would you mind adding an integ test for your save function? I'd be happy
 to help if you're unsure what to add.
 >
 Ok I'll try.

 > > +    return self._contents.keys()
 >
 > I'm gonna hazard the guess that this is testing code since the save()
 function is then a no-op. ;)
 >

 I'm not sure I follow. Where is this from?
 > > def iterkeys(self):
 >
 > I'm not sure of the point of this function... why did you add it? When
 you call dict.keys() it's an iterable object... I suppose getting an
 iterator directly is slightly more efficient but probably not worth adding
 a new function.
 >

 Yeah, I wanted to do --
 {{{
 for entry in sorted(self.iterkeys()):
 }}}
 instead of
 {{{
 config_keys = self.keys()
 config_keys.sort()
 }}}
 and iterating over
 {{{
 config_keys
 }}}
 For some reason I thought you'd have to pass an iterable to {{{ sorted()
 }}} and not just a list. Sorry.

 > > On the other hand, if we pass Multiple = True, we'd get a list of
 values which we dont need like...
 >
 > I'm not following, mind clarifying why you'd only want to save
 'login.password -> ["foo"]'?

 So we have a config file that has
 {{{
       login.password foo
 }}}
 and we do the following
 {{{
       user_config = stem.util.conf.get_config("login")
       user_config.load("/home/foo/myConfig")

       user_config.get("login.password")
       #"foo"

       user_config.set("login.password","bar")
       #login.password -> ["foo", "bar"]

       user_config.get("login.password")
       #"bar"

       user_config.save()
       #login.password bar
  }}}
 Now the config file has
 {{{
      login.password bar
 }}}
 The above behavior is perfect. We only need to save "login.password bar",
 thus overwriting "login.password foo".

 Now consider a config file with
 {{{
       startup.run export PATH=$PATH:~/bin
       startup.run alias l=ls
 }}}

 and we do the following --
 {{{
       user_config = stem.util.conf.get_config("startup")
       user_config.load("/home/foo/myConfig")

       user_config.get("startup.run")
       #"alias l=ls"

       user_config.save()
       #startup.run alias l=ls
 }}}

 Now, the config file only contains -
 {{{
 startup.run alias l=ls
 }}}
 And
 {{{
 startup.run export PATH=$PATH:~/bin
 }}}
 gets pruned.

 We have deleted information from the config file. We shouldn't be doing
 this.

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/4913#comment:6>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list