2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
23
# from _pyio import open
27
# custom plymouth bg by plymouthName
28
def custom_plymouth_bg(self, plymouthName):
29
plymouthName = plymouthName.encode('utf-8')
30
existingDir = '/var/lib/youker-assistant-daemon/plymouth/existing/'
31
linkFileDir = '/lib/plymouth/themes/default.plymouth'
33
# replace the config file
34
shutil.copy(existingDir + plymouthName + '/default.plymouth', linkFileDir)
36
# add new custom plymouth
37
def add_new_plymouth(self, customBG, plymouthName):
38
# if plymouthName exist return false
39
existingPlymouth = self.get_existing_plymouth_list()
40
customBG = customBG.encode('utf-8')
41
plymouthName = plymouthName.encode('utf-8')
43
if(plymouthName in existingPlymouth):
46
existingDir = '/var/lib/youker-assistant-daemon/plymouth/existing/'
47
customScript = '/var/lib/youker-assistant-daemon/plymouth/defaults/only_background.script'
48
defaultplymouthfile = '/var/lib/youker-assistant-daemon/plymouth/defaults/default.plymouth'
50
# add new plymouth conf dir
51
os.mkdir(existingDir + plymouthName)
52
shutil.copy(defaultplymouthfile, existingDir + plymouthName + '/default.plymouth')
54
fileHandle = open(existingDir + plymouthName + '/default.plymouth', 'a')
55
fileHandle.write('ImageDir=/lib/plymouth/themes/' + plymouthName + '\n')
56
fileHandle.write('ScriptFile=/lib/plymouth/themes/' + plymouthName + '/youker.script')
59
# add new system plymouth dir
60
os.mkdir('/lib/plymouth/themes/' + plymouthName)
61
shutil.copy(customScript, '/lib/plymouth/themes/' + plymouthName + '/youker.script')
62
#shutil.copy(customBG, '/lib/plymouth/themes/' + plymouthName + '/customBG.png')
63
Image.open(customBG).save('/lib/plymouth/themes/' + plymouthName + '/customBG.png')
67
# get existing plymouth list
68
def get_existing_plymouth_list(self):
70
edir = ('/var/lib/youker-assistant-daemon/plymouth/existing')
71
if os.path.isdir(edir):
72
for f in os.listdir(edir):
73
if os.path.isdir(os.path.join(edir, f)):
78
# check and save current plymouth when init
79
def plymouth_init_check(self):
80
existingDir = '/var/lib/youker-assistant-daemon/plymouth/existing/'
81
linkFileDir = '/lib/plymouth/themes/default.plymouth'
84
if(os.path.exists('/lib/plymouth/themes/ubuntukylin-logo') == False):
85
shutil.copytree('/var/lib/youker-assistant-daemon/plymouth/ubuntukylin-logo/', '/lib/plymouth/themes/ubuntukylin-logo')
87
# locate the current plymouth theme dir
88
linkFile = open(linkFileDir)
89
fullString = linkFile.read()
91
index = fullString.find('ScriptFile=')
92
theLine = fullString[index:]
93
# cut 'ScriptFile=' & '\n'
94
scriptFile = theLine[theLine.find('/'):theLine.find('\n')]
95
# scriptFile = theLine[theLine.find('/'):]
96
scriptDir = scriptFile[0:scriptFile.rfind('/')]
97
scriptName = scriptFile[scriptFile.rfind('/') + 1:]
98
plymouthName = scriptDir[scriptDir.rfind('/') + 1:]
100
# check and save current pl linkFile.close()ymouth
101
if(os.path.exists(existingDir + plymouthName) == False):
102
os.mkdir(existingDir + plymouthName)
103
shutil.copy(scriptFile, existingDir + plymouthName + '/' + scriptName)
104
shutil.copy(linkFileDir, existingDir + plymouthName + '/default.plymouth')
106
def get_image_path(self,name):
107
name = name.encode('utf-8')
108
# if not os.path.exists('/lib/plymouth/themes/' + name + '/customBG.png') :
109
if not os.path.exists('/lib/plymouth/themes/' + name + '/' + name + '.script') :
110
if not os.path.exists('/lib/plymouth/themes/' + name + '/youker.script') :
111
if not os.path.exists('/lib/plymouth/themes/' + name + '/customBG.png') :
119
# path = '/lib/plymouth/themes/' + name + '/customBG.png'
122
def delete_plymouth(self,plymouthName):
123
plymouthName = plymouthName.encode('utf-8')
124
fd = open('/lib/plymouth/themes/default.plymouth','r')
125
animation = fd.read()
127
used = animation[animation.index('themes/')+len('themes/'):]
128
used = used[:used.index('\n')]
129
if used == plymouthName :
131
elif plymouthName == 'ubuntukylin-logo':
134
shutil.rmtree('/var/lib/youker-assistant-daemon/plymouth/existing/' + plymouthName)
135
shutil.rmtree('/lib/plymouth/themes/' + plymouthName)
137
# plymouthName = plymouthName.encode('utf-8')
138
# fd = open('/lib/plymouth/themes/default.plymouth','r')
139
# animation = fd.read()
141
# used = animation[animation.index('themes/')+len('themes/'):]
142
# used = used[:used.index('\n')]
143
# if used == plymouthName :
146
# shutil.rmtree('/var/lib/youker-assistant-daemon/plymouth/existing/' + plymouthName)
147
# shutil.rmtree('/lib/plymouth/themes/' + plymouthName)
150
if __name__ == '__main__':
152
# print ooo.get_existing_plymouth_list()
153
# ooo.add_new_plymouth('/home/shine/heihei.png', 'hoho')
154
# ooo.custom_plymouth_bg('hoho')
155
# ooo.plymouth_init_check()