Ejemplo n.º 1
0
def take_picture(camera: gp.camera,
                 rotation_pos: int, declination_pos: int,
                 queue: beanstalk.Connection) -> str:
    """take a picture and save it to the USB drive
    or the google drive, if specified"""

    # take the picture
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE))
    file_name = 'P{dec:02d}{rot:02d}_'.\
                    format(dec=declination_pos, rot=rotation_pos) + file_path.name

    # read the photo from the camera
    camera_file = gp.check_result(gp.gp_camera_file_get(camera,
                                                        file_path.folder,
                                                        file_path.name,
                                                        gp.GP_FILE_TYPE_NORMAL))

    # if a google drive isn't specified, write to the local USB drive
    # read the image from the camera into memory
    # and upload it
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))

    # okay, upload to the Google drive via a thread...
    byte_stream = io.BytesIO(file_data)
    camera_bytes = byte_stream.read(-1)
    job = {'task': 'photo',
           'filename': file_name,
           'data': base64.encodebytes(camera_bytes).decode('ascii')}
    # now send the photo to the Google Drive process
    queue.use(google_drive.GDRIVE_QUEUE)
    job_str = json.dumps(job)
    print("photo job size is {0} bytes".format(len(job_str)))
    queue.put(job_str)
    return file_name
Ejemplo n.º 2
0
def post_status(queue: beanstalk.Connection, message: str) -> None:
    """post a simple message to whomever is listening"""
    print(message)  # echo message to stdout
    if queue:
        queue.use(STATUS_QUEUE)
        status_json = json.dumps({'msg': message})
        queue.put(status_json)
Ejemplo n.º 3
0
def main():
    parser = OptionParser()
    parser.add_option("--i", default=50)
    parser.add_option("--n", default=10)
    parser.add_option("--tube", default="default")
    
    options, args = parser.parse_args()

    conn = Connection(HOST, PORT)
    conn.use(options.tube)

    for i in range(int(options.n)):
        conn.put(str(i))
Ejemplo n.º 4
0
def send_cancel_request(queue: beanstalk.Connection) -> int:
    """send a cancel request to the rig controller"""
    clear_status_queue(queue)   # so we see what home command triggers

    queue.use(CANCEL_QUEUE)
    task_body = json.dumps({'task': 'cancel'})
    return queue.put(task_body)
Ejemplo n.º 5
0
def send_home_command(queue: beanstalk.Connection) -> int:
    """send a home command to home the rig"""

    clear_status_queue(queue)   # so we see what home command triggers

    queue.use(TASK_QUEUE)
    task_body = json.dumps({'task': 'home'})
    return queue.put(task_body)
Ejemplo n.º 6
0
def send_token(queue: beanstalk.Connection, body_str: str) -> int:
    """send the google token so we can save photos to a google drive"""
    queue.use(TASK_QUEUE)
    job_body = json.dumps({'task':'token', 'value': body_str})
    job_id = queue.put(job_body)

    # **********************
    # test_write_file(queue)
    # **********************
    return job_id
Ejemplo n.º 7
0
def send_scan_command(queue: beanstalk.Connection,
                      declination_steps: int,
                      rotation_steps: int,
                      start: int, stop: int) -> int:
    """this is it - time to scan. send the # of steps for each axis
    and return"""
    queue.use(TASK_QUEUE)
    task_body = json.dumps({'task': 'scan',
                            'steps': {'declination': declination_steps,
                                      'rotation': rotation_steps},
                            'offsets': {'start': start, 'stop': stop}
                            })
    return queue.put(task_body)
Ejemplo n.º 8
0
class JobWorkerClient(object):
    """
    job client.
    """
    def __init__(self, host, port, tube=None):
        self.__host = host
        self.__port = port
        self.__tube = tube
        self.__bs = None

    def _ensure_connect(self):
        if self.__bs is None:
            print 'beanstalkc client connecting ...'
            self.__bs = Connection(self.__host, self.__port)
            print 'beanstalkc client connected to %s:%s:[%s]' % (
                self.__host, self.__port, self.__tube)
            if not self.__tube is None:
                self.__bs.use(self.__tube)
                print 'beanstalkc client using %s' % self.__bs.using()

    def put(self, obj):
        self._ensure_connect()
        self.__bs.put(json.dumps(obj))

    def use_put(self, tube, obj):
        self._ensure_connect()
        self.__bs.use(tube)
        self.__bs.put(json.dumps(obj))

    def use(self, tube):
        self._ensure_connect()
        self.__bs.use(tube)
        self.__tube = tube

    def close(self):
        try:
            self.__bs.close()
        except:
            pass
Ejemplo n.º 9
0
class JobWorkerClient(object):
    """
    job client.
    """
    def __init__(self, host, port, tube=None):
        self.__host = host
        self.__port = port
        self.__tube = tube    
        self.__bs = None
        
    def _ensure_connect(self):
        if self.__bs is None:
            print 'beanstalkc client connecting ...'
            self.__bs = Connection(self.__host, self.__port)
            print 'beanstalkc client connected to %s:%s:[%s]' % (self.__host, self.__port, self.__tube)
            if not self.__tube is None:
                self.__bs.use(self.__tube)
                print 'beanstalkc client using %s' % self.__bs.using()
        
    def put(self,obj):
        self._ensure_connect()
        self.__bs.put(json.dumps(obj))
    
    def use_put(self, tube, obj):
        self._ensure_connect()
        self.__bs.use(tube)
        self.__bs.put(json.dumps(obj))
    
    def use(self, tube):
        self._ensure_connect()
        self.__bs.use(tube)
        self.__tube = tube
    
    def close(self):
        try:
            self.__bs.close()
        except:
            pass
Ejemplo n.º 10
0
def send_cancel(queue: beanstalk.Connection) -> int:
    """send a cancel to the rig software to stop whatever is
    happening"""
    queue.use(CANCEL_QUEUE)
    return queue.put('STOP!') # anything will do
Ejemplo n.º 11
0
def session_start(queue: beanstalk.Connection) -> None:
    """before scanning, we need to start a 'session', which
    basically means doing any pre-scanning work. So we will
    shoot the drive process a message to kick off this activity"""
    queue.use(google_drive.GDRIVE_QUEUE)
    queue.put(json.dumps({'task': 'session_start'}))
Ejemplo n.º 12
0
def forward_authorization(queue: beanstalk.Connection, job: dict):
    """Forward the Google Drive authentication credentials to our
    Google Drive process"""
    queue.use(google_drive.GDRIVE_QUEUE)
    queue.put(json.dumps(job))