~flimm/epidermis/icon-theme-bugfix

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
#!/usr/bin/env python
# Copyright 2008-2010 David D Lowe
# released under the GPLv3

from pigment import PigmentType, Pigment
from pigment_more import FileBasedPigment, FileBasedPigmentType
import pigment
import os, sys
import subprocess
import gtk
from glob import glob
if __name__ == "__main__" or 'pychecker' in sys.argv[0]:
    sys.path.append("..")
import handy
import ep_exceptions
from const import logger
import hashlib
from gettext import gettext as _


class GrubType(FileBasedPigmentType):
    humanName = {"en":"Grub"}
    humanPluralName = {"en":"Grub"}
    codeName = "grub"
    abbreviation = "gr"
    directoryName = "grub"
    canGeneratePreview = True
    
    attachmentTypeHelp = _("The theme file should be a compressed xpm image file with the extension xpm.gz")
    
    publicBaseDir = "/boot/grub/splashimages"
    personalBaseDir = ""
        
    @staticmethod
    def get_Pigment():
        return Grub
    
    @classmethod
    def does_system_support_me(klass):
        pop = None
        try:
            pop = subprocess.Popen(["grub-mkisofs", "--version"],stdout=subprocess.PIPE)
        except OSError:
            return False
        try:
            line = pop.stdout.readlines()[0][:-1]
            grubVersion = line.split(" ")[-1][:-1]
            if grubVersion[:3] == "1.9":
                return False
            elif grubVersion[:3] == "0.9":
                return True
            else:
                return False
        except Exception, ee:
            logger.warning(str(ee))
            return False

class Grub(FileBasedPigment):
    
    type = GrubType    
    
    def __init__(self):
        FileBasedPigment.__init__(self)
    
    def activate(self, progressCallback=None, shell=None):
        if progressCallback is None:
            progressCallback = lambda(a1): False
        if progressCallback(0.0): return
        if os.path.exists("/boot/grub/splash.xpm.gz"):
            shell.do(["cp", "-f", "/boot/grub/splash.xpm.gz", "/boot/grub/splash.xpm.gz.epidermis.bak"])
            shell.do(["rm", "/boot/grub/splash.xpm.gz"])
        if progressCallback(0.25): return
        shell.do(["ln", "-s", os.path.join(self.type.publicBaseDir,self.attFilename), "/boot/grub/splash.xpm.gz"])
        if progressCallback(0.5): return
        shell.do(["update-grub"])
        progressCallback(1.0)
    
    def is_activated(self):
        return self.is_meat_activated()

    def is_attachment_correct(self, attachmentIndex=None):
        if FileBasedPigment.is_attachment_correct(self, attachmentIndex):
            if attachmentIndex is None:
                attachmentIndex = 0
            extension = self.attachments[attachmentIndex].split(".")[-2:]
            if not (extension[0], extension[1]) == ("xpm","gz"):
                return False
            return True
        else: return False
    
    def is_meat_activated(self):
        # TODO: finish is_meat_activated
        (md1, md2) = (hashlib.md5(), hashlib.md5())
        try:
            f1 = file(self.attPath, 'rb')
            f2 = file("/boot/grub/splash.xpm.gz", 'rb')
        except:
            return False
        for mm, ff in ((md1, f1), (md2, f2)):
            ss = ff.read(8096)
            if not ss:
                break
            mm.update(ss)
        return md1 == md2
    
    def generate_preview(self):
        if not os.path.exists(self.attPath):
            return None
        subprocess.call(["mkdir",  "-p",  "/tmp/epidermis"])
        subprocess.call(["cp", self.attPath,  "/tmp/epidermis/grub-preview.xpm.gz"])
        res = subprocess.call(["gunzip",  "-f","/tmp/epidermis/grub-preview.xpm.gz"],  cwd="/tmp/epidermis")
        if res == 1:
            subprocess.call(["mv",  "grub-preview.xpm.gz",  "grub-preview.xpm"],  cwd="/tmp/epidermis")
        try:
            pb = gtk.gdk.pixbuf_new_from_file_at_size("/tmp/epidermis/grub-preview.xpm", 100, 75)
        except:
            import traceback
            traceback.print_exc()
            return None
        if pb is None:
            return None
        else:
            self.preview = pb
            return pb
    
    def does_activation_require_root(self):
        return True
    
    def get_display_data(self, index=0):
        return