import urllib from gi.repository import Nautilus,GObject import pwd import getpass import grp import subprocess import os import os.path import locale import gettext #locale.textdomain("lliurex-homework-harvester") #gettext.textdomain("lliurex-homework-harvester") #_=locale.gettext def get_translation(line): try: trans={} trans["Restore teacher access"]={} trans["Restore teacher access"]["es"]="Restaurar acceso a profesor/a" trans["Restore teacher access"]["qcv"]="Restaurar acceso a profesor/a" lng=os.getenv("LANG") if lng.find("ca")==0 or lng.find("qcv")==0: try: ret_line=trans[line]["qcv"] return ret_line except: return line if lng.find("es")==0: try: ret_line=trans[line]["es"] return ret_line except: return line else: return line except: return line #def get_translation _=get_translation class LlxRestoreTeacherAccessExtension(GObject.GObject,Nautilus.MenuProvider): def __init__(self): self.file_list=[] #def init def get_groups(self,user): groups=[] for g in grp.getgrall(): if user in g.gr_mem: groups.append(g.gr_name) return groups #def get_groups def teachers_cb(self,menu,path): command=[] command.append("/usr/bin/llx-restore-teacher-access") command.append(path) subprocess.Popen(command,stdout=subprocess.PIPE) #def teachers_cb def get_file_items(self, window, files): file_list=[] for file in files: filename = urllib.unquote(file.get_uri()[7:]) file_list.append(str(filename)) user=getpass.getuser() group_list=self.get_groups(user) if len(file_list)<1: return if "teachers" in group_list or "adm" in group_list or "admins" in group_list: item = Nautilus.MenuItem(name='Nautilus::restore_teacher', label=_('Restore teacher access'), tip=_('Restore teacher access to student files'), icon='dialog-password') item.connect('activate', self.teachers_cb, file_list[0]) return item, else: return