Fix python 3 syntax errors with new revdep-rebuild. Change VERSION to
[gentoolkit.git] / pym / gentoolkit / revdep_rebuild / stuff.py
1 #!/usr/bin/python
2
3 import subprocess
4
5 import portage
6
7
8 # util. functions
9 def call_program(args):
10         ''' Calls program with specified parameters and returns stdout '''
11         subp = subprocess.Popen(args, stdout=subprocess.PIPE, \
12                                                                 stderr=subprocess.PIPE)
13         stdout, stderr = subp.communicate()
14         return stdout
15
16
17 def scan(params, files, max_args):
18         ''' Calls scanelf with given params and files to scan.
19                 @param params is list of parameters that should be passed into scanelf app.
20                 @param files list of files to scan.
21                 @param max_args number of files to process at once
22
23                 When files count is greater CMD_MAX_ARGS, it'll be divided
24                 into several parts
25
26                 @return scanelf output (joined if was called several times)
27         '''
28         out = []
29         for i in range(0, len(files), max_args):
30                 out += call_program(['scanelf'] + params + files[i:i+max_args]).strip().split('\n')
31         return out
32
33
34 def exithandler(signum, frame):
35         sys.exit(1)
36
37
38 def get_masking_status(ebuild):
39         try:
40                 status = portage.getmaskingstatus(ebuild)
41         except KeyError:
42                 status = ['unavailable']
43         return status
44
45
46 def _match_str_in_list(lst, stri):
47         for l in lst:
48                 if stri.endswith(l):
49                         return l
50         return False
51
52
53
54 if __name__ == '__main__':
55         print("There is nothing to run here.")