コード例 #1
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def running_callback(task):
     self._log.info("writing g-code to %s with%s start/end gcode", output_path, '' if add_start_end else 'out')
     try:
         with open(input_path) as ifp:
             with open(output_path, 'w') as ofp:
                 extruders = [e.strip() for e in slicer_settings.extruder.split(',')]
                 gcode_scaffold = profile.get_gcode_scaffold(
                     extruders,
                     slicer_settings.extruder_temperature,
                     slicer_settings.platform_temperature,
                     material_name)
                 if add_start_end:
                     for line in gcode_scaffold.start:
                         print(line, file=ofp)
                 for line in ifp.readlines():
                     ofp.write(line)
                 if add_start_end:
                     for line in gcode_scaffold.end:
                         print(line, file=ofp)
     except Exception as e:
         self._log.exception('unhandled exception; failed to add start/end g-code')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
     else:
         task.end(None)
コード例 #2
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def runningcallback(task):
     self._log.info("postweave processing on %s" % (gcode_path))
     try:
         conveyor.dualstrusion.post_weave(gcode_path, gcode_path_tmp, gcode_path_out, profile)
     except Exception as e:
         self._log.exception('unhandled exception; dualstrusion post-processing failed')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
     else:
         task.end(None)
コード例 #3
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def runningcallback(task):
     self._log.info('verifying s3g file %s', s3gpath)
     try:
         # If the filereader can parse it, then the s3g file is valid
         reader = makerbot_driver.FileReader.FileReader()
         with open(s3gpath, 'rb') as reader.file:
             payloads = reader.ReadFile(update)
         task.end(True)
     except makerbot_driver.FileReader.S3gStreamError as e:
         self._log.exception('unhandled exception; s3g verification failed')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
コード例 #4
0
ファイル: jsonrpc.py プロジェクト: nmsl1993/conveyor
 def _handleresponse(self, response, id):
     self._log.debug('response=%r, id=%r', response, id)
     task = self._tasks.pop(id, None)
     if None is task:
         self._log.debug('ignoring response for unknown id: %r', id)
     elif self._iserrorresponse(response):
         error = response['error']
         task.fail(error)
     elif self._issuccessresponse(response):
         result = response['result']
         task.end(result)
     else:
         raise ValueError(response)
コード例 #5
0
ファイル: jsonrpc.py プロジェクト: jsadusk/conveyor
 def _handleresponse(self, response, id):
     self._log.debug('response=%r, id=%r', response, id)
     task = self._tasks.pop(id, None)
     if None is task:
         self._log.debug('ignoring response for unknown id: %r', id)
     elif self._iserrorresponse(response):
         error = response['error']
         task.fail(error)
     elif self._issuccessresponse(response):
         result = response['result']
         task.end(result)
     else:
         raise ValueError(response)
コード例 #6
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def runningcallback(task):
     self._log.info('processing gcode %s -> %s', inputpath, outputpath)
     try:
         with open(inputpath) as f:
             output = list(f)
             for gcodeprocessor in gcodeprocessors:
                 output = gcodeprocessor.process_gcode(output)
         with open(outputpath, 'w') as f:
             for line in output:
                 f.write(line)
     except Exception as e:
         self._log.exception('unhandled exception; gcode processing failed')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
     else:
         task.end(None)
コード例 #7
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def uploadfirmware(self, machine_type, filename, task):
     with self._condition:
         self._statetransition("idle", "uploadingfirmware")
         uploader = makerbot_driver.Firmware.Uploader()
         self._fp.close()
         try:
             uploader.upload_firmware(self._portname, machine_type, filename)
             task.end(None)
         except makerbot_driver.Firmware.subprocess.CalledProcessError as e:
             self._log.debug('handled exception', exc_info=True)
             message = str(e)
             task.fail(message)
         finally:
             self._fp.open()
             self._statetransition("uploadingfirmware", "idle")
             self._currenttask = None
コード例 #8
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def uploadfirmware(self, machine_type, filename, task):
     with self._condition:
         self._statetransition("idle", "uploadingfirmware")
         uploader = makerbot_driver.Firmware.Uploader()
         self._fp.close()
         try:
             uploader.upload_firmware(self._portname, machine_type,
                                      filename)
             task.end(None)
         except makerbot_driver.Firmware.subprocess.CalledProcessError as e:
             self._log.debug('handled exception', exc_info=True)
             message = str(e)
             task.fail(message)
         finally:
             self._fp.open()
             self._statetransition("uploadingfirmware", "idle")
             self._currenttask = None
コード例 #9
0
ファイル: recipe.py プロジェクト: nmsl1993/conveyor
 def runningcallback(task):
     try:
         # TODO: Attention future dave: makerbot_driver needs to import unicode literals
         in_name = inputpath
         for preprocessor in preprocessors:
             #The last prepro should output to the outputpath
             if preprocessor == preprocessors[-1]:
                 out_name = outputpath
             else:
                 with tempfile.NamedTemporaryFile(suffix='.gcode', delete=True) as f:
                     out_name = f.name 
             self._log.info('preprocessing %s -> %s', in_name, out_name)
             preprocessor.process_file(in_name, out_name)
             in_name = out_name
     except Exception as e:
         self._log.debug('unhandled exception', exc_info=True)
         task.fail(e)
     else:
         task.end(None)
コード例 #10
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def runningcallback(task):
     self._log.info("weaving together %s and %s to %s for dualstrusion" % (tool_0_path, tool_1_path, outputpath))
     try:
         with contextlib.nested(open(tool_0_path), open(tool_1_path)) as (t0, t1):
             t0_codes = conveyor.dualstrusion.GcodeObject(list(t0))
             t1_codes = conveyor.dualstrusion.GcodeObject(list(t1))
         weaver = conveyor.dualstrusion.DualstrusionWeaver(t0_codes, t1_codes, task)
         woven_codes = weaver.combine_codes()
         progress_processor = makerbot_driver.GcodeProcessors.DualstrusionProgressProcessor()
         output = progress_processor.process_gcode(woven_codes)
         with open(outputpath, 'w') as f:
             for line in output:
                 f.write(line)
     except Exception as e:
         self._log.exception('unhandled exception; dualstrusion weave failed')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
     else:
         task.end(None)
コード例 #11
0
 def runningcallback(task):
     try:
         # TODO: Attention future dave: makerbot_driver needs to import unicode literals
         in_name = inputpath
         for preprocessor in preprocessors:
             #The last prepro should output to the outputpath
             if preprocessor == preprocessors[-1]:
                 out_name = outputpath
             else:
                 with tempfile.NamedTemporaryFile(suffix='.gcode',
                                                  delete=True) as f:
                     out_name = f.name
             self._log.info('preprocessing %s -> %s', in_name, out_name)
             preprocessor.process_file(in_name, out_name)
             in_name = out_name
     except Exception as e:
         self._log.debug('unhandled exception', exc_info=True)
         task.fail(e)
     else:
         task.end(None)
コード例 #12
0
ファイル: recipe.py プロジェクト: vongoethe/conveyor
 def runningcallback(task):
     self._log.info('verifying g-code file %s', gcodepath)
     try:
         parser = makerbot_driver.Gcode.GcodeParser()
         parser.state.values['build_name'] = "VALIDATION"
         parser.state.profile = profile._s3g_profile
         parser.s3g = mock.Mock()
         extruders = [e.strip() for e in slicer_settings.extruder.split(',')]
         gcode_scaffold = profile.get_gcode_scaffold(
             extruders,
             slicer_settings.extruder_temperature,
             slicer_settings.platform_temperature,
             material_name)
         parser.environment.update(gcode_scaffold.variables)
         with open(gcodepath) as f:
             for line in f:
                 parser.execute_line(line)
                 update(parser.state.percentage)
     except Exception as e:
         self._log.exception('unhandled exception; g-code verification failed')
         failure = conveyor.util.exception_to_failure(e)
         task.fail(failure)
     else:
         task.end(True)
コード例 #13
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
    def _genericprint(self, server, portname, profile, buildname, writer,
                      polltemperature, pollinterval, gcodepath, skip_start_end,
                      slicer_settings, material, task):
        current_progress = None
        new_progress = {'name': 'print', 'progress': 0}
        current_progress = self._update_progress(current_progress,
                                                 new_progress, task)
        parser = makerbot_driver.Gcode.GcodeParser()
        parser.state.profile = profile
        parser.state.set_build_name(str(buildname))
        parser.s3g = makerbot_driver.s3g()
        parser.s3g.writer = writer

        def cancelcallback(task):
            try:
                self._log.debug('setting external stop')
                writer.set_external_stop()
            except makerbot_driver.Writer.ExternalStopError:
                self._log.debug('handled exception', exc_info=True)
            if polltemperature:
                self._log.debug('aborting printer')
                # NOTE: need a new s3g object because the old one has
                # external stop set.
                # TODO: this is a horrible hack.
                s3g = makerbot_driver.s3g()
                s3g.writer = makerbot_driver.Writer.StreamWriter(
                    parser.s3g.writer.file)
                s3g.abort_immediately()

        task.cancelevent.attach(cancelcallback)
        if polltemperature:
            self._log.debug('resetting machine %s', portname)
            parser.s3g.reset()
        now = time.time()
        polltime = now + pollinterval
        if not polltemperature:
            temperature = None
        else:
            temperature = _gettemperature(profile, parser.s3g)
            server.changeprinter(portname, temperature)
        gcodelines, variables = self._gcodelines(profile, gcodepath,
                                                 skip_start_end,
                                                 slicer_settings, material)
        parser.environment.update(variables)
        # TODO: remove this {current,total}{byte,line} stuff; we have
        # proper progress from the slicer now.
        totallines, totalbytes = self._countgcodelines(gcodelines)
        currentbyte = 0
        for currentline, data in enumerate(gcodelines):
            if conveyor.task.TaskState.RUNNING != task.state:
                break
            else:
                # Increment currentbyte *before* stripping whitespace
                # out of data or the currentbyte will not match the
                # actual file position.
                currentbyte += len(data)
                data = data.strip()
                now = time.time()
                if polltemperature and polltime <= now:
                    temperature = _gettemperature(profile, parser.s3g)
                self._log.debug('gcode: %r', data)
                # The s3g module cannot handle unicode strings.
                data = str(data)
                parser.execute_line(data)
                new_progress = {
                    'name': 'print',
                    'progress': int(parser.state.percentage)
                }
                if polltime <= now:
                    polltime = now + pollinterval
                    if polltemperature:
                        server.changeprinter(portname, temperature)
                current_progress = self._update_progress(
                    current_progress, new_progress, task)

        if polltemperature:
            '''
                # This is the code that should be, but it requires new
                # firmware.
                while conveyor.task.TaskState.STOPPED != task.state:
                    build_stats = parser.s3g.get_build_stats()
                    build_state = build_stats['BuildState']
                    self._log.debug('build_stats=%r', build_stats)
                    self._log.debug('build_state=%r', build_state)
                    if 0 == build_state or 2 == build_state or 4 == build_state: # TODO: constants for these magic codes
                        break
                    else:
                        time.sleep(0.2) # TODO: wait on a condition
                '''
            while conveyor.task.TaskState.STOPPED != task.state:
                available = parser.s3g.get_available_buffer_size()
                if 512 == available:
                    break
                else:
                    time.sleep(0.2)  # TODO: wait on a condition

        if conveyor.task.TaskState.STOPPED != task.state:
            new_progress = {'name': 'print', 'progress': 100}
            current_progress = self._update_progress(current_progress,
                                                     new_progress, task)
            task.end(None)
コード例 #14
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def runningcallback(task):
     driver = S3gDriver()
     with self._condition:
         driver.resettofactory(self._fp)
     task.end(None)
コード例 #15
0
 def func2(task):
     self.assertTrue(callback1.delivered)
     self.assertFalse(callback2.delivered)
     callback2()
     task.end(None)
コード例 #16
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def runningcallback(task):
     driver = S3gDriver()
     with self._condition:
         driver.writeeeprom(eeprommap, self._fp)
     task.end(None)
コード例 #17
0
 def func(task):
     self.assertFalse(callback.delivered)
     task.heartbeat(None)
     task.end(None)
コード例 #18
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def runningcallback(task):
     driver = S3gDriver()
     with self._condition:
         driver.writeeeprom(eeprommap, self._fp)
     task.end(None)
コード例 #19
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
 def runningcallback(task):
     driver = S3gDriver()
     with self._condition:
         driver.resettofactory(self._fp)
     task.end(None)
コード例 #20
0
ファイル: s3g.py プロジェクト: jsadusk/conveyor
    def _genericprint(
        self, server, portname, profile, buildname, writer, polltemperature,
        pollinterval, gcodepath, skip_start_end, slicer_settings, material,
        task):
            current_progress = None
            new_progress = {
                'name': 'print',
                'progress': 0
            }
            current_progress = self._update_progress(
                current_progress, new_progress, task)
            parser = makerbot_driver.Gcode.GcodeParser()
            parser.state.profile = profile
            parser.state.set_build_name(str(buildname))
            parser.s3g = makerbot_driver.s3g()
            parser.s3g.writer = writer
            def cancelcallback(task):
                try:
                    self._log.debug('setting external stop')
                    writer.set_external_stop()
                except makerbot_driver.Writer.ExternalStopError:
                    self._log.debug('handled exception', exc_info=True)
                if polltemperature:
                    self._log.debug('aborting printer')
                    # NOTE: need a new s3g object because the old one has
                    # external stop set.
                    # TODO: this is a horrible hack.
                    s3g = makerbot_driver.s3g()
                    s3g.writer = makerbot_driver.Writer.StreamWriter(parser.s3g.writer.file)
                    s3g.abort_immediately()
            task.cancelevent.attach(cancelcallback)
            if polltemperature:
                self._log.debug('resetting machine %s', portname)
                parser.s3g.reset()
            now = time.time()
            polltime = now + pollinterval
            if not polltemperature:
                temperature = None
            else:
                temperature = _gettemperature(profile, parser.s3g)
                server.changeprinter(portname, temperature)
            gcodelines, variables = self._gcodelines(
                profile, gcodepath, skip_start_end, slicer_settings, material)
            parser.environment.update(variables)
            # TODO: remove this {current,total}{byte,line} stuff; we have
            # proper progress from the slicer now.
            totallines, totalbytes = self._countgcodelines(gcodelines)
            currentbyte = 0
            for currentline, data in enumerate(gcodelines):
                if conveyor.task.TaskState.RUNNING != task.state:
                    break
                else:
                    # Increment currentbyte *before* stripping whitespace
                    # out of data or the currentbyte will not match the
                    # actual file position.
                    currentbyte += len(data)
                    data = data.strip()
                    now = time.time()
                    if polltemperature and polltime <= now:
                        temperature = _gettemperature(profile, parser.s3g)
                    self._log.debug('gcode: %r', data)
                    # The s3g module cannot handle unicode strings.
                    data = str(data)
                    parser.execute_line(data)
                    new_progress = {
                        'name': 'print',
                        'progress': int(parser.state.percentage)
                    }
                    if polltime <= now:
                        polltime = now + pollinterval
                        if polltemperature:
                            server.changeprinter(portname, temperature)
                    current_progress = self._update_progress(
                        current_progress, new_progress, task)

            if polltemperature:
                '''
                # This is the code that should be, but it requires new
                # firmware.
                while conveyor.task.TaskState.STOPPED != task.state:
                    build_stats = parser.s3g.get_build_stats()
                    build_state = build_stats['BuildState']
                    self._log.debug('build_stats=%r', build_stats)
                    self._log.debug('build_state=%r', build_state)
                    if 0 == build_state or 2 == build_state or 4 == build_state: # TODO: constants for these magic codes
                        break
                    else:
                        time.sleep(0.2) # TODO: wait on a condition
                '''
                while conveyor.task.TaskState.STOPPED != task.state:
                    available = parser.s3g.get_available_buffer_size()
                    if 512 == available:
                        break
                    else:
                        time.sleep(0.2) # TODO: wait on a condition

            if conveyor.task.TaskState.STOPPED != task.state:
                new_progress = {
                    'name': 'print',
                    'progress': 100
                }
                current_progress = self._update_progress(
                    current_progress, new_progress, task)
                task.end(None)
コード例 #21
0
 def func(task):
     callback()
     task.end(None)
コード例 #22
0
ファイル: process.py プロジェクト: jsadusk/conveyor
 def func(task):
     callback()
     task.end(None)
コード例 #23
0
ファイル: process.py プロジェクト: jsadusk/conveyor
 def func(task):
     self.assertFalse(callback.delivered)
     task.heartbeat(None)
     task.end(None)
コード例 #24
0
ファイル: process.py プロジェクト: jsadusk/conveyor
 def func2(task):
     self.assertTrue(callback1.delivered)
     self.assertFalse(callback2.delivered)
     callback2()
     task.end(None)