Get the state of the requested app
516293
def get_app_state(device_id, app_id):
    
    if not is_valid_app_id(app_id):
        abort(403)
    if not is_valid_device_id(device_id):
        abort(403)
    if device_id not in devices:
        abort(404)
    app_state = devices[device_id].app_state(app_id)
    return jsonify(state=app_state, status=app_state)
265372
def init_app(self, app):
        
        state = self.init_mail(app.config, app.debug, app.testing)

        # register extension with app
        app.extensions = getattr(app, 'extensions', {})
        app.extensions['mail'] = state
        return state
114118
def is_state(self, entity_id, state):
        """"""
        return remote.is_state(self.api, entity_id, state)
1188846
def check_application_state(self, request, callback):
        ""
        stored = request.session.get(self.session_key, None)
        returned = request.GET.get('state', None)
        check = False
        if stored is not None:
            if returned is not None:
                check = constant_time_compare(stored, returned)
            else:
                logger.error('No state parameter returned by the provider.')
        else:
            logger.error('No state stored in the sesssion.')
        return check
51043
def app_update_state(app_id,state):
    
    try:
        create_at = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        conn = get_conn()
        c = conn.cursor()
        c.execute("UPDATE app SET state='{0}',change_at='{1}' WHERE id='{2}'".format(state, create_at, app_id))
        conn.commit()
        conn.close()
        print 'UPDATE app %s state to %s succeed!' % (app_id,state)
    except Exception, e:
        raise RuntimeError( 'update app %s state to %s failed! %s' % (app_id,state,e) )
43417
def info(self):
        """"""

        return self._h._get_resource(
            resource=('apps', self.name),
            obj=App,
        )
1047960
def get_status(self):
        
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url,
            headers={
                "Accept": Consts.mediaTypeMigrationPreview
            }
        )
        self._useAttributes(data)
        return self.state
707124
ServerStatus getState() {
        final InternalState requiredState = this.requiredState;
        final InternalState state = internalState;
        if(requiredState == InternalState.FAILED) {
            return ServerStatus.FAILED;
        }
        switch (state) {
            case STOPPED:
                return ServerStatus.STOPPED;
            case SERVER_STARTED:
                return  ServerStatus.STARTED;
            default: {
                if(requiredState == InternalState.SERVER_STARTED) {
                    return ServerStatus.STARTING;
                } else {
                    return ServerStatus.STOPPING;
                }
            }
        }
    }
219068
def status(app_name=None, only_cozy=False, as_boolean=False):
    '''
    '''
    apps = {}
    # Get all apps status & slip them
    apps_status = subprocess.Popen('cozy-monitor status',
                                   shell=True,
                                   stdout=subprocess.PIPE).stdout.read()
    apps_status = apps_status.split('\n')

    # Parse result to store them in apps dictionary
    for app_status in apps_status:
        if app_status:
            app_status = ANSI_ESCAPE.sub('', app_status).split(': ')
            if len(app_status) == 2:
                current_status = app_status[1]
                if as_boolean:
                    if app_status[1] == 'up':
                        current_status = True
                    else:
                        current_status = False
                if only_cozy and app_status[0] not in SYSTEM_APPS:
                    apps[app_status[0]] = current_status
                else:
                    apps[app_status[0]] = current_status

    # Return app status if get as param or return all apps status
    if app_name:
        return apps.get(app_name, None)
    else:
        return apps
1060516
def update_state_from_api(self):
        
        if self.last_api_call is not None:
            difference = (datetime.datetime.now() - self.last_api_call).seconds
        else:
            # This is the first run, so we need to get the lastest state.
            difference = 301
        if difference >= 300:
            url = BASE_URL + "/rest/item"
            payload = {'usertoken': self.token}
            arequest = requests.get(url, params=payload)
            status = str(arequest.status_code)
            if status == '401':
                _LOGGER.info("Token expired? Trying to get a new one.")
                self.authenticate(True)
                arequest = requests.get(url, params=payload)
                status = arequest.status_code
            elif status == '404':
                _LOGGER.error("No devices associated with this account.")
            elif status != '200':
                _LOGGER.error("API error not updating state. " + status)
            else:
                self.state = arequest.json()
            self.last_api_call = datetime.datetime.now()
            _LOGGER.info("Pulled latest state from API.")
607434
def get_valid_app_auth(self, app_uri):
        

        ret, retInfo = self.get_app_keys(app_uri)

        if ret is None:
            return None

        for k in ret:
            if (k.get('state') == 'enabled'):
                return QiniuMacAuth(k.get('ak'), k.get('sk'))

        return None
1005224
def get_app_info(app_id):
    
    try:
        conn = get_conn()
        c = conn.cursor()
        c.execute("SELECT name,source_id,region,state,create_at,change_at FROM app WHERE id='{0}' ".format(app_id))
        app_info = c.fetchone()
        c.execute("SELECT app_data FROM app WHERE id='{0}' ".format(app_id))
        app_data = c.fetchone()
        c.execute("SELECT id,name,app_id FROM container WHERE app_id='{0}' ".format(app_id))
        container_rlt = c.fetchall()
        conn.close()
        return (app_info, app_data, container_rlt)
    except Exception,e:
        raise RuntimeError('get app info failed! %s' % e)
52056
def get_state(self, state):
        """"""
        # Check to see if we have a change request pending; if we do
        # return the value we expect it to change to.
        for data in list(self._send_queue.queue):
            desired_states = data['desired_states']
            for desired_state in desired_states:
                if desired_state['state'] == state:
                    return desired_state['enabled']
        if state == States.FILTER_LOW_SPEED:
            return (States.FILTER.value & self._flashing_states) != 0
        return (state.value & self._states) != 0
179262
def state(self):
        """"""
        state = self._resource.get('state', self.default_state)

        if state in State:
            return state
        else:
            return getattr(State, state)
356747
def get_state(self):
        """"""
        return {"started": (True if self.background_process and
                            self.background_process.is_alive() else False),
                "paused": self._pause.value,
                "stopped": self._end.value,
                "tasks": len(self.current_tasks),
                "busy_tasks": len(self.busy_tasks),
                "free_tasks": len(self.free_tasks)}
1291948
def _create_get_state_request(self, given_devices):
        """"""
        dev_list = []

        if isinstance(given_devices, list):
            devices = given_devices
        else:
            devices = []
            for dev_name, item in self.__devices.items():
                if item:
                    devices.append(self.__devices[dev_name])

        for device in devices:
            states = []

            for state_name in sorted(device.active_states.keys()):
                states.append({'name': state_name})

            dev_list.append({'deviceURL': device.url, 'states': states})

        return json.dumps(
            dev_list, indent=None,
            sort_keys=True, separators=(',', ': '))
1298573
private FinalApplicationStatus getYarnStatus(ApplicationStatus status) {
		if (status == null) {
			return FinalApplicationStatus.UNDEFINED;
		}
		else {
			switch (status) {
				case SUCCEEDED:
					return FinalApplicationStatus.SUCCEEDED;
				case FAILED:
					return FinalApplicationStatus.FAILED;
				case CANCELED:
					return FinalApplicationStatus.KILLED;
				default:
					return FinalApplicationStatus.UNDEFINED;
			}
		}
	}