[Yum] some refactoring...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2002-10-29 at 18:59, Vladimir Bormotov wrote:
>                 Hi!
> 
>  now clientStuff.take_action() looks:
>   
> ============== cut =========== 
>  def take_action(cmds, nulist, uplist, newlist, obslist, tsInfo,
>                  HeaderInfo, rpmDBInfo, obsdict):
>     from yummain import usage
> 
>     _command = cmds.pop(0)
> 
>     if (conf.uid != 0) and \
>        (_command in ['install', 'update', 'clean', 'upgrade', 'erase']):
>       errorlog(0, _('You need to be root to perform these commands'))
>       sys.exit(1)
> 
>     if _command == 'install':
>         action_install(cmds, nulist, tsInfo, HeaderInfo, rpmDBInfo)
>     elif _command == 'provides':
>         action_provides(cmds, nulist, HeaderInfo, rpmDBInfo)
>         sys.exit(0)
>     elif _command == 'update':
>         action_update(cmds, nulist, uplist, newlist, obslist, tsInfo,
>                       HeaderInfo, rpmDBInfo)
>     elif _command == 'upgrade':
>         action_upgrade(cmds, nulist, uplist, obslist, tsInfo, HeaderInfo,
>                        rpmDBInfo, obsdict)
>     elif _command in ['erase', 'remove']:
>         action_erase(cmds, tsInfo, rpmDBInfo)
>     elif _command == 'list':
>         action_list(cmds, nulist, uplist, newlist, HeaderInfo, rpmDBInfo)
>         sys.exit(0)
>     elif _command == 'info':
>         action_info(cmds, nulist, uplist, newlist, HeaderInfo, rpmDBInfo)
>         sys.exit(0)
>     elif _command == 'clean':
>         action_clean(cmds, HeaderInfo, rpmDBInfo)
>         sys.exit(0)
>     else:
>         usage()
> ============== cut =========== 
> 
>  1. I just "extract" each action into separate function, named action_*
>  2. List object can pop element, as result we pop command from cmds, once.
>  
>   each case modified like this:
>   
>     -    elif cmds[0] == 'info':
>     -        cmds.remove(cmds[0])
>     +    elif _command == 'info':
>   
>  I think, result very pretty ;)
>   


I like the single pop instead of multiple cmds.remove

but I don't understand - is there a benefit from naming the variable
_command? Is it just to imply that it should be a private variable? I
thought _ didn't do anything but __ really made it private. Is that
right?

-sv





[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux