func grep utility

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

 



Hi ML, i added a new method to func_module so we can search for
a specific word the results from module methods. Why someone
may need it ? Well the main idea is to have a utility method like "grep"
which maybe useful in troubleshooting or just filtering some info. Examples
are better than definitions :

Scanning the "service" and "smart" modules for "funcd" expression

[root@acerfedora func]# func "*" grep -m "service,smart" -v funcd

Scanning module : service
Scanning module : smart
{'acerfedora': [{'func.minion.modules.service.get_running': 
[['/usr/bin/funcd',
                                                              'running']]}]}

When using grep utility it is better  to use it in async mode because you may 
get the "connection timeout errors"
Scanning all modules in system in async mode for keyword "funcd"

[root@acerfedora func]# func "*" grep --async funcd

{'acerfedora': [{'func.minion.modules.process.info': ['root 5629 0.0 1.0 15724 
9212 ? S 23:15 0:00 /usr/bin/python /usr/bin/funcd --daemon',
                                                      'root 8053 14.4 0.9 
13920 8716 pts/0 S+ 23:37 0:03 /usr/bin/python /usr/bin/func * grep --async 
funcd',
                                                      'root 8235 7.0 0.0 0 0 ? 
Z 23:37 0:00 [funcd] <defunct>',
                                                      'root 8237 0.0 0.8 16692 
8084 ? S 23:37 0:00 /usr/bin/python /usr/bin/funcd --daemon'],
                 'func.minion.modules.process.mem': ['1.7 MiB 2.6 MiB 4.3 MiB 
funcd']},
                {'func.minion.modules.service.get_running': 
[['/usr/bin/funcd',
                                                              'running']]}]}



I added grep utility for most of the modules but if you want to add it to your 
own module what you should do is easy :
here is the example of service.grep :

    @func_module.findout
    def grep(self,word):
        """
        Dig for some useful info in that module ...
        """
        final_dict = {self.get_running:[],
                      self.get_enabled:[]      
                }
        running = self.get_running()
        enabled = self.get_enabled()
        
        #get enabled ones
        for e in enabled:
            if e[0].lower().find(word)!=-1:
                final_dict[self.get_enabled].append(e)
         
        #get running ones
        for e in running:
            if e[0].lower().find(word)!=-1:
                final_dict[self.get_running].append(e)

        return final_dict


Branch is here for those who want to test it : 
http://github.com/makkalot/func/tree/modules

Comments ,ideas ? 

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

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

  Powered by Linux