Change default cache directory to '/var/cache/revdep-rebuild'
[gentoolkit.git] / pym / gentoolkit / revdep_rebuild / stuff.py
1 #!/usr/bin/python
2
3 """Utilities submodule"""
4
5
6 from __future__ import print_function
7
8 import subprocess
9
10 import portage
11
12
13 # util. functions
14 def call_program(args):
15         ''' Calls program with specified parameters
16         and returns the stdout as a str object.
17         
18         @param, args: arument list to pass to subprocess
19         @return str
20         '''
21         subp = subprocess.Popen(args, stdout=subprocess.PIPE, \
22                                                                 stderr=subprocess.PIPE)
23         stdout, stderr = subp.communicate()
24         return str(stdout)
25
26
27 def scan(params, files, max_args):
28         ''' Calls scanelf with given params and files to scan.
29                 @param params is list of parameters that should
30                         be passed into scanelf app.
31                 @param files list of files to scan.
32                 @param max_args number of files to process at once
33
34                 When files count is greater CMD_MAX_ARGS, it'll be divided
35                 into several parts
36
37                 @return scanelf output (joined if was called several times)
38         '''
39         out = []
40         for i in range(0, len(files), max_args):
41                 out += call_program(
42                         ['scanelf'] + params + files[i:i+max_args]).strip().split('\n')
43         return out
44
45
46 def get_masking_status(ebuild):
47         """returns the masking status of an ebuild
48         
49         @param ebuild: str
50         @return list
51         """
52         try:
53                 status = portage.getmaskingstatus(ebuild)
54         except KeyError:
55                 status = ['unavailable']
56         return status
57
58
59 def _match_str_in_list(lst, stri):
60         """
61         @param lst: list
62         @param stri: string
63         @return boolean or list menber that matches stri.endswith(member)
64         """
65         for item in lst:
66                 if stri.endswith(item):
67                         return item
68         return False
69
70
71
72 if __name__ == '__main__':
73         print("There is nothing to run here.")