#940: Run `2to3` on OGAgent source code
Result after running the command: `2to3 -w ogagent/src`remotes/github/python3
parent
1528428d8b
commit
53e7d458c5
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2014 Virtual Cable S.L.
|
||||
|
@ -29,28 +29,21 @@
|
|||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import atexit
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import six
|
||||
import atexit
|
||||
|
||||
from opengnsys import VERSION, ipc, operations, utils
|
||||
from opengnsys.log import logger
|
||||
from opengnsys.service import IPC_PORT
|
||||
from about_dialog_ui import Ui_OGAAboutDialog
|
||||
from message_dialog_ui import Ui_OGAMessageDialog
|
||||
from opengnsys.scriptThread import ScriptExecutorThread
|
||||
from opengnsys import VERSION, ipc, operations, utils
|
||||
from opengnsys.config import readConfig
|
||||
from opengnsys.loader import loadModules
|
||||
|
||||
# Set default characters encoding to UTF-8
|
||||
reload(sys)
|
||||
if hasattr(sys, 'setdefaultencoding'):
|
||||
sys.setdefaultencoding('utf-8')
|
||||
from opengnsys.log import logger
|
||||
from opengnsys.scriptThread import ScriptExecutorThread
|
||||
from opengnsys.service import IPC_PORT
|
||||
|
||||
trayIcon = None
|
||||
|
||||
|
@ -61,7 +54,7 @@ def sigAtExit():
|
|||
|
||||
|
||||
# About dialog
|
||||
class OGAAboutDialog(QtGui.QDialog):
|
||||
class OGAAboutDialog(QtWidgets.QDialog):
|
||||
def __init__(self, parent=None):
|
||||
QtWidgets.QDialog.__init__(self, parent)
|
||||
self.ui = Ui_OGAAboutDialog()
|
||||
|
@ -115,13 +108,13 @@ class MessagesProcessor(QtCore.QThread):
|
|||
def isAlive(self):
|
||||
return self.ipc is not None
|
||||
|
||||
def sendLogin(self, userName, language):
|
||||
def sendLogin(self, username, language):
|
||||
if self.ipc:
|
||||
self.ipc.sendLogin(userName, language)
|
||||
self.ipc.sendLogin(username, language)
|
||||
|
||||
def sendLogout(self, userName):
|
||||
def sendLogout(self, username):
|
||||
if self.ipc:
|
||||
self.ipc.sendLogout(userName)
|
||||
self.ipc.sendLogout(username)
|
||||
|
||||
def run(self):
|
||||
if self.ipc is None:
|
||||
|
@ -136,15 +129,15 @@ class MessagesProcessor(QtCore.QThread):
|
|||
msg = self.ipc.getMessage()
|
||||
if msg is None:
|
||||
break
|
||||
msgId, data = msg
|
||||
msg_id, data = msg
|
||||
logger.debug('Got Message on User Space: {}:{}'.format(msgId, data))
|
||||
if msgId == ipc.MSG_MESSAGE:
|
||||
if msg_id == ipc.MSG_MESSAGE:
|
||||
module, message, data = data.split('\0')
|
||||
self.message.emit((module, message, data))
|
||||
elif msgId == ipc.MSG_LOGOFF:
|
||||
elif msg_id == ipc.MSG_LOGOFF:
|
||||
self.logoff.emit()
|
||||
elif msgId == ipc.MSG_SCRIPT:
|
||||
self.script.emit(QtCore.QString.fromUtf8(data))
|
||||
elif msg_id == ipc.MSG_SCRIPT:
|
||||
self.script.emit(data.decode('utf-8'))
|
||||
except Exception as e:
|
||||
try:
|
||||
logger.error('Got error on IPC thread {}'.format(utils.exceptionToMessage(e)))
|
||||
|
@ -161,17 +154,14 @@ class OGASystemTray(QtWidgets.QSystemTrayIcon):
|
|||
def __init__(self, app_, parent=None):
|
||||
self.app = app_
|
||||
self.config = readConfig(client=True)
|
||||
|
||||
self.modules = None
|
||||
# Get opengnsys section as dict
|
||||
cfg = dict(self.config.items('opengnsys'))
|
||||
|
||||
# Set up log level
|
||||
logger.setLevel(cfg.get('log', 'INFO'))
|
||||
|
||||
self.ipcport = int(cfg.get('ipc_port', IPC_PORT))
|
||||
|
||||
# style = app.style()
|
||||
# icon = QtGui.QIcon(style.standardPixmap(QtGui.QStyle.SP_ComputerIcon))
|
||||
icon = QtGui.QIcon(':/images/img/oga.png')
|
||||
|
||||
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
|
||||
|
@ -208,18 +198,16 @@ class OGASystemTray(QtWidgets.QSystemTrayIcon):
|
|||
logger.debug('Modules: {}'.format(list(v.name for v in self.modules)))
|
||||
|
||||
# Send init to all modules
|
||||
validMods = []
|
||||
valid_mods = []
|
||||
for mod in self.modules:
|
||||
try:
|
||||
logger.debug('Activating module {}'.format(mod.name))
|
||||
mod.activate()
|
||||
validMods.append(mod)
|
||||
valid_mods.append(mod)
|
||||
except Exception as e:
|
||||
logger.exception()
|
||||
logger.error("Activation of {} failed: {}".format(mod.name, utils.exceptionToMessage(e)))
|
||||
|
||||
self.modules[:] = validMods # copy instead of assignment
|
||||
|
||||
self.modules[:] = valid_mods # copy instead of assignment
|
||||
# If this is running, it's because he have logged in, inform service of this fact
|
||||
self.ipc.sendLogin(operations.getCurrentUser(), operations.getSessionLanguage())
|
||||
|
||||
|
@ -259,7 +247,7 @@ class OGASystemTray(QtWidgets.QSystemTrayIcon):
|
|||
|
||||
def executeScript(self, script):
|
||||
logger.debug('Executing script')
|
||||
script = six.text_type(script.toUtf8()).decode('base64')
|
||||
script = base64.b64decode(script.encode('ascii'))
|
||||
th = ScriptExecutorThread(script)
|
||||
th.start()
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt4 import QtCore
|
||||
from PyQt5 import QtCore
|
||||
|
||||
qt_resource_data = b"\
|
||||
\x00\x00\x0f\x42\
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
# pylint: disable-msg=E1101,W0703
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import requests
|
||||
import logging
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
# On centos, old six release does not includes byte2int, nor six.PY2
|
||||
import six
|
||||
|
||||
import modules
|
||||
from RESTApi import REST, RESTError
|
||||
from . import modules
|
||||
from .RESTApi import REST, RESTError
|
||||
|
||||
try:
|
||||
with open('../VERSION', 'r') as v:
|
||||
|
|
|
@ -26,24 +26,25 @@
|
|||
# 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
|
||||
'''
|
||||
"""
|
||||
# pylint: disable=unused-wildcard-import, wildcard-import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
from configparser import SafeConfigParser
|
||||
|
||||
config = None
|
||||
|
||||
|
||||
def readConfig(client=False):
|
||||
'''
|
||||
"""
|
||||
Reads configuration file
|
||||
If client is False, will read ogagent.cfg as configuration
|
||||
If client is True, will read ogclient.cfg as configuration
|
||||
|
||||
This is this way so we can protect ogagent.cfg against reading for non admin users on all platforms.
|
||||
'''
|
||||
"""
|
||||
cfg = SafeConfigParser()
|
||||
if client is True:
|
||||
fname = 'ogclient.cfg'
|
||||
|
@ -55,4 +56,3 @@ def readConfig(client=False):
|
|||
return None
|
||||
|
||||
return cfg
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
|
||||
# Pydev can't parse "six.moves.xxxx" because it is loaded lazy
|
||||
import six
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import socket
|
||||
import threading
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
# 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
|
||||
"""
|
||||
|
||||
|
||||
from opengnsys.service import CommonService
|
||||
from opengnsys.service import IPC_PORT
|
||||
|
@ -45,7 +45,7 @@ import json
|
|||
|
||||
try:
|
||||
from prctl import set_proctitle # @UnresolvedImport
|
||||
except Exception: # Platform may not include prctl, so in case it's not available, we let the "name" as is
|
||||
except ImportError: # Platform may not include prctl, so in case it's not available, we let the "name" as is
|
||||
def set_proctitle(_):
|
||||
pass
|
||||
|
||||
|
@ -63,7 +63,6 @@ class OGAgentSvc(Daemon, CommonService):
|
|||
|
||||
# Call modules initialization
|
||||
# They are called in sequence, no threading is done at this point, so ensure modules onActivate always returns
|
||||
|
||||
|
||||
# *********************
|
||||
# * Main Service loop *
|
||||
|
@ -93,6 +92,7 @@ def usage():
|
|||
sys.stderr.write("usage: {} start|stop|restart|fg|login 'username'|logout 'username'|message 'module' 'message' 'json'\n".format(sys.argv[0]))
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger.setLevel('INFO')
|
||||
|
||||
|
@ -105,7 +105,6 @@ if __name__ == '__main__':
|
|||
sys.exit(0)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
if len(sys.argv) == 3 and sys.argv[1] in ('login', 'logout'):
|
||||
logger.debug('Running client opengnsys')
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import socket
|
||||
import platform
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import platform
|
||||
import os
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.linux.renamer import renamers
|
||||
from opengnsys.log import logger
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.linux.renamer import renamers
|
||||
from opengnsys.log import logger
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.linux.renamer import renamers
|
||||
from opengnsys.log import logger
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
# This is a simple module loader, so we can add "external opengnsys" modules as addons
|
||||
# Modules under "opengsnsys/modules" are always autoloaded
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import pkgutil
|
||||
import os.path
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import traceback
|
||||
import sys
|
||||
|
|
|
@ -29,4 +29,4 @@
|
|||
'''
|
||||
@author: Ramón M. Gómez, ramongomez at us dot es
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import socket
|
||||
import platform
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"""
|
||||
@author: Ramón M. Gómez, ramongomez at us dot es
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.workers import ClientWorker
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2014 Virtual Cable S.L.
|
||||
|
@ -28,7 +29,7 @@
|
|||
"""
|
||||
@author: Ramón M. Gómez, ramongomez at us dot es
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import os
|
||||
import random
|
||||
|
@ -36,12 +37,14 @@ import shutil
|
|||
import string
|
||||
import threading
|
||||
import time
|
||||
import urllib
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from opengnsys.workers import ServerWorker
|
||||
from opengnsys import REST, RESTError, operations, VERSION
|
||||
from opengnsys import REST, operations, VERSION
|
||||
from opengnsys.log import logger
|
||||
from opengnsys.scriptThread import ScriptExecutorThread
|
||||
from opengnsys.workers import ServerWorker
|
||||
|
||||
|
||||
# Check authorization header decorator
|
||||
|
@ -312,7 +315,7 @@ class OpenGnSysWorker(ServerWorker):
|
|||
"""
|
||||
logger.debug('Processing script request')
|
||||
# Decoding script (Windows scripts need a subprocess call per line)
|
||||
script = urllib.unquote(post_params.get('script').decode('base64')).decode('utf8')
|
||||
script = urllib.parse.unquote(post_params.get('script').decode('base64')).decode('utf8')
|
||||
if operations.os_type == 'Windows':
|
||||
script = 'import subprocess; {0}'.format(
|
||||
';'.join(['subprocess.check_output({0},shell=True)'.format(repr(c)) for c in script.split('\n')]))
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
"""
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
# Importing platform operations and getting operating system data.
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
# 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
|
||||
"""
|
||||
|
||||
|
||||
from .log import logger
|
||||
from .config import readConfig
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import sys
|
||||
import six
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# pylint: disable=unused-wildcard-import, wildcard-import
|
||||
|
||||
import win32serviceutil # @UnresolvedImport, pylint: disable=import-error
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import servicemanager # @UnresolvedImport, pylint: disable=import-error
|
||||
import logging
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import os
|
||||
import locale
|
||||
|
@ -102,12 +102,12 @@ def getWindowsVersion():
|
|||
'''
|
||||
Returns Windows version.
|
||||
'''
|
||||
import _winreg
|
||||
reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
|
||||
import winreg
|
||||
reg = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
|
||||
try:
|
||||
data = '{} {}'.format(_winreg.QueryValueEx(reg, 'ProductName')[0], _winreg.QueryValueEx(reg, 'ReleaseId')[0])
|
||||
data = '{} {}'.format(winreg.QueryValueEx(reg, 'ProductName')[0], winreg.QueryValueEx(reg, 'ReleaseId')[0])
|
||||
except Exception:
|
||||
data = '{} {}'.format(_winreg.QueryValueEx(reg, 'ProductName')[0], _winreg.QueryValueEx(reg, 'CurrentBuildNumber')[0])
|
||||
data = '{} {}'.format(winreg.QueryValueEx(reg, 'ProductName')[0], winreg.QueryValueEx(reg, 'CurrentBuildNumber')[0])
|
||||
reg.Close()
|
||||
return data
|
||||
|
||||
|
@ -200,7 +200,7 @@ def joinDomain(domain, ou, account, password, executeInOneStep=False):
|
|||
error = getErrorMessage(res)
|
||||
if res == 1355:
|
||||
error = "DC Is not reachable"
|
||||
print('{} {}'.format(res, error))
|
||||
print(('{} {}'.format(res, error)))
|
||||
raise Exception('Error joining domain {}, with credentials {}/*****{}: {}, {}'.format(domain.value, account.value, ', under OU {}'.format(ou.value) if ou.value is not None else '', res, error))
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class ClientWorker(object):
|
||||
'''
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class ServerWorker(object):
|
||||
'''
|
||||
|
|
|
@ -3,7 +3,7 @@ Created on Jul 9, 2015
|
|||
|
||||
@author: dkmaster
|
||||
'''
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
|
||||
# Pydev can't parse "six.moves.xxxx" because it is loaded lazy
|
||||
from six.moves.socketserver import ThreadingMixIn # @UnresolvedImport
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.workers import ClientWorker
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# Module must be imported on package, so we can initialize and load it
|
||||
from sample1 import Sample1
|
||||
from .sample1 import Sample1
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from opengnsys.workers import ServerWorker
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
|
||||
def test():
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
|
||||
# Pydev can't parse "six.moves.xxxx" because it is loaded lazy
|
||||
from six.moves.socketserver import ThreadingMixIn # @UnresolvedImport
|
||||
|
|
Loading…
Reference in New Issue