This file is indexed.

/usr/share/pyshared/profilemanager/ProfileManagerModels.py is in edubuntu-menueditor 1.3.5-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# -*- coding: utf-8 -*-
### BEGIN LICENSE
# Copyright (C) 2009 <Marc Gariépy> <mgariepy@revolutionlinux.com> Révolution Linux
#This program is free software: you can redistribute it and/or modify it 
#under the terms of the GNU General Public License version 3  or (at your option) 
#any later version, as published by the Free Software Foundation.
#
#This program is distributed in the hope that it will be useful, but 
#WITHOUT ANY WARRANTY; without even the implied warranties of 
#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
#PURPOSE.  See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along 
#with this program.  If not, see <http://www.gnu.org/licenses/>.
### END LICENSE

import sys
import os
import gtk
import grp
import glob, csv


class GroupsModel(gtk.ListStore):
    (
        GROUP_NAME,
        GROUP_GID,
    ) = range(2)

    def __init__(self):
        gtk.ListStore.__init__(self, str, int)

        self.fill_model(self.get_groups())

    def add_group(self, name, gid):
        # TODO: need to validate the data.
        gr_name = []
        gr_gid = []
        for item in self.get_groups():
            gr_name.append(item.gr_name)
            gr_gid.append(item.gr_gid)

        if gid not in gr_gid and name not in gr_name:
            self.append([name, gid])
            return True
        else:
            return False

    def fill_model(self, list):
        for item in list:
            self.append([item.gr_name, item.gr_gid])

    def remove_groups(self,list):
        for item in list:
            iter_to_remove = self.iter_for_group(item.gr_name)
            if iter_to_remove:
                self.remove(iter_to_remove)

    def append_group_if_valid(self,name):
        system_groups = self.get_groups()
        for group in system_groups:
            if group.gr_name == name:
                self.append([group.gr_name, group.gr_gid])

    def get_groups(self):
        groups = grp.getgrall()
        gr_list = []
        for group in groups:
            if group.gr_gid >= 1000 and group.gr_name != "nogroup":
                gr_list.append(group)
        return gr_list
    
    def get_system_groups(self):
        groups = grp.getgrall()
        gr_list = []
        for group in groups:
            if group.gr_gid < 1000:
                gr_list.append(group)
        return gr_list

    def iter_for_group(self, name):
        # return the iter of the group or None
        iter = self.get_iter_first()
        while iter:
            if self.get_value(iter, self.GROUP_NAME) == name:
                return iter
            iter = self.iter_next(iter)
        return None

class MenusModel(gtk.ListStore):
    (
        MENU_NAME,
        MENU_PATH
    ) = range(2)

    def __init__(self):
        gtk.ListStore.__init__(self, str, str)

        self.fill_model(self.get_menus_list())

    def add_menu(self, name, path):
        self.append([name, path])
        return True

    def create_tar_gz(self,directory,destination):
        """This function create a tar.gz file of the directory"""
        import tarfile
        if os.path.exists(destination):
            # We have user confirmation to overwrite.
            os.remove(destination)
        target = tarfile.TarFile.open(destination, "w:gz")
        target.add(directory,arcname=os.path.basename("."))
        target.close()
        return True

    def fill_model(self, list):
        for item in list:
            self.append([item["name"], item["path"]])

    def get_menus_list(self):
        dir_list = []
        for path in ["/etc/edubuntu-menueditor","/usr/share/edubuntu-menueditor/menus"]:
            for dir in os.listdir(path):
                if os.path.isdir(os.path.join(path,dir)):
                    dir_list.append({"name":dir, "path":os.path.join(path,dir)})
        dir_list.sort()
        return dir_list

    def import_archive(self, name, archive_path):
        # this function will create the directory "name" in
        # /etc/edubuntu-menueditor/name then extract files from the archive.
        import tarfile
        dest = os.path.join("/etc/edubuntu-menueditor",name)
        # if the path doesn't exist, create it, else, return False.
        if not os.path.exists(dest):
            tar = tarfile.open(archive_path,"r:gz")
            os.mkdir(dest)
            tar.extractall(dest)
            tar.close()
            for root, dirs, files in os.walk(os.path.join("/etc/edubuntu-menueditor",name)):
                for dir in dirs:
                    os.chown(os.path.join(root,dir),0,0)
                for file in files:
                    os.chown(os.path.join(root,file),0,0)
            os.chmod(dest,0755)
            os.chown(dest,0,0)
            self.add_menu(name,dest)
            return True
        else:
            return False

class GroupsManagerModel(gtk.ListStore):
    (
        GROUP,
        MENU_NAME,
        MENU_PATH,
        XDG_DATA_PATH,
        XDG_CONFIG_PATH,
        FILE_PATH
    ) = range(6)

    def __init__(self,groups_model):
        gtk.ListStore.__init__(self, str, str, str, str, str, str)
        self.COMMENT_STRING="#This file is managed by ProfileManager, Do not edit by hand"
        self.groups_model = groups_model
        self.fill_model(self.file_parser())

    def file_parser(self):
        # my two row in config file will be like the following:
        # type-group-profilename     ;type       ;path                                  ;   ;group  ;COMMENT1
        # XDG_DATA-group-datadir1    ;XDG_DATA   ;/etc/profile-manager/datadir1/share/  ;   ;group  ;COMMENT1
        # XDG_CONFIG-group-datadir1  ;XDG_CONFIG ;/etc/profile-manager/datadir1/xdg/    ;   ;group  ;COMMENT1
        # i need to have :
        # 1- "name" : name
        # test = {row["names"]:{"GROUP":"group","XDG_DATA":"xdg_data_path","XDG_CONFIG":"xdg_config_path","FILE_PATH":file_path}}
        content_dict = {}
        for file in glob.glob("/etc/desktop-profiles/*.listing"):
            with open(file) as content:
                data = {}
                name = ""
                csvreader = csv.DictReader(content,delimiter=";", \
                            fieldnames=["name","type","path","priority","group","comment"])
                for row in csvreader:
                    # is it our file? if yes, parse it.
                    if row["comment"] == self.COMMENT_STRING:
                        # test the name to be consistant
                        if name == "":
                            name = row["name"].split(row["type"] + "-")[1]
                        elif name != row["name"].split(row["type"] + "-")[1]:
                            #TODO: add stuff here to control what append when the name doesn't match.
                            name = ""
                            print "name doesn't match name : %s, row : %s" % (name, row["name"].split(row["type"] + "-")[1])
                        # test the group to be consistant
                        if data.has_key("GROUP"):
                            if not data["GROUP"] == row["group"]:\
                                #TODO: add stuff here to control what appen if the groups doesn't match.
                                break
                                print "Key error, the two groups doesn't match data : %s , row : %s" % (data["GROUP"], row["group"])
                        else:
                            data["GROUP"] = row["group"]
                        # add the file path to the dict
                        if not data.has_key("FILE_PATH"):
                            data["FILE_PATH"] = file

                        data[row["type"]] = row["path"]
                if data.has_key("GROUP") and data.has_key("XDG_DATA") and \
                        data.has_key("XDG_CONFIG") and data.has_key("FILE_PATH") \
                        and name != "":
                    content_dict[name] = data
        return content_dict

    def fill_model(self, dict_data):
        for entry in dict_data:
            #if os.path.dirname(dict_data[entry]["XDG_DATA"] == os.path.dirname(dict_data[entry]["XDG_CONFIG"]:
            menu_path = os.path.dirname(dict_data[entry]["XDG_DATA"])
            menu_name = os.path.basename(menu_path)
            self.append([dict_data[entry]["GROUP"], menu_name, menu_path, \
                dict_data[entry]["XDG_DATA"],dict_data[entry]["XDG_CONFIG"],\
                dict_data[entry]["FILE_PATH"]])
            iter_to_remove = self.groups_model.iter_for_group(dict_data[entry]["GROUP"])
            if iter_to_remove:
                self.groups_model.remove(iter_to_remove)
   
    def cleanup_groups(self):
        iter = self.get_iter_first()
        while iter:
            iter_to_remove = self.groups_model.iter_for_group(self.get_value(iter, self.GROUP))
            if iter_to_remove:
                self.groups_model.remove(iter_to_remove)
            iter = self.iter_next(iter)

    def save_all_new_files(self):
        # if the file exist (self.FILE_PATH), i suppose it's right.
        # if it doesn't, create it!
        iter = self.get_iter_first()
        while iter:
            content = ""
            group = ""
            file = self.get_value(iter, self.FILE_PATH)
            if not os.path.exists(file):
                group = self.get_value(iter, self.GROUP)
                content = "XDG_DATA-"+ group + "-" +self.get_value(iter, self.MENU_NAME) + ";XDG_DATA;" + self.get_value(iter, self.XDG_DATA_PATH) + ";10;" + group + ";" + self.COMMENT_STRING + "\n"
                content += "XDG_CONFIG-" + group + "-" + self.get_value(iter, self.MENU_NAME) + ";XDG_CONFIG;" + self.get_value(iter, self.XDG_CONFIG_PATH) + ";10;" + group + ";" + self.COMMENT_STRING + "\n"
                opened_file = open(file,"w")
                opened_file.write(content)
                opened_file.close()
            iter = self.iter_next(iter)