示例#1
0
    def getGeniusTransationData(self):
        data = fetch_genius_data()
        if data is not None:
            stockCode = data.get('stockCode')
            tradeType = data.get('tradeType')

            content = ''
            if tradeType == 'B':
                r = self.trade.buy(stockCode)
                type = '买入'
            else:
                r = self.trade.sell(stockCode)
                type = '卖出'

            code = r.get('code')
            msg = r.get('msg')
            if code == 1:
                title = type + ' 委托成功 ' + current_time()

            else:
                title = type + ' 委托失败 ' + current_time()

            content += '委托代码:' + str(stockCode) + '\n'
            content += msg.encode('utf-8')
            send_notification(title, content)
示例#2
0
    def start_current(self):
        """Activate calculation simulation for next result."""
        stage = self.current_stage
        stages = self.stages_stack + [stage]
        stagename = self._name(stage)
        name = valid_filename(stagename)
        params = self._params
        self.log(translate('Runner', 'Starting "{0}"...').format(stagename))
        try:
            server = params['server']
            servcfg = self._infos.server_config(server)
            stage.set_remote(params.get('remote_folder'))
            if not servcfg:
                raise RunnerError(translate("Runner",
                                            "Server {0!r} is not available.")
                                  .format(server))
            prof = create_profil_for_current(None, self._case,
                                             stages, name, params, servcfg)
            dbtype, _ = prof.get_base('D')
            remote_in_files = [i.path for i in prof.get_data() \
                                      if i.host and i.type == dbtype]
            salome_job = create_command_job(servcfg, params, prof, stage)
            jobid = self.hdlr.createJob(salome_job)
            try:
                self._infos.export_remote_input_files(server,
                                                      remote_in_files,
                                                      salome_job.work_directory)
                self.hdlr.launchJob(jobid)
                self.save_jobs()
            except Exception as exc:
                msg = translate('Runner',
                                'Error during submission of "{0}"'
                                .format(stagename))
                self.log(msg)
                self.log(str(exc))
                raise RunnerError(msg, str(exc))

        except RunnerError as exc:
            self.log("ERROR: {0}".format(exc.msg))
            self.stop()
            raise

        else:
            self.current.state = SO.Pending
            # Store job informations
            job = self.current.job
            job.jobid = str(jobid)
            job.server = server
            job.name = name
            job.mode = params['mode']
            job.set_parameters_from(params)
            job.start_time = current_time()
            job.description = params.get('description', '')
            self.log(translate('Runner',
                               'Stage "{0}" start calculation (jobid={1})')
                     .format(stagename, jobid))
示例#3
0
 def refresh(self):
     """Refresh state of currently processed (calculated) result."""
     if self.is_finished() or not self.is_started():
         return
     res = self.hdlr.tail(nbline=self._nbline)
     self.current.state = convert_asrun_state(res.state, res.diag)
     debug_message2('Job status is', res, ':', self.current.state)
     if self.current.state & SO.Finished:
         self.current.job.end_time = current_time()
         self.hdlr.get_results()
         self._update_result()
         # refresh next if any
         self.refresh()
     else:
         self.console("\nLast {0} lines at {1}...".format(
             self._nbline, current_time()))
         self.console(res.output)
         # on partial output
         self.current.add_messages(extract_messages(res.output))
示例#4
0
    def refresh(self):
        """Refresh state of currently processed (calculated) result."""
        if self.is_finished() or not self.is_started():
            return
        job = self.current.job
        res = self.hdlr.getJobState(job.jobid_int)
        self.current.state = convert_launcher_state(res)
        debug_message2('Job {0}: status is {1}: {2}'
                       .format(job.jobid, res, SO.name(self.current.state)))
        if self.current.state & SO.Finished:
            job.end_time = current_time()
            self.get_job_results(job)
            # parse message file if it exists
            stage = self.current_stage
            output = glob(osp.join(stage.folder, "logs", "command_*.log"))
            if output:
                self.current.state = convert_state_from_message(res, output[0])
                with open(output[0], 'rb') as fileout:
                    text = to_unicode(fileout.read())
                    self.current.add_messages(extract_messages(text))

            self.save_jobs()
            self._update_result()
            # refresh next if any
            self.refresh()
        else:
            self.console("\nLast {0} lines at {1}..."
                         .format(self._nbline, current_time()))
            salome_job = self.hdlr.getJobParameters(job.jobid_int)
            text = remote_tail(self._infos.server_username(job.server),
                               self._infos.server_hostname(job.server),
                               osp.join(salome_job.work_directory,
                                        "logs", "command_*.log"),
                               self._nbline)
            self.current.add_messages(extract_messages(text))
            self.console(text)
示例#5
0
    def start_current(self):
        """Activate calculation simulation for next result."""
        stage = self.current_stage
        stages = self.stages_stack + [stage]
        stagename = self._name(stage)
        name = valid_filename(stagename)
        params = self._params
        self.log(translate('Runner', 'Starting "{0}"...').format(stagename))
        try:
            self.new_handler()
            create_profil_for_current(self.hdlr.prof, self._case, stages, name,
                                      params, None)
            jret, out = self.hdlr.start()
            if jret != 0:
                msg = translate(
                    'Runner',
                    'Error during submission of "{0}"'.format(stagename))
                self.log(msg)
                self.log(out)
                raise RunnerError(msg, out)

        except RunnerError as exc:
            self.log("ERROR: {0}".format(exc.msg))
            self.stop()
            raise

        else:
            self.current.state = SO.Pending
            job = self.current.job
            job.jobid = self.hdlr.jobid
            job.server = params['server']
            job.name = name
            job.mode = params['mode']
            job.set_parameters_from(params)
            job.start_time = current_time()
            job.description = params.get('description', '')
            self.log(
                translate(
                    'Runner', 'Stage "{0}" start calculation (jobid={1}, '
                    'queue={2})').format(stagename, self.hdlr.jobid,
                                         self.hdlr.queue))