initial commit: 1.5.0
[systemrescuecd.git] / portage-overlay / sys-apps / dumpdisklayout / files / mod_checks.py
1 import re,os,commands
2 import mod_lvm
3
4 # -------------------------- check required progs/files---------------------
5 def check_requirements(reqprogs, reqfiles): # we need these programs/files
6         for arg in reqprogs:
7                 (status, output) = commands.getstatusoutput('which %s' % arg)
8                 if status != 0 or len(output)==0:
9                         return (-1, 'error: command %s not found' % arg)
10         for arg in reqfiles:
11                 if not os.path.isfile(arg) and not os.path.isdir(arg):
12                         return (-1, 'error: %s not found' % arg)
13         return (0, 'ok')
14
15 def check_linux26(): # we need linux-2.6
16         (status, output) = commands.getstatusoutput('uname -r')
17         if status != 0:
18                 print 'Cannot check the linux version running'
19                 return -1
20         if output[0:3] != '2.6':
21                 print 'This support only linux-2.6 or newer'
22                 return -1
23         return (0, 'ok')
24
25 def check_lvmprogs(): # we need the lvm tools version 2
26         lvmvers=mod_lvm.get_lvm_version()
27         if lvmvers[0:2]=='2.':
28                 return (0, 'ok')
29         else:
30                 return (-1, 'Cannot find lvm-tools version 2 (type "lvm version" for details)')
31
32 def check_lvm_status(status): # check the lvm status is as said in argument
33         for lv in mod_lvm.list_lv():
34                 if mod_lvm.get_lv_status(lv).lower()!=status:
35                         return -1 # wrong status
36         return 0 # ok