forked from shaba/openuds
* Added logger and first simple tests worked :)
This commit is contained in:
parent
1f519308a1
commit
449b3df02a
@ -68,6 +68,12 @@
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>101</width>
|
||||
@ -93,6 +99,12 @@
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>111</width>
|
||||
@ -115,7 +127,7 @@
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>361</width>
|
||||
<height>131</height>
|
||||
<height>146</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
|
@ -12,9 +12,9 @@ def testRest():
|
||||
print "Intefaces: ", list(operations.getNetworkInfo())
|
||||
print "Joined Domain: ", operations.getDomainName()
|
||||
|
||||
#renameComputer('win7-64')
|
||||
#joinDomain('dom.dkmon.com', 'ou=pruebas_2,dc=dom,dc=dkmon,dc=com', 'administrador@dom.dkmon.com', 'Temporal2012', True)
|
||||
#reboot()
|
||||
# renameComputer('win7-64')
|
||||
# joinDomain('dom.dkmon.com', 'ou=pruebas_2,dc=dom,dc=dkmon,dc=com', 'administrador@dom.dkmon.com', 'Temporal2012', True)
|
||||
# reboot()
|
||||
r = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'], scrambledResponses=True)
|
||||
print "Connected: {}".format(r.isConnected)
|
||||
r.test()
|
||||
@ -30,14 +30,15 @@ def testRest():
|
||||
|
||||
print 'uuid = {}'.format(uuid)
|
||||
|
||||
#print 'Login: {}'.format(r.login('test-user'))
|
||||
#print 'Logout: {}'.format(r.logout('test-user'))
|
||||
# print 'Login: {}'.format(r.login('test-user'))
|
||||
# print 'Logout: {}'.format(r.logout('test-user'))
|
||||
print "Information: >>{}<<".format(r.information())
|
||||
print "Login: >>{}<<".format(r.login('Pepito'))
|
||||
|
||||
print r.setReady([(v.mac, v.ip) for v in operations.getNetworkInfo()])
|
||||
print r.log(10000, 'Test error message')
|
||||
|
||||
|
||||
def ipcTest():
|
||||
from udsactor import ipc
|
||||
from time import sleep
|
||||
@ -80,15 +81,15 @@ def ipcTest():
|
||||
client2.join()
|
||||
s.join()
|
||||
|
||||
|
||||
def ipcServer():
|
||||
from udsactor import ipc
|
||||
from win32api import Sleep
|
||||
from time import sleep
|
||||
|
||||
s = ipc.ServerIPC(39188, {'idle': 180}) # I have got the enterprise number for Virtual Cable. This number is not about ports, but as good as any other selection :)
|
||||
|
||||
s.start()
|
||||
|
||||
|
||||
counter = 0
|
||||
while True:
|
||||
try:
|
||||
@ -99,33 +100,35 @@ def ipcServer():
|
||||
s.sendMessage(ipc.MSG_SCRIPT, 'print "This is a test message ñöitó 33.3€ {}"'.format(counter))
|
||||
counter += 1
|
||||
s.sendMessage(ipc.MSG_LOGOFF, None)
|
||||
Sleep(1000)
|
||||
sleep(1)
|
||||
except:
|
||||
break
|
||||
|
||||
s.stop()
|
||||
|
||||
|
||||
def testIdle():
|
||||
from udsactor import operations
|
||||
from win32api import Sleep
|
||||
from time import sleep
|
||||
|
||||
for i in xrange(1, 10):
|
||||
print operations.getIdleDuration()
|
||||
Sleep(1000)
|
||||
sleep(1)
|
||||
|
||||
|
||||
def testServer():
|
||||
from win32api import Sleep
|
||||
import random
|
||||
import requests
|
||||
import json
|
||||
import logging
|
||||
from time import sleep
|
||||
|
||||
from udsactor import httpserver
|
||||
from udsactor import ipc
|
||||
|
||||
# Disable verify warinings
|
||||
logging.getLogger("requests").setLevel(logging.ERROR)
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
# requests.packages.urllib3.disable_warnings() # @UndefinedVariable
|
||||
|
||||
s = ipc.ServerIPC(39188) # I have got the enterprise number for Virtual Cable. This number is not about ports, but as good as any other selection :)
|
||||
|
||||
@ -167,16 +170,17 @@ def testServer():
|
||||
print client.getMessage()
|
||||
print client.getMessage()
|
||||
|
||||
#try:
|
||||
# try:
|
||||
# while True:
|
||||
# Sleep(1000)
|
||||
#except:
|
||||
# except:
|
||||
# pass
|
||||
|
||||
server.stop()
|
||||
s.stop()
|
||||
client.stop()
|
||||
|
||||
|
||||
def testRemote():
|
||||
import requests
|
||||
import json
|
||||
@ -202,9 +206,10 @@ def testRemote():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#ipcServer()
|
||||
#testRest()
|
||||
#testIdle()
|
||||
testServer()
|
||||
#testRemote()
|
||||
# ipcServer()
|
||||
ipcTest()
|
||||
# testRest()
|
||||
# testIdle()
|
||||
# testServer()
|
||||
# testRemote()
|
||||
|
||||
|
@ -134,6 +134,7 @@ class ServerIPC(threading.Thread):
|
||||
self.port = listenPort
|
||||
self.running = False
|
||||
self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.threads = []
|
||||
self.infoParams = infoParams
|
||||
|
||||
|
65
actors/src/udsactor/linux/log.py
Normal file
65
actors/src/udsactor/linux/log.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2014 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# Valid logging levels, from UDS Broker (uds.core.utils.log)
|
||||
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in xrange(6))
|
||||
|
||||
|
||||
class LocalLogger(object):
|
||||
def __init__(self):
|
||||
# tempdir is different for "user application" and "service"
|
||||
# service wil get c:\windows\temp, while user will get c:\users\XXX\temp
|
||||
logging.basicConfig(
|
||||
filename=os.path.join(tempfile.gettempdir(), 'udsactor.log'),
|
||||
filemode='a',
|
||||
format='%(levelname)s %(asctime)s %(message)s',
|
||||
level=logging.DEBUG
|
||||
)
|
||||
self.logger = logging.getLogger('udsactor')
|
||||
|
||||
def log(self, level, message):
|
||||
# Debug messages are logged to a file
|
||||
# our loglevels are 10000 (other), 20000 (debug), ....
|
||||
# logging levels are 10 (debug), 20 (info)
|
||||
# OTHER = logging.NOTSET
|
||||
self.logger.log(level / 1000 - 10, message)
|
||||
|
||||
def isWindows(self):
|
||||
return False
|
||||
|
||||
def isLinux(self):
|
||||
return True
|
@ -35,7 +35,7 @@ import sys
|
||||
if sys.platform == 'win32':
|
||||
from udsactor.windows.log import LocalLogger
|
||||
else:
|
||||
pass
|
||||
from udsactor.linux.log import LocalLogger
|
||||
|
||||
# Valid logging levels, from UDS Broker (uds.core.utils.log)
|
||||
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in xrange(6))
|
||||
|
@ -17,11 +17,13 @@ import os
|
||||
# backups = Number of backups to keep of log file (defaults to 3)
|
||||
|
||||
|
||||
import ConfigParser, logging, sys
|
||||
import ConfigParser
|
||||
import logging
|
||||
import sys
|
||||
|
||||
CONFIGFILE = '/etc/udsactor/udsactor.cfg'
|
||||
|
||||
cfg = ConfigParser.SafeConfigParser(defaults={ 'server' : '', 'ssl' : False, 'timeout' : '10',
|
||||
cfg = ConfigParser.SafeConfigParser(defaults={ 'server' : '', 'ssl' : False, 'timeout' : '10',
|
||||
'log' : '/tmp/udsactor.log', 'debug' : 'ERROR', 'maxsize' : '20', 'backups' : '3' })
|
||||
cfg.read(CONFIGFILE)
|
||||
|
||||
@ -38,7 +40,7 @@ try:
|
||||
'timeout' : cfg.getint('broker', 'timeout'),
|
||||
'log' : cfg.get('logging', 'log'),
|
||||
'debug' : levels.get(cfg.get('logging', 'debug'), logging.ERROR),
|
||||
'maxsize' : cfg.getint('logging', 'maxsize')*1024*1024,
|
||||
'maxsize' : cfg.getint('logging', 'maxsize') * 1024 * 1024,
|
||||
'backups' : cfg.getint('logging', 'backups')
|
||||
}
|
||||
# Config file is used only in "root mode", in user mode we overwrite it
|
||||
|
Loading…
Reference in New Issue
Block a user