| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 | #!/usr/bin/python2
# -*- coding: utf-8 -*-
__author__ = "James Meyer"
__date__   = "Dec 11th 2012"
import subprocess, sys
class plymouth_driver():
    def __init__(self):
        self.videocard = self.find_video_card()
        self.old_conf = self.read_mkinit()
        self.set_old_hook(self.old_conf)
    def getvc(self):
        return self.videocard
    def get_old_hooks(self):
        return self.old_hooks
    def get_old_modules(self):
        return self.old_modules
    def get_new_hooks(self):
        return self.new_hooks
    def get_new_modules(self):
        return self.new_modules
    def set_old_hook(self,conf):
        self.old_hooks, self.old_modules = self.find_hooks_modules(conf)
    def find_video_card(self):
        videocard=""
        conf_file="/etc/X11/xorg.conf.d/20-automv.conf"
        lines=[]
        try:
            f=open(conf_file,'r')
            lines=f.readlines()
            f.close()
        except:
            print "    find_video_card: couldn't read in %s" %conf_file
            videocard = "unknown"
        for line in lines:
            parsed=line.split()
            if parsed[0].strip() == "Driver":
                videocard = parsed[1].strip('''"''')
                break
        return  videocard
    def read_mkinit(self):
        conf_file="/etc/mkinitcpio.conf"
        old_conf=[]
        try:
            f=open(conf_file,'r')
            old_conf=f.readlines()
        except:
            print "    plymouth_config: couldn't read %s" %conf_file
            sys.exit(1)
        return old_conf
    def find_hooks_modules(self,conf_list):
        for line in conf_list:
            if line.startswith('HOOKS='):
                hooks=line.split('''"''')[1].split()
            if line.startswith('MODULES='):
                modules=line.split('''"''')[1].split()
        return hooks,modules
    def add_hooks(self,add_hooks, hooks):
        new_hooks = hooks
        for i in add_hooks:
            if not i in (new_hooks):
                new_hooks.append(i)
        return new_hooks
    def remove_hooks(self,remove_hooks, hooks):
        for i in remove_hooks:
            try:
                while True:
                    hooks.remove(i)
            except:
                pass
        return hooks
    def add_modules(self, add_modules, modules):
        new_modules = modules
        for i in add_modules:
            if not i in (new_modules):
                new_modules.append(i)
        return new_modules
    def remove_modules(self,remove_modules, modules):
        for i in remove_modules:
            try:
                while True:
                    modules.remove(i)
            except:
                pass
        return modules
    def create_new_hooks_modules(self):
        new_hooks = list(self.old_hooks)
        new_modules = list(self.old_modules)
        add_hooks=[]
        remove_hooks=[]
        remove_modules=[]
        add_modules=[]
        if self.videocard == "intel":
           add_modules = ['i915']
           remove_hooks = ['v86d']
        else:
            #add_modules = ['nfs','jm']
            remove_modules = ['i915']
            add_hooks = ['v86d']
        new_hooks = self.add_hooks(add_hooks , new_hooks)
        new_hooks = self.remove_hooks(remove_hooks, new_hooks)
        new_modules = self.add_modules(add_modules, new_modules)
        new_modules = self.remove_modules(remove_modules, new_modules)
        self.new_hooks = new_hooks
        self.new_modules = new_modules
    def compare_hooks_modules(self):
        h = cmp( self.old_hooks,self.new_hooks)
        m = cmp( self.old_modules,self.new_modules)
        if h == 0 and m == 0:
            return True
        else:
            return False
    def create_newmkinitcpio(self):
        if self.compare_hooks_modules() == True:
            print "    plymouth_config: no changes made"
            return False
        else:
            conf_file="/etc/mkinitcpio.conf"
            try:
                f=open(conf_file,'w')
                for line in self.old_conf:
                    new_line=line
                    if line.startswith('HOOKS='):
                        new_line = 'HOOKS="%s"' %(" ".join(self.new_hooks))
                    if line.startswith('MODULES='):
                        new_line = 'MODULES="%s"'%(" ".join(self.new_modules))
                    f.write(new_line)
                    f.write("\n")
                f.close()
            except:
                print "    plymouth_config: couldn't write %s" %conf_file
                return False
        return True
    def run_mkinitcpio(self):
        print "    plymouth_config: Running mkinitcpio "
        subprocess.call(["/usr/bin/mkinitcpio", "-p" , "linux"])
def go():
    p = plymouth_driver()
    vc = p.getvc()
    print "    plymouth_config: found videocard %s" %vc
    p.create_new_hooks_modules()
    #print p.get_old_hooks()
    #print p.get_new_hooks()
    #print "=="
    #print p.get_old_modules()
    #print p.get_new_modules()
    if p.create_newmkinitcpio() == True or "--mkinitcpio" in sys.argv:
        p.run_mkinitcpio()
if __name__ == '__main__':
    go()
 |