parent
b3f7a7a2ec
commit
31de24cf5a
@ -0,0 +1,85 @@
|
|||||||
|
# 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.
|
||||||
|
# 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 soaplib, sys, time, os
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from soaplib.serializers.primitive import String, Integer, Any, Boolean
|
||||||
|
from soaplib.serializers.clazz import Array, ClassSerializer
|
||||||
|
from soaplib.service import rpc, DefinitionBase
|
||||||
|
from calculate.core.server.api_types import ReturnedMessage
|
||||||
|
from calculate.core.server.api_types import ChoiceValue, Table, Option, Field, \
|
||||||
|
GroupField, ViewInfo, ViewParams
|
||||||
|
from calculate.lib.datavars import VariableError,DataVarsError
|
||||||
|
from calculate.desktop.cl_desktop import DesktopError
|
||||||
|
|
||||||
|
from cl_desktop import Desktop,DataVarsDesktop
|
||||||
|
import cl_desktop
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
|
||||||
|
from calculate.core.server.decorators import Dec
|
||||||
|
from calculate.core.server.func import catchExcept
|
||||||
|
core_method = Dec.core_method
|
||||||
|
setLocalTranslate('cl_desktop3',sys.modules[__name__])
|
||||||
|
import traceback
|
||||||
|
from functools import wraps,WRAPPER_ASSIGNMENTS
|
||||||
|
|
||||||
|
__ = getLazyLocalTranslate(_)
|
||||||
|
|
||||||
|
class DesktopInfo(ClassSerializer):
|
||||||
|
"""Parameters for method install"""
|
||||||
|
ur_login = String
|
||||||
|
cl_verbose_set = String
|
||||||
|
|
||||||
|
Default = Array(String)
|
||||||
|
CheckOnly = Boolean
|
||||||
|
CheckAll = Boolean
|
||||||
|
|
||||||
|
desktopCatchExcept = catchExcept(VariableError,DataVarsError,
|
||||||
|
cl_desktop.DesktopError)
|
||||||
|
|
||||||
|
class Wsdl:
|
||||||
|
"""
|
||||||
|
cl-desktop
|
||||||
|
"""
|
||||||
|
@rpc(Integer, DesktopInfo, _returns = Array(ReturnedMessage))
|
||||||
|
@core_method(category=__('Desktop'),title=__('Configure user'),
|
||||||
|
image='applications-other',
|
||||||
|
gui=True,command='cl-desktop',
|
||||||
|
rights=['userconfigure'])
|
||||||
|
def desktop(self, sid, info):
|
||||||
|
return self.callMethod(sid,info,method_name="desktop",
|
||||||
|
logicClass=Desktop,
|
||||||
|
method="createHome")
|
||||||
|
|
||||||
|
def desktop_vars(self,dv=None):
|
||||||
|
if not dv:
|
||||||
|
dv = DataVarsDesktop()
|
||||||
|
dv.importDesktop()
|
||||||
|
dv.flIniFile()
|
||||||
|
dv.Set('cl_action','desktop',True)
|
||||||
|
dv.addGroup(None,
|
||||||
|
normal=('ur_login','cl_verbose_set',),
|
||||||
|
next_label=_("Configure"))
|
||||||
|
return dv
|
||||||
|
|
||||||
|
@rpc(Integer, ViewParams,_returns = ViewInfo)
|
||||||
|
def desktop_view (self, sid, params):
|
||||||
|
dv = self.get_cache(sid,"desktop","vars")
|
||||||
|
if not dv:
|
||||||
|
dv = self.desktop_vars()
|
||||||
|
else:
|
||||||
|
dv.processRefresh()
|
||||||
|
view = ViewInfo(dv,viewparams=params)
|
||||||
|
self.set_cache(sid, 'desktop', "vars",dv,smart=False)
|
||||||
|
return view
|
@ -0,0 +1,34 @@
|
|||||||
|
#-*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
__app__ = 'calculate-desktop'
|
||||||
|
__version__ = '3.1.0'
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from calculate.lib.datavars import DataVars
|
||||||
|
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||||||
|
setLocalTranslate('cl_desktop3',sys.modules[__name__])
|
||||||
|
|
||||||
|
class DataVarsDesktop(DataVars):
|
||||||
|
"""Variable class for desktop package"""
|
||||||
|
|
||||||
|
def importDesktop(self, **args):
|
||||||
|
"""Import desktop variables"""
|
||||||
|
self.importData()
|
||||||
|
self.importData('calculate.desktop.variables')
|
||||||
|
self.defaultModule = "desktop"
|
@ -0,0 +1,20 @@
|
|||||||
|
#-*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2008-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.
|
||||||
|
# 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 action
|
||||||
|
import desktop
|
||||||
|
|
||||||
|
section = "desktop"
|
@ -0,0 +1,60 @@
|
|||||||
|
#-*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2008-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.
|
||||||
|
# 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
|
||||||
|
import sys
|
||||||
|
from os import path
|
||||||
|
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
|
||||||
|
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||||||
|
setLocalTranslate('cl_desktop3',sys.modules[__name__])
|
||||||
|
|
||||||
|
class VariableAcDesktopMerge(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Action variable which has value "up" for package install and
|
||||||
|
install this package
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
ret = ""
|
||||||
|
action = self.Get("cl_action")
|
||||||
|
if action in ("install","merge"):
|
||||||
|
ret = "up"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
class VariableAcDesktopInstall(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Action variable which has value "up" for install calculate-desktop
|
||||||
|
and "down" for uninstall
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
ret = ""
|
||||||
|
action = self.Get("cl_action")
|
||||||
|
if action in ("install","merge"):
|
||||||
|
ret = "up"
|
||||||
|
elif action == "uninstall":
|
||||||
|
ret = "down"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
class VariableAcDesktopDesktop(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Action variable which has value "up" on user profile setup
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
ret = ""
|
||||||
|
action = self.Get("cl_action")
|
||||||
|
if action in ("desktop",):
|
||||||
|
ret = "up"
|
||||||
|
return ret
|
@ -0,0 +1,150 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from os import path
|
||||||
|
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
|
||||||
|
from calculate.lib.utils.files import readLinesFile
|
||||||
|
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||||||
|
setLocalTranslate('cl_desktop3',sys.modules[__name__])
|
||||||
|
|
||||||
|
class VariableUrJidHost(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Jabber host for user
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
userJid = self.Get("ur_jid")
|
||||||
|
if userJid:
|
||||||
|
return userJid.partition('@')[2]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
class VariableUrDomainSet(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Flag for determining domain user or local
|
||||||
|
"""
|
||||||
|
def getUserDataInFile(self, login, filePasswd):
|
||||||
|
return filter(lambda x: x[0]==login,
|
||||||
|
map(lambda x: x.strip().split(':'),
|
||||||
|
readLinesFile(filePasswd)))
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
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
|
||||||
|
|
||||||
|
class VariableClDesktopXsession(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
User current X session
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
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 \
|
||||||
|
any(x in desktopSession.lower()
|
||||||
|
for x in ("kde","xfce","gnome")):
|
||||||
|
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 ""
|
||||||
|
|
||||||
|
class VariableClDesktopGstData(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
GStreamer data
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
# try import gst
|
||||||
|
try:
|
||||||
|
olderr = os.dup(sys.stderr.fileno())
|
||||||
|
os.close(sys.stderr.fileno())
|
||||||
|
import gst
|
||||||
|
import gst.interfaces
|
||||||
|
except ImportError:
|
||||||
|
gst = None
|
||||||
|
finally:
|
||||||
|
os.dup2(olderr,sys.stderr.fileno())
|
||||||
|
if gst is None:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
outdata = {}
|
||||||
|
try:
|
||||||
|
pipeline = "alsamixer"
|
||||||
|
alsamixer = gst.element_factory_make(pipeline)
|
||||||
|
res = alsamixer.set_state(gst.STATE_PAUSED)
|
||||||
|
if res == gst.STATE_CHANGE_SUCCESS:
|
||||||
|
outdata['device_name'] = alsamixer.get_property("device-name")
|
||||||
|
outdata['long_name'] = alsamixer.get_factory().get_longname()
|
||||||
|
outdata['internal_name'] = filter(str.isalnum,
|
||||||
|
"%s (%s)"%(outdata['device_name'],
|
||||||
|
outdata['long_name']))
|
||||||
|
outdata['channels'] = []
|
||||||
|
for t in alsamixer.list_tracks():
|
||||||
|
if t.flags & gst.interfaces.MIXER_TRACK_OUTPUT:
|
||||||
|
if t.flags & gst.interfaces.MIXER_TRACK_MASTER or \
|
||||||
|
any(x in t.label
|
||||||
|
for x in ("Wave","Front","LFE","Center",
|
||||||
|
"Head","Side","Speaker",
|
||||||
|
"Surround","PCM")):
|
||||||
|
outdata['channels'].append(t.label)
|
||||||
|
if t.flags & gst.interfaces.MIXER_TRACK_MASTER:
|
||||||
|
outdata['master_channel'] = t.label
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return outdata
|
||||||
|
|
||||||
|
class VariableClDesktopGstCard(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Internal card name for xfce mixer
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
return self.Get('cl_desktop_gst_data').get('internal_name','')
|
||||||
|
|
||||||
|
class VariableClDesktopGstMasterchannel(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Master track name
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
return self.Get('cl_desktop_gst_data').get('master_channel','')
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClDesktopXfceMixer(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
List of channel for xfce-perchannel mixer
|
||||||
|
"""
|
||||||
|
def get(self):
|
||||||
|
return "\n".join(
|
||||||
|
map(lambda x:' <value type="string" value="%s" />'%x,
|
||||||
|
self.Get('cl_desktop_gst_data').get('channels',[])))
|
@ -1,154 +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.
|
|
||||||
from cl_desktop import desktop, __app__, __version__
|
|
||||||
from cl_opt import opt
|
|
||||||
import sys
|
|
||||||
from cl_share_cmd import share_cmd
|
|
||||||
|
|
||||||
# Перевод сообщений для программы
|
|
||||||
from cl_lang import lang
|
|
||||||
lang().setLanguage(sys.modules[__name__])
|
|
||||||
|
|
||||||
# Использование программы
|
|
||||||
USAGE = _("%prog [options] user")
|
|
||||||
|
|
||||||
# Коментарии к использованию программы
|
|
||||||
COMMENT_EXAMPLES = _("Create home directory for the user_name")
|
|
||||||
|
|
||||||
# Пример использования программы
|
|
||||||
EXAMPLES = _("%prog user_name")
|
|
||||||
|
|
||||||
# Описание программы (что делает программа)
|
|
||||||
DESCRIPTION = _("Create home directory for the new user account")
|
|
||||||
|
|
||||||
# Опции командной строки
|
|
||||||
CMD_OPTIONS = [{'longOption':"verbose",
|
|
||||||
'help':_("display the template is applied")},
|
|
||||||
{'longOption':"set"},
|
|
||||||
{'longOption':"install",
|
|
||||||
'help':_("install package")},
|
|
||||||
{'longOption':"uninstall",
|
|
||||||
'help':_("uninstall package")},
|
|
||||||
{'longOption':"progress",
|
|
||||||
'help':_("show progress bar for xdm startup")}]
|
|
||||||
|
|
||||||
class desktop_cmd(share_cmd):
|
|
||||||
def __init__(self):
|
|
||||||
# Объект опций командной строки
|
|
||||||
setpos = \
|
|
||||||
filter(lambda x:x[1].get('longOption')=="set",
|
|
||||||
enumerate(CMD_OPTIONS))[0][0]
|
|
||||||
CMD_OPTIONS[setpos] = opt.variable_set[0]
|
|
||||||
self.optobj = opt(\
|
|
||||||
package=__app__,
|
|
||||||
version=__version__,
|
|
||||||
usage=USAGE,
|
|
||||||
examples=EXAMPLES,
|
|
||||||
comment_examples=COMMENT_EXAMPLES,
|
|
||||||
description=DESCRIPTION,
|
|
||||||
option_list=CMD_OPTIONS + opt.variable_view+opt.color_control,
|
|
||||||
check_values=self.checkOpts)
|
|
||||||
# Создаем объект логики
|
|
||||||
self.logicObj = desktop()
|
|
||||||
# Создаем переменные
|
|
||||||
self.logicObj.createClVars()
|
|
||||||
# Названия несовместимых опций
|
|
||||||
self.optionsNamesIncompatible = ["install", "uninstall"]
|
|
||||||
|
|
||||||
def getIncompatibleOptions(self, optObj):
|
|
||||||
"""Получаем несовместимые опции"""
|
|
||||||
retList = []
|
|
||||||
for nameOpt in self.optionsNamesIncompatible:
|
|
||||||
retList.append(getattr(optObj, nameOpt))
|
|
||||||
return retList
|
|
||||||
|
|
||||||
def _getNamesAllSetOptions(self):
|
|
||||||
"""Выдает словарь измененных опций"""
|
|
||||||
setOptDict = self.optobj.values.__dict__.items()
|
|
||||||
defaultOptDict = self.optobj.get_default_values().__dict__.items()
|
|
||||||
return dict(set(setOptDict) - set(defaultOptDict)).keys()
|
|
||||||
|
|
||||||
def getStringIncompatibleOptions(self):
|
|
||||||
"""Форматированная строка несовместимых опций разделенных ','"""
|
|
||||||
listOpt = list(set(self.optionsNamesIncompatible) &\
|
|
||||||
set(self._getNamesAllSetOptions()))
|
|
||||||
return ", ".join(map(lambda x: len(x) == 1 and "'-%s'"%x or "'--%s'"%x,\
|
|
||||||
listOpt))
|
|
||||||
|
|
||||||
def checkOpts(self, optObj, args):
|
|
||||||
"""Проверка опций командной строки"""
|
|
||||||
# Несовместимые опции
|
|
||||||
if len(filter(lambda x: x, self.getIncompatibleOptions(optObj)))>1:
|
|
||||||
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()
|
|
@ -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 ""
|
|
@ -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()
|
|
||||||
|
|
@ -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"}
|
|
@ -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)
|
|
@ -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
|
|
Loading…
Reference in new issue