def H_loadLayout(widgetApp, editor, aDefautPathMgr, nameLayout):

    if nameLayout == "":
        log.info("not layout file specified")
        widgetApp.resize(500, 500)
        widgetApp.move(100, 100)
        return
    afile = editor.layout_file(nameLayout)

    if not DiskUtils.is_file_exist(afile):
        afile = aDefautPathMgr.getDefaultLayoutFile()
        if not DiskUtils.is_file_exist(afile):
            log.debug("cannot find the layout file %s" % afile)
            widgetApp.resize(500, 500)
            widgetApp.move(100, 100)
            return

    settings = QtT.QtCore.QSettings(afile, QtT.QtCore.QSettings.IniFormat,
                                    None)
    if DO_PYQT4:
        widgetApp.resize(settings.value('MainWindow/size').toSize())
        widgetApp.move(settings.value('MainWindow/pos').toPoint())
        widgets = list(
            map(str,
                settings.value('MainWindow/widgets').toStringList()))
        for w in widgets:
            className = str(settings.value('%s/className' % w).toString())
            widgetApp.toolInstanciate(className, w)
        widgetApp.restoreState(
            settings.value('MainWindow/state').toByteArray())
        for w in widgets:
            if w in widgetApp._docksWidget:
                widgetApp._docksWidget[w].getCustomWidget().resize(
                    settings.value('%s/size' % w).toSize())
                isFloating = settings.value('%s/floating' % w).toBool()
                if isFloating:
                    widgetApp._docksWidget[w].getCustomWidget().move(
                        settings.value('%s/pos' % w).toPoint())
    else:
        widgetApp.resize(settings.value('MainWindow/size'))
        widgetApp.move(settings.value('MainWindow/pos'))
        widgets = settings.value('MainWindow/widgets')
        if widgets != None:
            for w in widgets:
                className = str(settings.value('%s/className' % w))
                widgetApp.toolInstanciate(className, w)
            widgetApp.restoreState(settings.value('MainWindow/state'))
            for w in widgets:
                if w in widgetApp._docksWidget:
                    widgetApp._docksWidget[w].getCustomWidget().resize(
                        settings.value('%s/size' % w))
                    isFloating = settings.value('%s/floating' % w)
                    if isFloating:
                        widgetApp._docksWidget[w].getCustomWidget().move(
                            settings.value('%s/pos' % w))
Beispiel #2
0
 def load_preference(self):
     if self._prefs == None:
         self.make_preference()
     filePref = self.get_pref_file()
     if filePref == "":
         return self._prefs
     if DiskUtils.is_file_exist(filePref):
         #print "loading preferences",filePref
         self._prefs = self._prefs.ReadAsXml(filePref)[0]
     return self._prefs
Beispiel #3
0
    def importFromFile(self, fileName):
        if self.isGz(fileName) == True:
            f = self.OpenFileGz(fileName, "r")
            if f != 0:
                astr = f.read()
                self.reset()
                self._doc = parseString(astr)
                f.close()
                return True
        else:
            self.reset()
            if DiskUtils.is_file_exist(fileName):
                try:
                    self._doc = parse(fileName)
                except:
                    MsgUtils.error('Trouble in parsing %s' % fileName)
                    return False
            else:
                return False
            return True

        return False
Beispiel #4
0
 def loads(self, fileName):
     d = {}
     if self.isGz(fileName) == True:
         f = self.OpenFileGz(fileName, "r")
         if f != 0:
             astr = f.read()
             d = JSON.loads(astr)
             f.close()
             return d
     else:
         if DiskUtils.is_file_exist(fileName):
             try:
                 f = self.OpenFile(fileName, 'r')
                 astr = f.read()
                 f.close()
                 d = JSON.loads(astr)
             except:
                 return d
         else:
             return d
         return d
     return d
Beispiel #5
0
def send_mail(sendFrom,
              sendTo,
              subject,
              text,
              files=[],
              sendCc=[],
              sendBcc=[],
              authName=None,
              authPass=None):
    """
    quick and easy utility function to send email from any system
    via a python interface.
    """

    import mimetypes
    import smtplib
    import os

    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEBase import MIMEBase
    from email.MIMEText import MIMEText
    from email.Utils import formatdate
    from email import Encoders

    import getpass
    assert type(sendTo) == list
    assert type(sendCc) == list
    assert type(sendBcc) == list
    assert type(files) == list

    addressEmailSuffix = initDefault.EMAIL_SUFFIX

    if '@' not in sendFrom:
        sendFrom += addressEmailSuffix

    for i in range(len(sendTo)):
        if '@' not in sendTo[i]:
            sendTo[i] += addressEmailSuffix

    for i in range(len(sendCc)):
        if '@' not in sendCc[i]:
            sendCc[i] += addressEmailSuffix

    for i in range(len(sendBcc)):
        if '@' not in sendBcc[i]:
            sendBcc[i] += addressEmailSuffix

    msg = MIMEMultipart()
    msg['From'] = sendFrom
    msg['To'] = ', '.join(sendTo)
    if len(sendCc) > 0:
        msg['Cc'] = ', '.join(sendCc)
    if len(sendBcc) > 0:
        msg['Bcc'] = ', '.join(sendBcc)
    msg['Date'] = formatdate(localtime=True)
    msg['Realname'] = getpass.getuser()
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    # attach files as mime parts
    for f in files:
        if DiskUtils.is_file_exist(f):
            ftxt = f.replace(".log", ".txt")
            mimeType = mimetypes.guess_type(ftxt)[0]
            mimeTuple = ('application', 'octet-stream')

            if mimeType is not None:
                mimeTuple = tuple(mimeType.split('/'))
                part = MIMEBase(mimeTuple[0], mimeTuple[1])
                part.set_payload(open(f, "rb").read())
                Encoders.encode_base64(part)
                part.add_header(
                    'Content-Disposition',
                    'attachment; filename="%s"' % os.path.basename(f))
                msg.attach(part)

    log.debug("sending email from %s to %s" % (sendFrom, sendTo))

    smtp = smtplib.SMTP(initDefault.SERVER_EMAIL_NAME)
    if authName is not None and authPass is not None:
        smtp.ehlo()
        smtp.starttls()
        smtp.ehlo()
        smtp.login(authName, authPass)
    smtp.sendmail(sendFrom, sendTo + sendCc + sendBcc, msg.as_string())
    smtp.close()