parent
ff53f288e5
commit
1542dd4b16
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2013 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 __future__
|
||||
|
||||
import gobject
|
||||
|
||||
import dbus
|
||||
import dbus.mainloop.glib
|
||||
from calculate.lib.datavars import DataVars, VariableError
|
||||
from calculate.lib.utils.files import isMount, getRunCommands
|
||||
from calculate.client.client import Client
|
||||
from argparse import ArgumentParser
|
||||
from time import sleep
|
||||
|
||||
class ResourceRemounter:
|
||||
"""
|
||||
Object contains one method for handle 'Resuming' dbus signal.
|
||||
|
||||
'handle_resuming' method checks and remounts user remote resources.
|
||||
"""
|
||||
def __init__(self,dv):
|
||||
self.dv = dv
|
||||
self.dv.defaultModule = 'client'
|
||||
self.client = Client()
|
||||
self.client.clVars = dv
|
||||
|
||||
def handle_resuming(self,statename):
|
||||
print("Restoring remote mounts for user %s"%self.dv.Get('ur_login'))
|
||||
# waiting for the domain
|
||||
for wait in [1,2,5,10]:
|
||||
if self.client.checkDomainServer(
|
||||
self.dv.Get('cl_remote_host'),
|
||||
self.dv.Get('os_net_domain')):
|
||||
break
|
||||
sleep(wait)
|
||||
# check and remount remote resources
|
||||
self.client.mountUserDomainRes(self.dv.Get('ur_login'),
|
||||
self.dv.Get('desktop.ur_password'),
|
||||
int(self.dv.Get('ur_uid')),
|
||||
int(self.dv.Get('ur_gid')),
|
||||
"unix","share","homes","ftp")
|
||||
|
||||
def main(argv):
|
||||
# processing the user argument
|
||||
argp = ArgumentParser(add_help=True)
|
||||
argp.add_argument("user",help="tracked user",metavar="USER")
|
||||
namespace = argp.parse_args(argv[1:])
|
||||
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
# initialization calculate datavars and quitting on an error
|
||||
try:
|
||||
dv = DataVars()
|
||||
dv.importData()
|
||||
dv.flIniFile()
|
||||
dv.Set('ur_login',namespace.user)
|
||||
if dv.Get('desktop.ur_domain_set') == 'off':
|
||||
print("%s isn't a domain user"%namespace.user)
|
||||
sys.exit(0)
|
||||
except VariableError as e:
|
||||
sys.stderr.write(str(e)+'\n')
|
||||
sys.exit(1)
|
||||
|
||||
rm = ResourceRemounter(dv)
|
||||
bus.add_signal_receiver(rm.handle_resuming,dbus_interface="org.freedesktop.UPower",
|
||||
signal_name = "NotifyResume")
|
||||
loop = gobject.MainLoop()
|
||||
context = loop.get_context()
|
||||
while True:
|
||||
# need for dbus processing
|
||||
context.iteration(1)
|
||||
sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv)
|
@ -0,0 +1,25 @@
|
||||
#! /bin/sh
|
||||
# Copyright 2013 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.
|
||||
|
||||
env-update
|
||||
source /etc/profile
|
||||
source /usr/share/calculate/xdm/functions
|
||||
|
||||
if [[ "${DOMAIN_USER}" == "on" ]]
|
||||
then
|
||||
/usr/sbin/cl-client-resume-remount ${USER} &
|
||||
fi
|
||||
|
||||
exit 0
|
@ -0,0 +1,25 @@
|
||||
#! /bin/sh
|
||||
# Copyright 2013 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.
|
||||
|
||||
env-update
|
||||
source /etc/profile
|
||||
source /usr/share/calculate/xdm/functions
|
||||
|
||||
if [[ "${DOMAIN_USER}" == "on" ]]
|
||||
then
|
||||
pkill -f "cl-client-resume-remount ${USER}"
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Reference in new issue