Example #1
0
           'formatFileSize', 'fromJson', 'generateOpsiHostKey', 'getfqdn',
           'ipAddressInNetwork', 'isRegularExpressionPattern',
           'librsyncDeltaFile', 'librsyncPatchFile', 'librsyncSignature',
           'md5sum', 'objectToBash', 'objectToBeautifiedText', 'objectToHtml',
           'randomString', 'removeDirectory', 'removeUnit',
           'replaceSpecialHTMLCharacters', 'serialize', 'timestamp', 'toJson')

logger = Logger()

if os.name == 'posix':
    from duplicity import librsync
elif os.name == 'nt':
    try:
        import librsync
    except Exception as e:
        logger.error(u"Failed to import librsync: %s" % e)

BLOWFISH_IV = 'OPSI1234'
RANDOM_DEVICE = u'/dev/urandom'
UNIT_REGEX = re.compile(r'^(\d+\.*\d*)\s*(\w{0,4})$')
_ACCEPTED_CHARACTERS = ("abcdefghijklmnopqrstuvwxyz"
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                        "0123456789")

Version = namedtuple('Version', 'product package')


class CryptoError(ValueError):
    pass

Example #2
0
import signal as ui_signal
from snack import *

from OPSI.Logger import Logger
from OPSI.Types import (forceBool, forceInt, forceList, forceUnicode,
                        forceUnicodeList)
from OPSI.Util.Message import MessageObserver, ProgressObserver

logger = Logger()
encoding = locale.getpreferredencoding()

try:
    translation = gettext.translation('python-opsi', '/usr/share/locale')
    _ = translation.ugettext
except Exception as e:
    logger.error(u"Locale not found: %s" % e)

    def _(string):
        """
		Fallback function for providing translations.
		"""
        return string


def UIFactory(type=u''):
    uiType = forceUnicode(type)
    if uiType in (u'snack', u'SnackUI'):
        return SnackUI()
    elif uiType in (u'dummy', u'UI'):
        return UI()
Example #3
0
import termios

from OPSI.Exceptions import (
	BackendConfigurationError, OpsiBackupFileError,
	OpsiBackupBackendNotFound, OpsiError)
from OPSI.Logger import Logger, LOG_DEBUG
from OPSI.Types import forceList, forceUnicode
from OPSI.Util.File.Opsi import OpsiBackupArchive

logger = Logger()

try:
	translation = gettext.translation('opsi-utils', '/usr/share/locale')
	_ = translation.ugettext
except Exception as error:
	logger.error(u"Locale not found: {0}", error)

	def _(string):
		""" Function for translating text. """
		return string


WARNING_DIFF = _(u"""WARNING: Your system config is different from the one recorded with this backup.
This means the backup was probably taken for another machine and restoring it might leave this opsi installation unusable.
Do you wish to continue? [y/n]""")

WARNING_SYSCONFIG = _(u"""WARNING: A problem occurred while reading the sysconfig: %s
This means the backup was probably taken for another machine and restoring it might leave this opsi installation unusable.
Do you wish to continue? [y/n]""")

Example #4
0
		parser.add_argument("-i", "--id", dest="notificationClientId", help="Notification client id", default=None)
		parser.add_argument("-l", "--log-file", dest="logFile", help="Log file to use.")

		args = parser.parse_args()
		args.port = forceUnicode(args.port)
		args.notificationClientId = forceUnicode(args.notificationClientId)

		if args.logFile:
			logFile = forceFilename(args.logFile)
			# TODO: logrotate?
			if os.path.exists(logFile):
				logger.notice("Deleting old log file: %s" % logFile)
				os.unlink(logFile)
			logger.notice("Setting log file: %s" % logFile)
			logger.setLogFile(logFile)
			logger.setFileLevel(LOG_DEBUG)

		w = OpsiDialogWindow()
	except Exception as err: # pylint: disable=broad-except
		logger.error(err, exc_info=True)
		tb = sys.exc_info()[2]
		while tb is not None:
			f = tb.tb_frame
			c = f.f_code
			print("     line %s in '%s' in file '%s'" % (tb.tb_lineno, c.co_name, c.co_filename), file=sys.stderr)
			tb = tb.tb_next
		print(f"ERROR: {err}", file=sys.stderr)
		sys.exit(1)

	sys.exit(0)