def takePicture(device, watermark=None, output="webcam.jpg", brightness=50, contrast=50): output = hive.getImageDirectory(output) with mutex: log = logging.getLogger('botqueue') try: # what os are we using myos = hive.determineOS() if myos == "osx": imagesnap = os.path.dirname(os.path.realpath(__file__)) + os.sep + "imagesnap" command = "%s -q -d '%s' -w 2.0 '%s' && " \ "sips --resampleWidth 640" \ " --padToHeightWidth 480 640" \ " --padColor FFFFFF -s formatOptions 60%% '%s' 2>/dev/null" % ( imagesnap, device, output, output ) # log.info("Webcam Command: %s" % command) return __run_picture_command(command, log) elif myos == "raspberrypi" or myos == "linux": if device == "Rasberry Pi Camera": import picamera try: with picamera.PiCamera() as camera: camera.capture(output, resize=(640, 480)) camera.close() return True except picamera.exc.PiCameraError as ex: # No need to log an exception here return False else: command = "exec /usr/bin/fswebcam" \ " -q --jpeg 60 -d '%s'" \ " -r 640x480 --title '%s'" \ " --set brightness=%s%%" \ " --set contrast=%s%% '%s'" % ( device, watermark, brightness, contrast, output ) # log.info("Webcam Command: %s" % command) return __run_picture_command(command, log) else: raise Exception("Webcams are not supported on your OS (%s)." % myos) except Exception as ex: log.exception(ex) return False
def scanCameras(): with mutex: cameras = [] myos = hive.determineOS() if myos == "osx": __scanCamerasOSX(cameras) elif myos == "linux": __scanCameraLinux(cameras) elif myos == "raspberrypi": __scanCameraRaspi(cameras) return cameras
def __init__(self): my_os = hive.determineOS() if my_os == "os": self._camera_control = CameraControlOSX() elif my_os == "linux": self._camera_control = CameraControlLinux() elif my_os == "raspberrypi": self._camera_control = CameraControlRaspberryPi() else: self._camera_control = CameraControl() self.cameras = {} self._timer = None
def __init__(self): my_os = hive.determineOS() if my_os == "os": self._camera_control = CameraControlOSX() elif my_os == "linux": self._camera_control = CameraControlLinux() elif my_os == "raspberrypi": self._camera_control = CameraControlRaspberryPi() else: self._camera_control = CameraControl() self.cameras = {} self._timer = None
def getSlicerPath(self): # Have we already figured out where we are? if self.slicePath and os.path.exists(self.slicePath): return self.slicePath my_os = hive.determineOS() if my_os == "unknown": raise Exception("This engine is not supported on your OS.") # figure out where our path is. realPath = os.path.dirname(os.path.realpath(__file__)) engine_type = self.config['engine']['type'] engine_path = self.config['engine']['path'] sliceEnginePath = "%s/engines/%s/%s" % (realPath, engine_type, engine_path) if not os.path.exists(sliceEnginePath): with Ginsu.downloadLock: self.slicePath = hive.downloadSlicer(engine_path, engine_type, sliceEnginePath) if self.slicePath is None: raise Exception("The requested engine can't be installed.") else: # Change permissions st = os.stat(self.slicePath) os.chmod(self.slicePath, st.st_mode | stat.S_IEXEC) else: user = '******' repo = 'engines' url = "https://raw.github.com/%s/%s/%s-%s/manifest.json" % ( user, repo, my_os, engine_path) manifestFile = "%s-%s-manifest.json" hive.download(url, manifestFile) manifest = json.load(open(manifestFile, 'r')) os.remove(manifestFile) dirName = manifest['directory'] self.slicePath = "%s/%s/%s" % (sliceEnginePath, dirName, manifest['path']) if not (os.path.exists(self.slicePath)): self.log.debug("Cleaning up bad installation") shutil.rmtree(sliceEnginePath) return self.getSlicerPath() return self.slicePath
def getSlicerPath(self): # Have we already figured out where we are? if self.slicePath and os.path.exists(self.slicePath): return self.slicePath my_os = hive.determineOS() if my_os == "unknown": raise Exception("This engine is not supported on your OS.") # figure out where our path is. realPath = os.path.dirname(os.path.realpath(__file__)) engine_type = self.config['engine']['type'] engine_path = self.config['engine']['path'] sliceEnginePath = "%s/engines/%s/%s" % (realPath, engine_type, engine_path) if not os.path.exists(sliceEnginePath): with Ginsu.downloadLock: self.slicePath = hive.downloadSlicer(engine_path, engine_type, sliceEnginePath) if self.slicePath is None: raise Exception("The requested engine can't be installed.") else: # Change permissions st = os.stat(self.slicePath) os.chmod(self.slicePath, st.st_mode | stat.S_IEXEC) else: user = '******' repo = 'engines' url = "https://raw.github.com/%s/%s/%s-%s/manifest.json" % (user, repo, my_os, engine_path) manifestFile = "%s-%s-manifest.json" hive.download(url, manifestFile) manifest = json.load(open(manifestFile, 'r')) os.remove(manifestFile) dirName = manifest['directory'] self.slicePath = "%s/%s/%s" % (sliceEnginePath, dirName, manifest['path']) if not (os.path.exists(self.slicePath)): self.log.debug("Cleaning up bad installation") shutil.rmtree(sliceEnginePath) return self.getSlicerPath() return self.slicePath
def run_process(self, command, output_file, cwd, output_callback): try: if hive.determineOS() != "win": command = "exec " + command self.log.info("Slice Command: %s" % command) outputLog = "" errorLog = "" # this starts our thread to slice the model into gcode self.p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cwd) self.log.info("%s started." % self.name) while self.p.poll() is None: output = self.p.stdout.readline() if output: self.log.info("%s: %s" % (self.name, output.strip())) outputLog = outputLog + output output_callback(output) time.sleep(0.1) # did we get cancelled? if not self.running: self.p.terminate() self.p.kill() return # this code does not work for some reason and ends up blocking the loop # until program exits if there is no errors # this is a bummer, because we can't get realtime error logging. :( # err = self.p.stderr.readline().strip() # if err: # self.log.error("Slic3r: %s" % error) # errorLog = errorLog + err # get any last lines of output output = self.p.stdout.readline() while output: self.log.debug("%s: %s" % (self.name, output.strip())) outputLog = outputLog + output output_callback(output) output = self.p.stdout.readline() # get our errors (if any) error = self.p.stderr.readline() while error: self.log.error("%s: %s" % (self.name, error.strip())) errorLog = errorLog + error error = self.p.stderr.readline() # give us 1 second for the main loop to pull in our finished status. time.sleep(1) # save all our results to an object sushi = hive.Object sushi.output_file = output_file.name sushi.output_log = outputLog sushi.error_log = errorLog # did we get errors? if errorLog: sushi.status = "pending" # unknown return code... failure elif self.p.returncode > 0: sushi.status = "failure" self.log.error("Program returned code %s" % self.p.returncode) else: sushi.status = "complete" # okay, we're done! self.running = False return sushi except Exception as ex: self.log.exception(ex)
def run_process(self, command, output_file, cwd, output_callback): try: if hive.determineOS() != "win": command = "exec " + command self.log.info("Slice Command: %s" % command) outputLog = "" errorLog = "" # this starts our thread to slice the model into gcode self.p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cwd) self.log.info("%s started." % self.name) while self.p.poll() is None: output = self.p.stdout.readline() if output: self.log.info("%s: %s" % (self.name, output.strip())) outputLog = outputLog + output output_callback(output) time.sleep(0.1) # did we get cancelled? if not self.running: self.p.terminate() self.p.kill() return # this code does not work for some reason and ends up blocking the loop # until program exits if there is no errors # this is a bummer, because we can't get realtime error logging. :( # err = self.p.stderr.readline().strip() # if err: # self.log.error("Slic3r: %s" % error) # errorLog = errorLog + err # get any last lines of output output = self.p.stdout.readline() while output: self.log.debug("%s: %s" % (self.name, output.strip())) outputLog = outputLog + output output_callback(output) output = self.p.stdout.readline() # get our errors (if any) error = self.p.stderr.readline() while error: self.log.error("%s: %s" % (self.name, error.strip())) errorLog = errorLog + error error = self.p.stderr.readline() # give us 1 second for the main loop to pull in our finished status. time.sleep(1) # save all our results to an object sushi = hive.Object sushi.output_file = output_file.name sushi.output_log = outputLog sushi.error_log = errorLog # did we get errors? if errorLog: sushi.status = "pending" # unknown return code... failure elif self.p.returncode > 0: sushi.status = "failure" self.log.error("Program returned code %s" % self.p.returncode) else: sushi.status = "complete" # okay, we're done! self.running = False return sushi except Exception as ex: self.log.exception(ex)