diff --git a/README b/README index 50d7703..1345743 100644 --- a/README +++ b/README @@ -4,10 +4,10 @@ INSTALL ------- calculate-desktop needs the following library version installed, in order to run: - Python >= 2.5 + Python >= 2.7 python-ldap >= 2.0.0 pyxml >= 0.8 - calculate-lib >= 2.2.24 + calculate-lib >= 3.0.0 To install calculate-desktop, just execute the install script 'setup.py'. Example: diff --git a/data/gtkbg b/data/gtkbg index 741dc15..7489965 100644 --- a/data/gtkbg +++ b/data/gtkbg @@ -21,6 +21,15 @@ import sys import re import subprocess +def select_color(): + try: + if filter(re.compile(r"(cld|cldx|cldg|cmc|cls)-themes-12").search, + os.listdir('/var/db/pkg/media-gfx')): + return "#73a363" + except: + pass + return '#30648b' + if __name__ == "__main__": if gtk.gdk.get_display(): window = gtk.Window(gtk.WINDOW_TOPLEVEL) @@ -43,7 +52,7 @@ if __name__ == "__main__": window.set_border_width(0) window.modify_bg(gtk.STATE_NORMAL, - gtk.gdk.rgb_get_colormap().alloc_color('#30648b')) + gtk.gdk.rgb_get_colormap().alloc_color(select_color())) window.show() pid = os.fork() diff --git a/data/login.d/00init b/data/login.d/00init index 7076476..2e235d4 100644 --- a/data/login.d/00init +++ b/data/login.d/00init @@ -14,7 +14,12 @@ # limitations under the License. # set background color -xsetroot -solid rgb:30/64/8b +if ls /var/db/pkg/media-gfx/cld[-gx]*themes-12* &>/dev/null +then + xsetroot -solid rgb:73/a3/63 +else + xsetroot -solid rgb:30/64/8b +fi if [[ "`ps axeo command | grep 'xdm/xdm --logout' | grep -v grep | \ sed -n -r 's/.* USER=([^ ]+) .*/\1/p'`" == "$USER" ]]; diff --git a/data/logout.d/00init b/data/logout.d/00init index 52c0006..f959375 100644 --- a/data/logout.d/00init +++ b/data/logout.d/00init @@ -14,5 +14,10 @@ # limitations under the License. # set background color -xsetroot -solid rgb:30/64/8b +if ls /var/db/pkg/media-gfx/cld[-gx]*themes-12* &>/dev/null +then + xsetroot -solid rgb:73/a3/63 +else + xsetroot -solid rgb:30/64/8b +fi exit 0 diff --git a/data/xdm b/data/xdm index 3b43c0c..869c33d 100755 --- a/data/xdm +++ b/data/xdm @@ -64,7 +64,7 @@ die_xmes() { } gtk_background(){ - if [[ -n $(env | grep RUNNING_UNDER_GDM=true) ]]; + if [[ -n $(env | grep RUNNING_UNDER_GDM=true) ]] && ls /var/db/pkg/gnome-base/gdm-2* &>/dev/null; then /usr/bin/env python2 /usr/share/calculate/xdm/gtkbg BG_PID=$(ps ax | sed -nr "s/^\s*([0-9]+)\s.*gtkbg$/\1/p") diff --git a/pym/__init__.py b/desktop/__init__.py similarity index 100% rename from pym/__init__.py rename to desktop/__init__.py diff --git a/desktop/cl_desktop.py b/desktop/cl_desktop.py new file mode 100644 index 0000000..6677a82 --- /dev/null +++ b/desktop/cl_desktop.py @@ -0,0 +1,306 @@ +#-*- coding: utf-8 -*- + +# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from os import path +import re +import sys +import pwd +import time +import traceback + +from datavars import DataVarsDesktop, DataVars, __version__,__app__ + +from calculate.lib.cl_template import Template, ProgressTemplate,TemplatesError +from calculate.lib.utils.files import runOsCommand +from calculate.lib.utils.common import getpathenv,appendProgramToEnvFile, \ + removeProgramToEnvFile +from calculate.core.server.func import safetyWrapper + +from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate +setLocalTranslate('cl_desktop3',sys.modules[__name__]) +__ = getLazyLocalTranslate(_) + +class DesktopError(Exception): + """Desktop Error""" + +class share: + """Общие методы""" + # Объект хранения переменных + clVars = False + + def isRoot(self, printError=True): + """Определяет является ли пользователь root""" + if os.getuid() == 0 and os.getgid() == 0: + return True + else: + if printError: + self.printERROR(_("The user is not root")) + return False + + def createClVars(self, clVars=False): + """Создает объект Vars""" + if not clVars: + clVars = DataVarsDesktop() + # Импортируем переменные + clVars.importDesktop() + # Заменяем значения переменных переменными из env файлов + clVars.flIniFile() + # Устанавливаем у объекта атрибут объект переменных + self.clVars = clVars + return True + + def applyTemplatesFromSystem(self): + """Применяем шаблоны для cистемы""" + # Cоздаем объект обработки шаблонов + clTempl = template(self.clVars) + # Объединяем шаблоны + dirsFiles = clTempl.applyTemplates() + if clTempl.getError(): + self.printERROR(clTempl.getError().strip()) + return False + else: + return dirsFiles + +class Desktop(share): + """Методы работы с профилем пользователя""" + # Имя пользователя + userName = "" + verbose = False + + def __init__(self): + self.homeDir = "" + self.clTempl = None + self.clVars = None + +# def installProg(self,dv): +# """Наложение шаблонов на систему при инсталяции""" +# # Проверяем на root +# if not self.isRoot(): +# return False +# self.clVars.AppendToList("cl_merges", __app__, force=True) +# # Действие инсталяция +# self.clVars.Set("cl_action", "install", True) +# if not self.applyTemplatesFromSystem(): +# raise DesktopError(_("Failed to apply install templates")) +# # Добавление программы в инсталяционную переменную +# if not appendProgramToEnvFile(__app__, self.clVars): +# self.printERROR(_("Failed to save '%s'") %__app__ + " " +\ +# _("to %s") %self.clVars.Get("cl_env_path")[0]) +# return False +# self.printOK(_("Install templates applied")) +# return True +# +# def uninstallProg(self): +# """Наложение шаблонов на систему при деинсталяции""" +# # Проверяем на root +# if not self.isRoot(): +# return False +# # Действие деинсталяция +# self.clVars.Set("cl_action", "uninstall", True) +# if not self.applyTemplatesFromSystem(): +# self.printERROR(_("Failed to apply uninstall templates")) +# return False +# # Удаление программы из инсталяционной переменной +# if not removeProgramToEnvFile(__app__, self.clVars): +# self.printERROR(_("Failed to remove '%(app)s' from %(path)s")% +# {'app':__app__, +# 'path': self.clVars.Get("cl_env_path")[0]}) +# return False +# self.printOK(_("Uninstall templates applied")) +# return True + + def createUserDir(self, uid, gid, userDir, mode=0700): + """ + Create user directory with need uid and gid + """ + if not path.exists(userDir): + os.makedirs(userDir) + if mode: + os.chmod(userDir,mode) + os.chown(userDir,uid,gid) + return True + else: + raise DesktopError(_("Path %s exists") %userDir) + + def displayTemplatesApplied(self,dirsFiles): + """ + Display templates are applied (--verbose) + """ + self.printWARNING(_("The following files were changed")+":") + for nameF in dirsFiles[1]: + nameFile = nameF + if nameFile[:1] != "/": + nameFile = "/" + nameFile + self.printWARNING(" "*5 + nameFile) + + def applyTemplatesFromUser(self): + """Применяем шаблоны для пользователя""" + if self.clTempl: + self.closeClTemplate() + self.clTempl = ProgressTemplate(self.setProgress,self.clVars, + cltObj=False) + dirsFiles = self.clTempl.applyTemplates() + if self.clTempl.getError(): + self.printERROR(self.clTempl.getError().strip()) + return False + else: + if self.verbose: + self.displayTemplatesApplied(dirsFiles) + return dirsFiles + + def initVars(self,datavars=None): + """Primary variables initialization""" + if not datavars: + self.clVars = DataVarsDesktop() + self.clVars.importDesktop() + self.clVars.flIniFile() + else: + self.clVars = datavars + + def closeClTemplate(self): + if self.clTempl: + if self.clTempl.cltObj: + self.clTempl.cltObj.closeFiles() + self.clTempl.closeFiles() + self.clTempl = None + + def umountUserRes(self, error): + """Отмонтируем пользовательские директории если они есть""" + self.closeClTemplate() + if error and self.homeDir: + umountPaths = self.getMountUserPaths(self.homeDir) + ret = True + for umountPath in umountPaths: + if not self.umountSleepPath(umountPath): + ret = False + break + return ret + + @safetyWrapper(native_errors=(TemplatesError,DesktopError), + man_int=__("Configuration manually interrupted"), + post_action=umountUserRes) + def createHome(self, datavars=None): + """ + Creating user profile and userdir + """ + self.initVars(datavars) + self.verbose = self.clVars.Get('cl_verbose_set') == 'on' + #uid = os.getuid() + #try: + # realUserName = pwd.getpwuid(uid).pw_name + #except: + # realUserName = "" + userName = self.clVars.Get("ur_login") + #if userName != realUserName and not self.isRoot(): + # return False + uidGid = False + if self.clVars.isModuleInstalled("client"): + import ipdb + ipdb.set_trace() + # domain host + domain = self.clVars.Get("client.cl_remote_host") + # authorized in domain or local + hostAuth = self.clVars.Get("client.os_remote_auth") + else: + domain = "" + hostAuth = "" + uid = self.clVars.Get('ur_uid') + gid = self.clVars.Get('ur_gid') + if not uid or not gid: + raise DesktopError(_("Failed to determine user UID")) + uid,gid = int(uid),int(gid) + + self.homeDir = self.clVars.Get('ur_home_path') + rootPath = self.clVars.Get('cl_root_path') + # real path to home dir + self.homeDir = path.join(rootPath, self.homeDir[1:]) + if not path.exists(self.homeDir): + self.startTask(_("Creating the home directory for %s")%self.homeDir) + self.createUserDir(uid,gid,self.homeDir) + self.endTask() + # Действие - шаблоны пользователя + self.clVars.Set("cl_action", "desktop", True) + # Применяем профили для пользователя + self.startTask(_("Setting up the user profile"),progress=True) + dirsAndFiles = self.applyTemplatesFromUser() + self.endTask() + if not dirsAndFiles: + # Отмонтируем пользовательские ресурсы в случае ошибки + raise DesktopError(_("Failed to apply user profile templates")) + self.printSUCCESS(_("User account %s is configured")%userName + " ...") + return True + + def getMountUserPaths(self, homeDir=False): + """Находит пользовательские примонтированные пути""" + # Имя пользователя + if not homeDir: + userName = self.clVars.Get("ur_login") + homeDir = self.clVars.Get("ur_home_path") + if not homeDir: + raise DesktopError(_("Failed to determine home directory")) + dirStart, dirEnd = path.split(homeDir) + mountProfileDir = path.join(dirStart, ".%s" %dirEnd) + mountRemoteProfileDir = path.join(dirStart, ".%s.remote" %dirEnd) + return filter(lambda x: x.startswith(homeDir) or\ + x.startswith(mountProfileDir) or\ + x.startswith(mountRemoteProfileDir), + map(lambda x: x.split(" ")[1],\ + open("/proc/mounts").readlines())) + + def execProg(self, cmdStrProg, inStr=False, envProg={}): + """Выполняет внешнюю программу + + Параметры: + cmdStrProg внешняя программа + inStr данные передаваемые программе на страндартный вход. + Возвращаемые параметры: + строки которые выведет внешняя программа или False в случае ошибки + """ + env_path = {"PATH":getpathenv()} + env = {} + env.update(os.environ.items() + env_path.items() + envProg.items()) + retCode,programOut = runOsCommand(cmdStrProg,in_str=inStr,env_dict=env) + if not retCode: + return programOut + return False + + + def umountSleepPath(self, umountpath): + """Отмонтирует путь при неудаче задержка потом повтор""" + # Задержки при отмонтированиии директории + sleeps = [0.5, 2, 5] + # Проверяем на монтирование директорию + if path.ismount(umountpath): + textLine = self.execProg("umount %s"%umountpath) + if textLine is False: + i = 0 + flagError = False + while (i'%x, + self.Get('cl_desktop_gst_data').get('channels',[]))) diff --git a/pym/cl_desktop.py b/pym/cl_desktop.py deleted file mode 100644 index 3c8fdd4..0000000 --- a/pym/cl_desktop.py +++ /dev/null @@ -1,327 +0,0 @@ -#-*- coding: utf-8 -*- - -# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -__version__ = "2.2.24" -__app__ = "calculate-desktop" - -import os -import re -import sys -import pwd -import time - -from cl_lang import lang -from cl_template import template -from cl_datavars import DataVars -from cl_print import color_print -from client.progressbar import ProgressBar -from cl_utils import runOsCommand, getpathenv, appendProgramToEnvFile,\ - removeProgramToEnvFile - -lang().setLanguage(sys.modules[__name__]) - -class DataVarsDesktop(DataVars): - """Хранение переменных""" - - def importDesktop(self, **args): - '''Импорт переменных для десктопа''' - # Имя секции в calculate2.env - envSection = "desktop" - # импорт переменных - self.importData(envSection, ('cl_vars_desktop','cl_fill_desktop')) - -class ProgressTemplate(template): - def __init__(self, vars): - template.__init__(self, vars) - self.progress = ProgressBar(_("Setting up user profile") + " ...") - - def numberAllTemplates(self, number): - self.progress.setMaximum(number) - return True - - def numberProcessTemplates(self,number): - self.progress.setValue(number) - return True - - def close(self): - self.progress.shutdownDialog() - -class share(color_print): - """Общие методы""" - # Объект хранения переменных - clVars = False - - def isRoot(self, printError=True): - """Определяет является ли пользователь root""" - if os.getuid() == 0 and os.getgid() == 0: - return True - else: - if printError: - self.printERROR(_("The user is not root")) - return False - - def createClVars(self, clVars=False): - """Создает объект Vars""" - if not clVars: - clVars = DataVarsDesktop() - # Импортируем переменные - clVars.importDesktop() - # Заменяем значения переменных переменными из env файлов - clVars.flIniFile() - # Устанавливаем у объекта атрибут объект переменных - self.clVars = clVars - return True - - def applyTemplatesFromSystem(self): - """Применяем шаблоны для cистемы""" - # Cоздаем объект обработки шаблонов - clTempl = template(self.clVars) - # Объединяем шаблоны - dirsFiles = clTempl.applyTemplates() - if clTempl.getError(): - self.printERROR(clTempl.getError().strip()) - return False - else: - return dirsFiles - - def printVars(self, *arg, **argv): - """Печать существующих переменных""" - self.clVars.printVars(*arg, **argv) - -class desktop(share): - """Методы работы с профилем пользователя""" - # Имя пользователя - userName = "" - verbose = False - - def installProg(self): - """Наложение шаблонов на систему при инсталяции""" - # Проверяем на root - if not self.isRoot(): - return False - self.clVars.AppendToList("cl_merges", __app__, force=True) - # Действие инсталяция - self.clVars.Set("cl_action", "install", True) - if not self.applyTemplatesFromSystem(): - self.printERROR(_("Can not apply install templates")) - return False - # Добавление программы в инсталяционную переменную - if not appendProgramToEnvFile(__app__, self.clVars): - self.printERROR(_("Can not save '%s'") %__app__ + " " +\ - _("to %s") %self.clVars.Get("cl_env_path")[0]) - return False - self.printOK(_("Apply install templates")) - return True - - def uninstallProg(self): - """Наложение шаблонов на систему при деинсталяции""" - # Проверяем на root - if not self.isRoot(): - return False - # Действие деинсталяция - self.clVars.Set("cl_action", "uninstall", True) - if not self.applyTemplatesFromSystem(): - self.printERROR(_("Can not apply uninstall templates")) - return False - # Удаление программы из инсталяционной переменной - if not removeProgramToEnvFile(__app__, self.clVars): - self.printERROR(_("Can not remove '%(app)s' to %(path)s")% - {'app':__app__, - 'path': self.clVars.Get("cl_env_path")[0]}) - return False - self.printOK(_("Apply uninstall templates")) - return True - - def existsUser(self, userName): - """Существует ли пользователь""" - try: - pwd.getpwnam(userName).pw_gid - except: - self.printERROR(_("User %s not exists")%userName) - return False - return True - - def createUserDir(self, uid, gid, userDir, mode=0700): - """Создание пользовательской директории""" - if not os.path.exists(userDir): - os.makedirs(userDir) - if mode: - os.chmod(userDir,mode) - os.chown(userDir,uid,gid) - return True - else: - self.printERROR(_("Path %s exists") %userDir) - return False - - def displayTemplatesApplied(self,dirsFiles): - """ - Display templates are applied (--verbose) - """ - self.printWARNING(_("Following files were changed")+":") - for nameF in dirsFiles[1]: - nameFile = nameF - if nameFile[:1] != "/": - nameFile = "/" + nameFile - self.printWARNING(" "*5 + nameFile) - - def applyTemplatesFromUser(self, progress=False): - """Применяем шаблоны для пользователя""" - # Cоздаем объект обработки шаблонов - if progress: - clTempl = ProgressTemplate(self.clVars) - else: - clTempl = template(self.clVars,cltObj=False) - # Объединяем шаблоны - dirsFiles = clTempl.applyTemplates() - if progress: - clTempl.close() - if clTempl.getError(): - self.printERROR(clTempl.getError().strip()) - return False - else: - if self.verbose: - self.displayTemplatesApplied(dirsFiles) - return dirsFiles - - def createHome(self, progress=False, verbose=False): - """Создание профиля пользователя (пользовательской директории)""" - # Имя пользователя - self.verbose = verbose - uid = os.getuid() - try: - realUserName = pwd.getpwuid(uid).pw_name - except: - realUserName = "" - userName = self.clVars.Get("ur_login") - if userName != realUserName and not self.isRoot(): - return False - uidGid = False - # Домен для подключения Samba - domain = self.clVars.GetIniVar("client.cl_remote_host") - # Авторизация в домененe или локально - hostAuth = self.clVars.GetIniVar("client.os_remote_auth") - try: - passwdUsers = map(lambda x: x[0], - map(lambda x: x.split(':'), - map(lambda x: x.strip(), - open("/etc/passwd").readlines()))) - except: - self.printERROR("Can not open /etc/passwd") - return False - try: - pwdInfo = pwd.getpwnam(userName) - except: - self.printERROR(_("Can not found user %s") %userName) - self.umountUserRes() - return False - uid = pwdInfo.pw_uid - gid = pwdInfo.pw_gid - homeDir = pwdInfo.pw_dir - # Создаем пользовательскую директорию - rootPath = self.clVars.Get('cl_root_path') - # Реальный путь к домашней директории - homeDir = os.path.join(rootPath, homeDir[1:]) - # Домашняя директория существует - flagHomeExists = True - # Создаем домашнюю директорию если ее нет - if not os.path.exists(homeDir): - flagHomeExists = False - self.createUserDir(uid, gid, homeDir) - # Действие - шаблоны пользователя - self.clVars.Set("cl_action", "desktop", True) - # Применяем профили для пользователя - dirsAndFiles = self.applyTemplatesFromUser(progress) - if not dirsAndFiles: - # Отмонтируем пользовательские ресурсы в случае ошибки - self.printERROR(_("Can not apply user profile")) - self.umountUserRes(homeDir) - return False - if not flagHomeExists: - self.printSUCCESS(_("Created home dir %s")%homeDir + " ...") - self.printSUCCESS(_("User account %s is configured")%userName + " ...") - return True - - - def getMountUserPaths(self, homeDir=False): - """Находит пользовательские примонтированные пути""" - # Имя пользователя - if not homeDir: - userName = self.clVars.Get("ur_login") - try: - homeDir = pwd.getpwnam(userName).pw_dir - except: - homeDir = os.path.join("/home",userName) - dirStart, dirEnd = os.path.split(homeDir) - mountProfileDir = os.path.join(dirStart, ".%s" %dirEnd) - mountRemoteProfileDir = os.path.join(dirStart, ".%s.remote" %dirEnd) - return filter(lambda x: x.startswith(homeDir) or\ - x.startswith(mountProfileDir) or\ - x.startswith(mountRemoteProfileDir), - map(lambda x: x.split(" ")[1],\ - open("/proc/mounts").readlines())) - - def execProg(self, cmdStrProg, inStr=False, envProg={}): - """Выполняет внешнюю программу - - Параметры: - cmdStrProg внешняя программа - inStr данные передаваемые программе на страндартный вход. - Возвращаемые параметры: - строки которые выведет внешняя программа или False в случае ошибки - """ - env_path = {"PATH":getpathenv()} - env = {} - env.update(os.environ.items() + env_path.items() + envProg.items()) - retCode,programOut = runOsCommand(cmdStrProg,in_str=inStr,env_dict=env) - if not retCode: - return programOut - return False - - - def umountSleepPath(self, path): - """Отмонтирует путь при неудаче задержка потом повтор""" - # Задержки при отмонтированиии директории - sleeps = [0.5, 2, 5] - # Проверяем на монтирование директорию - if os.path.ismount(path): - textLine = self.execProg("umount %s"%path) - if textLine is False: - i = 0 - flagError = False - while (i1: - errMsg = _("incompatible options")+":"+" %s"\ - %self.getStringIncompatibleOptions() - self.optobj.error(errMsg) - return False - if optObj.v or optObj.filter or optObj.xml: - if args: - if len(args)>1: - errMsg = _("incorrect argument")+":" + " %s" %" ".join(args) - self.optobj.error(errMsg) - return False - userName = args[0] - # Проверка на существование пользователя - if not self.logicObj.existsUser(userName): - return False - elif optObj.install or optObj.uninstall: - if args: - errMsg = _("invalid argument") + ":" + " %s" %" ".join(args) - self.optobj.error(errMsg) - return False - else: - if not args: - errMsg = _("no such argument")+":"+" %s" %USAGE.split(" ")[-1] - self.optobj.error(errMsg) - return False - if len(args)>1: - errMsg = _("incorrect argument") + ":" + " %s" %" ".join(args) - self.optobj.error(errMsg) - return False - if not optObj.v: - if optObj.filter: - errMsg = _("incorrect option") + ":" + " %s" %"--filter" +\ - ": " + _("use with option '-v'") - self.optobj.error(errMsg) - return False - if optObj.xml: - errMsg = _("incorrect option") + ":" + " %s" %"--xml" +\ - ": " + _("use with option '-v'") - self.optobj.error(errMsg) - return False - return optObj, args - - def setUserName(self, userName): - """Установка имени пользователя""" - # Проверка на существование пользователя - if not self.logicObj.existsUser(userName): - return False - self.logicObj.clVars.Set("ur_login", userName, True) - return True - - def createHome(self, optObj): - """Создание домашней директории""" - return self.logicObj.createHome(optObj.progress, optObj.verbose) - - def install(self): - """Инсталяция программы""" - return self.logicObj.installProg() - - def uninstall(self): - """Удаление программы""" - return self.logicObj.uninstallProg() diff --git a/pym/cl_fill_desktop.py b/pym/cl_fill_desktop.py deleted file mode 100644 index 9637744..0000000 --- a/pym/cl_fill_desktop.py +++ /dev/null @@ -1,111 +0,0 @@ -#-*- coding: utf-8 -*- - -# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import re -import os - -class fillVars(): - """Методы определения значений переменных шаблона""" - - def getUserDataInFile(self, login, filePasswd): - return filter(lambda x: x[0]==login, - map(lambda x: x.split(':'), - map(lambda x: x.strip(), - open(filePasswd).readlines()))) - - def get_ur_jid_host(self): - """Host Jabber пользователя""" - userJid = self.Get("ur_jid") - if userJid: - return userJid.partition('@')[2] - return "" - - def get_ac_desktop_install(self): - """переключатель для шаблонов инсталяции и удаления программы""" - ret = "" - action = self.Get("cl_action") - if action in ("install","merge"): - ret = "up" - elif action == "uninstall": - ret = "down" - return ret - - def get_ac_desktop_merge(self): - """переключатель для шаблонов merge""" - ret = "" - action = self.Get("cl_action") - if action in ("install","merge"): - ret = "up" - return ret - - def get_ac_desktop_desktop(self): - """переключатель для шаблонов создания пользовательского профиля""" - ret = "" - action = self.Get("cl_action") - if action in ("desktop",): - ret = "up" - return ret - - def get_ur_domain_set(self): - '''доменный пользователь "on", "off"''' - ret = "off" - userName = self.Get("ur_login") - if userName: - try: - passwdUserData = self.getUserDataInFile(userName, "/etc/passwd") - except: - return ret - if passwdUserData: - passwdUserData = passwdUserData[0] - try: - cacheUserData = self.getUserDataInFile(userName, - "/var/lib/calculate/calculate-client/cache/passwd") - except: - return ret - if cacheUserData: - cacheUserData = cacheUserData[0] - if cacheUserData == passwdUserData: - ret = "on" - else: - ret = "on" - return ret - - def get_cl_desktop_xsession(self): - """Current session""" - envXsessionFile = "/etc/env.d/90xsession" - xsession = os.environ.get("XSESSION",None) - desktopSession = os.environ.get("DESKTOP_SESSION",None) - if not xsession: - if os.path.exists(envXsessionFile): - xsession = \ - map(lambda x:x.partition("=")[2].strip("'\""), - filter(lambda x:x.startswith("XSESSION="), - filter(lambda x:not x.startswith("#"), - open(envXsessionFile,"r")))) - if xsession: - xsession = xsession[-1] - if xsession: - if desktopSession and desktopSession.lower() != "default": - xsession = desktopSession - if "kde" in xsession.lower(): - return "kde" - elif "gnome" in xsession.lower(): - return "gnome" - elif "xfce" in xsession.lower(): - return "xfce" - else: - return xsession.lower() - return "" diff --git a/pym/cl_share_cmd.py b/pym/cl_share_cmd.py deleted file mode 100644 index e4d7c8c..0000000 --- a/pym/cl_share_cmd.py +++ /dev/null @@ -1,80 +0,0 @@ -#-*- coding: utf-8 -*- - -# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -from cl_print import color_print -from cl_utils import _error - -# Перевод сообщений для программы -from cl_lang import lang -lang().setLanguage(sys.modules[__name__]) - -class share_cmd(color_print, _error): - """Класс общих методов обработки опций командной строки""" - - def printVars(self, optObj): - """Печать переменных""" - if optObj.v: - varsFilter = None - varsNames = [] - format = "default" - # Фильтрование переменных - if optObj.filter: - optCmd = optObj.filter - if ',' in optCmd: - varsNames = optCmd.split(",") - else: - varsFilter = optCmd - if optObj.xml: - format = "xml" - try: - v = int(optObj.v) - except: - v = 1 - self.logicObj.printVars(varsFilter, varsNames, outFormat=format, - verbose=v) - - def setVars(self, optObj): - """Установка переменных""" - if optObj.set: - for val in optObj.set: - k,o,v = val.partition('=') - if self.logicObj.clVars.exists(k): - if self.logicObj.clVars.SetWriteVar(k,v) == False: - return False - else: - self.printERROR(_('variable %s not found')%k) - return False - return True - - def writeVars(self, optObj): - """Запись переменных""" - if optObj.set: - if not self.logicObj.clVars.WriteVars(): - errMsg = self.getError() - if errMsg: - self.printERROR(errMsg.strip()) - self.printERROR(_('Can not write template variables')) - return False - return True - - def setPrintNoColor(self, optObj): - """Установка печати сообщений без цвета""" - if optObj.color and optObj.color=="never": - color_print.colorPrint = lambda *arg : sys.stdout.write(arg[-1]) or\ - sys.stdout.flush() - diff --git a/pym/cl_vars_desktop.py b/pym/cl_vars_desktop.py deleted file mode 100644 index bcd6715..0000000 --- a/pym/cl_vars_desktop.py +++ /dev/null @@ -1,92 +0,0 @@ -#-*- coding: utf-8 -*- - -# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#Допустимые ключи -# mode - режим переменной r-не переназначается из командной строки, -# w-переназначается из командной строки -# type - тип переменной состоит из двух элементов(что это и для чего -# это) -# value - значение переменной по умолчанию -# hide - флаг того, что данная переменная служебная и не отображается -# при печати списка значений переменных - -from cl_desktop import __version__ -from cl_desktop import __app__ - -class Data: - # имя программы - cl_name = {'value':__app__} - - # версия программы - cl_ver = {'value':__version__} - - #Логин пользователя - ur_login = {'mode':"r"} - - #Название группы пользователя - ur_group = {'mode':"r"} - - #Полное имя пользователя - ur_fullname = {'mode':"r"} - - # Jabber ID пользователя - ur_jid = {'mode':"r"} - - # Почтовый адрес пользователя - ur_mail = {'mode':"r"} - - # Домашняя директория пользователя - ur_home_path = {'mode':"r"} - - # Host Jabber пользователя - ur_jid_host = {'mode':"w"} - - # переключатель для шаблонов merge - ac_desktop_merge = {} - - # переключатель для шаблонов инсталяции и удаления программы - ac_desktop_install = {} - - # переключатель для шаблонов создания пользовательского профиля - ac_desktop_desktop = {} - - # доменный пользователь "on", "off" - ur_domain_set = {} - - # user current X session - cl_desktop_xsession = {} - - # lib vars - cl_env_path = {} - cl_root_path = {'mode':"w"} - hr_laptop = {} - hr_laptop_model = {} - hr_virtual = {} - os_linux_name = {} - os_linux_shortname = {} - os_linux_subname = {} - os_linux_ver = {} - os_locale_lang = {} - os_locale_language = {} - os_locale_xkb = {} - os_locale_xkbname = {} - os_net_hostname = {'mode':"w"} - os_root_type = {} - os_x11_composite = {} - os_x11_height = {'mode':"w"} - os_x11_standart = {} - os_x11_video_drv = {} - os_x11_width = {'mode':"w"} diff --git a/scripts/cl-desktop b/scripts/cl-desktop deleted file mode 100644 index ae82f23..0000000 --- a/scripts/cl-desktop +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- - -# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -sys.path.insert(0,os.path.abspath('/usr/lib/calculate-2.2/calculate-lib/pym')) -sys.path.insert(0,\ - os.path.abspath('/usr/lib/calculate-2.2/calculate-desktop/pym')) - -from cl_lang import lang -tr = lang() -tr.setGlobalDomain('cl_desktop') -tr.setLanguage(sys.modules[__name__]) - -from cl_desktop_cmd import desktop_cmd - -if __name__ == "__main__": - obj = desktop_cmd() - ret = obj.optobj.parse_args() - if ret is False: - sys.exit(1) - opts, args = ret - if len(args) > 0: - userName = args[0] - else: - userName = "" - # Установка цвета при печати сообщений - obj.setPrintNoColor(opts) - if userName: - # Установка имени пользователя - if not obj.setUserName(userName): - sys.exit(1) - # Установка переменных - if not obj.setVars(opts): - sys.exit(1) - # Печать переменных - obj.printVars(opts) - # Если нет печати переменных выполняем логику программы - if not opts.v and not opts.filter and not opts.xml: - if opts.install: - # Наложение шаблонов на систему при инсталяции - if not obj.install(): - sys.exit(1) - elif opts.uninstall: - # Наложение шаблонов на систему при деинсталяции - if not obj.uninstall(): - sys.exit(1) - elif userName: - # Создаем домашнюю директорию, и применяем шаблоны - if not obj.createHome(opts): - sys.exit(1) - # Запись переменных - if not obj.writeVars(opts): - sys.exit(1) - sys.exit(0) diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index a584652..0000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[install] -install-scripts=/usr/bin -install-purelib=/usr/lib/calculate-2.2 -install-platlib=/usr/lib/calculate-2.2 -#install-data=/usr/share/calculate/templates diff --git a/setup.py b/setup.py index 176c5f6..e0575de 100755 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -# setup.py --- Setup script for calculate-client +# setup.py --- Setup script for calculate-desktop -#Copyright 2010 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,18 +17,31 @@ # See the License for the specific language governing permissions and # limitations under the License. +__app__ = "calculate-desktop" +__version__ = "3.0.0" + import os import stat -from distutils.core import setup +from distutils.core import setup, Extension from distutils.command.install_data import install_data - - -__app__ = "calculate-desktop" -__version__ = "2.2.24" +import distutils.command.build +import distutils.command.install +from os import system,path +import glob +import sys data_files = [] -var_data_files = [] +data_files += [('/usr/share/calculate/xdm', ['data/cmd_login', + 'data/functions', + 'data/gtkbg', + 'data/xdm'])] + \ + [('/usr/share/calculate/xdm/login.d', + ['data/login.d/00init', + 'data/login.d/20desktop', + 'data/login.d/99final'])] + \ + [('/usr/share/calculate/xdm/logout.d', + ['data/logout.d/00init'])] def __scanDir(scanDir, prefix, replace_dirname, dirData, flagDir=False): """Scan directory""" @@ -50,7 +63,7 @@ def __scanDir(scanDir, prefix, replace_dirname, dirData, flagDir=False): scanDir = os.path.join(prefix,scanDir) dirData.append((scanDir, files)) for sDir in dirs: - __scanDir(sDir, prefix, replace_dirname, dirData, True) + __scanDir(sDir, prefix, replace_dirname,dirData, True) return dirData def create_data_files(data_dirs, prefix="", replace_dirname=""): @@ -61,18 +74,6 @@ def create_data_files(data_dirs, prefix="", replace_dirname=""): data_files += __scanDir(data_dir, prefix, replace_dirname, data) return data_files -data_files += [('/usr/share/calculate/xdm', ['data/cmd_login', - 'data/functions', - 'data/gtkbg', - 'data/xdm'])] +\ - [('/usr/share/calculate/xdm/login.d', - ['data/login.d/00init', - 'data/login.d/20desktop', - 'data/login.d/99final'])] +\ - [('/usr/share/calculate/xdm/logout.d', - ['data/logout.d/00init'])] - - class cl_install_data(install_data): def run (self): install_data.run(self) @@ -80,7 +81,8 @@ class cl_install_data(install_data): ("/usr/share/calculate/xdm/cmd_login",0755), ("/usr/share/calculate/xdm/xdm",0755)] fileNames = map(lambda x: os.path.split(x[0])[1], data_file) - listNames = map(lambda x: filter(lambda y: y, x[0].split("/")),data_file) + listNames = map(lambda x: filter(lambda y: y, x[0].split("/")), + data_file) data_find = {} for i in range(len(fileNames)): listNames[i].reverse() @@ -102,18 +104,15 @@ class cl_install_data(install_data): if flagFound: os.chmod(path, mode) - setup( - name = __app__, - version = __version__, + name = 'calculate-desktop', + version = "3.0.0_alpha1", description = "Create and configure user profile", author = "Calculate Ltd.", author_email = "support@calculate.ru", url = "http://calculate-linux.org", license = "http://www.apache.org/licenses/LICENSE-2.0", - package_dir = {'calculate-desktop': "."}, - packages = ['calculate-desktop.pym'], + package_dir = {'calculate.desktop': "desktop"}, + packages = ['calculate.desktop','calculate.desktop.variables'], data_files = data_files, - scripts=["./scripts/cl-desktop"], - cmdclass={'install_data': cl_install_data}, -) + cmdclass={'install_data': cl_install_data})