Exemple #1
0
 def SendMail(self, dest, author=None, subject='no subject', text=''):
     """Send a message by mail.
     Use ", " in `dest` to separate multiple recipients.
     """
     sign = _(u'email sent at %s by as_run from %s') % (now(), local_host)
     sign = os.linesep*2 + '-'*len(sign) + os.linesep \
        + sign \
        + os.linesep   + '-'*len(sign) + os.linesep
     try:
         import smtplib
         from asrun.common.utils import MIMETextClass
         if MIMETextClass is None:
             raise ImportError
     except ImportError:
         self._mess(_(u'Can not send mail from this machine'),
                    '<A>_NO_MAILER')
         return
     dest = [s.strip() for s in dest.split(',')]
     mail_encoding = get_encoding()
     content = convert(to_unicode(text) + sign, mail_encoding)
     msg = MIMETextClass(content, _charset=mail_encoding)
     msg['Subject'] = convert(subject, mail_encoding)
     if author == None:
         author = '%s@%s' % (local_user, local_full_host)
     msg['From'] = author
     msg['To'] = ', '.join(dest)
     s = smtplib.SMTP()
     s.connect()
     s.sendmail(msg['From'], dest, msg.as_string())
     s.close()
Exemple #2
0
    def start(self):
        """Start the copy
        """
        if self.verbose:
            print3(_(u'(parallel_copy) - destination : %s - start time : %s') \
                % (self.dest, now(datefmt="")))
        # get a source
        src = self.get_repository()

        # copy
        if src == self.dest or src == self.leech:
            print3(_(u'source and destination are identical'))
            return
        if DEBUG:
            spl = src.split(':')
            host_src = ''
            if len(spl) > 0:
                host_src = spl[0].split('.')[0] + ':'
            host_dest = gethostname().split('.')[0] + ':'
            print3(u'GRAPH   "%s%s" -> "%s%s";' %
                   (host_src, os.path.basename(src), host_dest,
                    os.path.basename(self.dest)))
        if not os.path.exists(self.dest):
            #peter.zhang, for cygwin
            self.dest = self.dest.replace('\\', '/')
            self.dest = self.dest.replace('/cygdrive/', '')
            if self.dest.find(':/') < 0:
                self.dest = self.dest.replace('/', ':/', 1)
            os.makedirs(self.dest)
        iret = self.copy('%s/*' % src, self.dest)

        # remove repositories file in dest
        dest_repo = os.path.join(self.dest,
                                 os.path.basename(self.repo_filename()))
        if os.path.exists(dest_repo):
            os.remove(dest_repo)

        l_repo = [
            src,
        ]
        l_repo.extend([
            self.leech,
        ] * self.leech_limit)
        self.update_repository(l_repo)
        if self.verbose:
            print3(_(u'(parallel_copy) - destination : %s  -  end time : %s') \
                % (self.dest, now(datefmt="")))
Exemple #3
0
 def get_job(self, jobname):
     """Get 'jobname' from history.
     """
     dico = self.history.get(jobname)
     if dico is None:
         return {}
     dico['released'] = now(datefmt="%a")
     return dico.copy()
Exemple #4
0
 def store_job(self, host='unknown', **kwjob):
     """Store 'kwjob' in history.
     """
     if host is None:
         return
     dico = kwjob.copy()
     dico['host'] = host
     dico['allocated'] = now(datefmt="%a")
     self.history[kwjob['nomjob']] = dico
Exemple #5
0
 def hostinfo_repr(self, title=""):
     """Return a hostfile representing the content of the 'hostinfo' attribute.
     """
     if not title:
         title = "from ResourceManager object"
     content = ["# GENERATED %s - %s" % (title, now())]
     for mach, res in self.hostinfo.items():
         cpu = res["cpu"]
         mem = res["mem"]
         if cpu == mem == 0:
             content.append("# %s is not responding" % mach)
         else:
             content.append("[%s]" % mach)
             if cpu > 0:
                 content.append("cpu=%d" % cpu)
             if mem > 0:
                 content.append("mem=%d" % mem)
         content.append("")
     return os.linesep.join(content)
Exemple #6
0
    Commands catalogue directory    : %s
    Elements catalogue filename     : %s
    Working directory               : %s
    Submission timeout (seconds)    : %.0f""")

    sum_thread = _(u"""    Number of threads               : %d""")
    sum_rc = _(u"""    Available hosts (number of cpu) : %s""")
    sum_end = _(u"""
--- All executions finished at %s

--- Results :
""")
    fmt_spup = _(u"""
--- Speed-up is %.2f
""")
    info_start = (nbval, now(), resudir, flashdir, prof.get_version_path(),
                  kargs['exe'], kargs['cmde'], kargs['ele'], reptrav, timeout)
    txt_summary = [
        ufmt(summary, *info_start),
    ]
    if numthread > 1:
        txt_summary.append(sum_thread % numthread)
    if hostrc:
        host_str = ', '.join(['%(host)s (%(cpu)d)' % hostrc.GetConfig(h) \
                            for h in hostrc.get_all_connected_hosts()])
        txt_summary.append(sum_rc % host_str)
    txt_summary.append('')
    text_summary = os.linesep.join(txt_summary)
    print3(text_summary)
    if nbval < 1:
        run.Mess(_(u"There is no value for the parameters."), '<F>_ERROR')
Exemple #7
0
    except ReadDBError:
        run.Mess(_(u'Code_Aster product not found in database !'), '<F>_DB_ERROR')
    emis = STATUS({'_name' : 'emis'}, c)
    try:
        emis.read()
    except ReadDBError:
        run.Mess(_(u"Status 'emis' not found in database !"), '<F>_DB_ERROR')

    # 4.2. get version item
    d_vers = prod.GetLinks()
    vers = d_vers.get(d['VERSION'])
    if vers == None:
        run.Mess(_(u"Version %s not found in database !") % d['VERSION'])

    # 4.3. fill fields
    date_now = now(datefmt=mysql_date_fmt, timefmt="")
    txtmsg = convert(d['TEXTE'], db_encoding)
    txtmsg = cut_long_lines(txtmsg, maxlen=100)
    issue = ISSUE({
            '_creator'  : user,
            '_produit'  : prod,
            '_status'   : emis,
            '_title'    : convert(d['TITRE'], db_encoding),
            '_type'     : d_typ[d['TYPFIC']],
            '_version'  : vers,
            '_fichetude' : fichetude,
        }, c)
    descr = MSG({'_author'   : user,
                '_creation' : date_now,
                '_creator'  : user,
                '_date'     : date_now,
Exemple #8
0
    Submission timeout (seconds)     : %.0f""")

    sum_thread = _(u"""    Number of threads                : %d""")
    sum_end = _(u"""
--- All executions finished at %s

--- Results :
""")
    jobname = prof['nomjob'][0]
    ldir = ", ".join(
        ["%s/%s_%s" % (MULTIDIR, jobname, val[0]) for val in couples])
    if result_on_client:
        ldir = osp.expandvars(ldir)
    else:
        ldir = "(" + _(u"on each host") + ") " + ldir
    info_start = (nbval, ", ".join(serv_list), now(), prof.get_version_path(),
                  ldir, timeout)
    txt_summary = [
        ufmt(summary, *info_start),
    ]
    if numthread > 1:
        txt_summary.append(sum_thread % numthread)
    txt_summary.append('')
    text_summary = os.linesep.join(txt_summary)
    print3(text_summary)

    # ----- Execute calcutions in parallel using a Dispatcher object
    # elementary task...
    task = DistribMultipleTask(  # IN
        run=run,
        prof=prof,
Exemple #9
0
    Time multiplicative factor      : %f
    Working directory               : %s
    Submission timeout (seconds)    : %.0f""")

    sum_thread = _(u"""    Number of threads               : %d""")
    sum_rc = _(u"""    Available hosts (resources)     : %s""")
    sum_end = _(u"""
--- All tests finished at %s

--- Results :
""")
    fmt_spup = _(u"""
--- Speed-up is %.2f
""")
    version_number = '.'.join(get_aster_version(REPREF)[:3])
    info_start = (nbtest, now(), ', '.join([
        osp.join(REPREF, path) for path in conf['SRCTEST']
    ]), ', '.join(reptest), resutest, flashdir, prof.get_version_path(),
                  version_number, kargs['exe'], kargs['cmde'], kargs['ele'],
                  nbmaxnook, cpresok, facmtps, reptrav, timeout)
    txt_summary = [
        ufmt(summary, *info_start),
    ]
    if numthread > 1:
        txt_summary.append(sum_thread % numthread)
    if hostrc:
        host_str = ', '.join(['%(host)s (%(cpu)d)' % hostrc.GetConfig(h) \
                            for h in hostrc.get_all_connected_hosts()])
        txt_summary.append(sum_rc % host_str)
    txt_summary.append('')
    text_summary = os.linesep.join(txt_summary)