def __nm_command(self, args, json=False, sudo=True):
        network_manager_path = os.path.join(os.path.dirname(__file__),
                                            'network_manager.py')
        cmdline = []
        if sudo:
            cmdline.append('sudo')

        cmdline.append(network_manager_path)
        cmdline.extend(args)
        # logger.debug(cmdline)
        proc = subprocess.run(cmdline,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
        if proc.returncode != 0:
            raise FailedMethodError(
                'Error running NetworkManager command: {}'.format(proc.stderr))
        if json:
            return JSON.loads(proc.stdout)
        return proc.stdout
Beispiel #2
0
 def dither(self,
            pixels,
            settle_pixels,
            settle_time,
            settle_timeout,
            ra_only=False,
            wait_for_settle=False):
     settle_object = {
         'pixels': settle_pixels,
         'time': settle_time,
         'timeout': settle_timeout,
     }
     try:
         result = self.__execute('dither',
                                 pixels,
                                 ra_only,
                                 settle_object,
                                 wait_for_settle=True)
         return result
     except PHD2MethodError as e:
         raise FailedMethodError(e.get_message())
Beispiel #3
0
    def run(self, request_obj):
        subprocess_env = os.environ
        arguments = self.arguments.copy()
        if 'parameters' in request_obj:
            logger.debug('Command parameters: {}'.format(
                request_obj['parameters']))
            arguments.extend([p['value'] for p in request_obj['parameters']])
        logger.debug('Command arguments: {}'.format(arguments))

        try:
            result = subprocess.run(arguments,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            return {
                'exit_code': result.returncode,
                'stdout': result.stdout.decode() if result.stdout else None,
                'stderr': result.stderr.decode() if result.stderr else None,
            }
        except Exception as e:
            raise FailedMethodError(str(e))
Beispiel #4
0
    def solve_field(self, options):
        data = None
        fits_file = None
        logger.debug('Solve field options: {}'.format([
            '{}: {}'.format(key, '<blob>' if key == 'fileBuffer' else value)
            for key, value in options.items()
        ]))
        if 'fileBuffer' in options:
            data = base64.b64decode(
                options['fileBuffer']
                [options['fileBuffer'].find(Astrometry.DATAURL_SEPARATOR) +
                 len(Astrometry.DATAURL_SEPARATOR):])
        elif 'filePath' in options and os.path.isfile(options['filePath']):
            with open(options['filePath'], 'rb') as f:
                data = f.read()
        else:
            raise BadRequestError(
                'You must pass either a fileBuffer object (data-uri formatted) or a filePath argument'
            )
        fits_file = fits.open(BytesIO(data))
        resolution = fits_file[0].data.shape

        self.__set_enabled(True)
        try:
            controller.controller.indi_server.event_listener.add(
                'astrometry', self.event_listener)
            self.__set_astrometry_options(options)
            wait_for_solver_thread = threading.Thread(
                target=self.event_listener.wait_for_solver,
                args=(self.__solver_status(), ))
            wait_for_solver_thread.start()
            self.__upload_blob(data)
            logger.debug('Waiting for solver to finish')
            wait_for_solver_thread.join()
            if self.event_listener.error:
                raise self.event_listener.error

            final_status = self.__solver_status()
            if final_status == 'OK':
                solution_property = self.device.get_property(
                    'ASTROMETRY_RESULTS').to_map()
                solution_values = dict([(v['name'], v['value'])
                                        for v in solution_property['values']])
                solution_property['values'].append({
                    'label':
                    'Field width',
                    'name':
                    'ASTROMETRY_RESULTS_WIDTH',
                    'value':
                    resolution[1] *
                    solution_values['ASTROMETRY_RESULTS_PIXSCALE'] / 3600.
                })
                solution_property['values'].append({
                    'label':
                    'Field height',
                    'name':
                    'ASTROMETRY_RESULTS_HEIGHT',
                    'value':
                    resolution[0] *
                    solution_values['ASTROMETRY_RESULTS_PIXSCALE'] / 3600.
                })
                if options['syncTelescope']:

                    logger.debug(solution_values)
                    telescope = [
                        t for t in self.server.telescopes()
                        if t.id == options['telescope']
                    ]
                    if not telescope:
                        raise NotFoundError(
                            'Unable to find telescope {}'.format(telescope))
                    telescope = telescope[0]
                    telescope_coordinates = {
                        'ra':
                        solution_values['ASTROMETRY_RESULTS_RA'] *
                        (24. / 360.),
                        'dec':
                        solution_values['ASTROMETRY_RESULTS_DE']
                    }
                    telescope.sync(telescope_coordinates)
                return {'status': 'OK', 'solution': solution_property}
            else:
                raise FailedMethodError(
                    'Plate solving failed, check astrometry driver log')
        finally:
            controller.controller.indi_server.event_listener.remove(
                'astrometry')
            self.__set_enabled(False)
Beispiel #5
0
def set_timestamp(timestamp):
    timestamp = int(timestamp)
    if not __set_timestamp_timedatectl(timestamp):
        if not __set_timestamp_date(timestamp):
            raise FailedMethodError('Unable to set system time')
    return get_timestamp()
    def __wait_for_solution(self, options, resolution, fits_file_path,
                            temp_path):
        try:
            solved, solution = self.__run_solve_field(options, fits_file_path,
                                                      temp_path)
            if solved:
                solution_property = {'values': []}
                solution_property['values'].append({
                    'label':
                    'Right ascension',
                    'name':
                    'ASTROMETRY_RESULTS_RA',
                    'value':
                    solution['ASTROMETRY_RESULTS_RA']
                })
                solution_property['values'].append({
                    'label':
                    'Declination',
                    'name':
                    'ASTROMETRY_RESULTS_DE',
                    'value':
                    solution['ASTROMETRY_RESULTS_DE']
                })
                solution_property['values'].append({
                    'label':
                    'Pixel scale',
                    'name':
                    'ASTROMETRY_RESULTS_PIXSCALE',
                    'value':
                    solution['ASTROMETRY_RESULTS_PIXSCALE']
                })
                solution_property['values'].append({
                    'label':
                    'Field width',
                    'name':
                    'ASTROMETRY_RESULTS_WIDTH',
                    'value':
                    resolution[1] * solution['ASTROMETRY_RESULTS_PIXSCALE'] /
                    3600.
                })
                solution_property['values'].append({
                    'label':
                    'Field height',
                    'name':
                    'ASTROMETRY_RESULTS_HEIGHT',
                    'value':
                    resolution[0] * solution['ASTROMETRY_RESULTS_PIXSCALE'] /
                    3600.
                })
                if solution['ASTROMETRY_RESULTS_ORIENTATION'] is not None:
                    solution_property['values'].append({
                        'label':
                        'Field rotation (degrees E of N)',
                        'name':
                        'ASTROMETRY_RESULTS_ORIENTATION',
                        'value':
                        solution['ASTROMETRY_RESULTS_ORIENTATION']
                    })

                if options.get('syncTelescope'):
                    telescope = [
                        t for t in self.server.telescopes()
                        if t.id == options['telescope']
                    ]
                    if not telescope:
                        raise NotFoundError(
                            'Unable to find telescope {}'.format(telescope))
                    telescope = telescope[0]
                    telescope_coordinates = {
                        'ra': solution['ASTROMETRY_RESULTS_RA'] * (24. / 360.),
                        'dec': solution['ASTROMETRY_RESULTS_DE']
                    }
                    telescope.sync(telescope_coordinates)
                return {
                    'status': 'solved',
                    'solution': solution_property,
                }
            else:
                raise FailedMethodError(
                    'Plate solving failed, check astrometry driver log')
        except Exception as e:
            logger.warning('Error running platesolver with options {}'.format(
                self.__platesolving_options_log(options)),
                           exc_info=e)
            self.__set_status('error')
            return {
                'status': 'error',
                'error': str(e),
            }
        finally:
            shutil.rmtree(temp_path, True)
            self.solver_thread = None
            if not options.get('internalSkipIdle', False):
                self.__set_status('idle')