当前位置: 首页>>代码示例>>Python>>正文


Python Session.commit方法代码示例

本文整理汇总了Python中fts3rest.lib.base.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fts3rest.lib.base.Session的用法示例。


在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_access_granted

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def get_access_granted(self):
        dropbox_user_info = self._get_dropbox_user_info()
        if not dropbox_user_info:
            raise HTTPBadRequest('No registered user for the service "%s" has been found' % self.service)

        dropbox_info = self._get_dropbox_info()
        if not dropbox_info:
            raise HTTPNotFound('Dropbox info not found in the databse')

        access_tokens = self._make_call(
            dropboxApiEndpoint + "/1/oauth/access_token",
            'OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="' +
            dropbox_info.app_key + '", oauth_token="' + dropbox_user_info.request_token +
            '", oauth_signature="' + dropbox_info.app_secret + '&' + dropbox_user_info.request_token_secret + '"',
            None
        )

        # It returns: oauth_token=<access-token>&oauth_token_secret=<access-token-secret>&uid=<user-id>
        access_tokens = access_tokens.split('&')
        dropbox_user_info.access_token = access_tokens[1].split('=')[1]
        dropbox_user_info.access_token_secret = access_tokens[0].split('=')[1]
        try:
            Session.add(dropbox_user_info)
            Session.commit()
        except:
            Session.rollback()
            raise

        return access_tokens
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:31,代码来源:CSdropbox.py

示例2: cancel

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
	def cancel(self, id, **kwargs):
		"""DELETE /jobs/id: Delete an existing item"""
		job = self._getJob(id)
		
		if job.job_state in JobActiveStates:
			now = datetime.now()
			
			job.job_state    = 'CANCELED'
			job.finish_time  = now
			job.job_finished = now
			job.reason       = 'Job canceled by the user'
			
			for f in job.files:
				if f.file_state in JobActiveStates:
					f.file_state   = 'CANCELED'
					f.job_finished = now
					f.finish_time  = now
					f.reason       = 'Job canceled by the user'
				
			Session.merge(job)
			Session.commit()
			
			job = self._getJob(id)

		files = job.files
		return job
开发者ID:mhellmic,项目名称:fts3,代码行数:28,代码来源:jobs.py

示例3: get_access_requested

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def get_access_requested(self):
        dropbox_info = self._get_dropbox_info()
        request_tokens = self._make_call(
            dropboxApiEndpoint + "/1/oauth/request_token",
            'OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT",'
            'oauth_consumer_key="' + dropbox_info.app_key + '", oauth_signature="' + dropbox_info.app_secret + '&"',
            None
        )

        # It returns: oauth_token_secret=b9q1n5il4lcc&oauth_token=mh7an9dkrg59
        tokens = request_tokens.split('&')
        newuser = CloudStorageUser(
            user_dn=self.user_dn,
            cloudStorage_name=dropbox_info.cloudStorage_name,
            request_token=tokens[1].split('=')[1],
            request_token_secret=tokens[0].split('=')[1]
        )
        try:
            Session.add(newuser)
            Session.commit()
        except:
            Session.rollback()
            raise

        return request_tokens
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:27,代码来源:CSdropbox.py

示例4: test_get_retries

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def test_get_retries(self):
        """
        Get the retries for a file, forcing one
        """
        self.setup_gridsite_environment()
        self.push_delegation()
        job_id = self._submit()

        answer = self.app.get(url="/jobs/%s/files" % job_id, status=200)
        files = json.loads(answer.body)
        file_id = files[0]['file_id']

        retry = FileRetryLog()
        retry.file_id = file_id
        retry.attempt = 1
        retry.datetime = datetime.utcnow()
        retry.reason = 'Blahblahblah'

        Session.merge(retry)
        Session.commit()

        answer = self.app.get(url="/jobs/%s/files/%d/retries" % (job_id, file_id), status=200)
        retries = json.loads(answer.body)

        self.assertEqual(1, len(retries))
        self.assertEqual(1, retries[0]['attempt'])
        self.assertEqual('Blahblahblah', retries[0]['reason'])
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:29,代码来源:test_job_listing.py

示例5: test_set_voms

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def test_set_voms(self):
        """
        The server must regenerate a proxy with VOMS extensions
        Need a real proxy for this one
        """
        self.setup_gridsite_environment()
        creds = self.get_user_credentials()

        # Need to push a real proxy :/
        proxy_pem = self.get_real_x509_proxy()
        if proxy_pem is None:
            raise SkipTest('Could not get a valid real proxy for test_set_voms')

        proxy = Credential()
        proxy.dn = creds.user_dn
        proxy.dlg_id = creds.delegation_id
        proxy.termination_time = datetime.utcnow() + timedelta(hours=1)
        proxy.proxy = proxy_pem
        Session.merge(proxy)
        Session.commit()

        # Now, request the voms extensions
        self.app.post(url="/delegation/%s/voms" % creds.delegation_id,
                      content_type='application/json',
                      params=json.dumps(['dteam:/dteam/Role=lcgadmin']),
                      status=203)

        # And validate
        proxy2 = Session.query(Credential).get((creds.delegation_id, creds.user_dn))
        self.assertNotEqual(proxy.proxy, proxy2.proxy)
        self.assertEqual('dteam:/dteam/Role=lcgadmin', proxy2.voms_attrs)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:33,代码来源:test_delegation.py

示例6: test_cancel_terminal

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def test_cancel_terminal(self):
        """
        Cancel a job with files in terminal state
        """
        job_id = self._submit()

        job = Session.query(Job).get(job_id)
        job.job_state = 'FINISHED'
        for f in job.files:
            f.file_state = 'FINISHED'
        Session.merge(job)
        Session.commit()

        answer = self.app.delete(url="/jobs/%s" % job_id,
                                 status=200)
        job = json.loads(answer.body)

        self.assertEqual(job['job_id'], job_id)
        self.assertEqual(job['job_state'], 'FINISHED')
        self.assertNotEqual(job['reason'], 'Job canceled by the user')

        # Is it in the database?
        job = Session.query(Job).get(job_id)
        self.assertEqual(job.job_state, 'FINISHED')
        for f in job.files:
            self.assertEqual(f.file_state, 'FINISHED')
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:28,代码来源:test_job_cancel.py

示例7: test_expired

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def test_expired(self):
        """
        Get a token, the token expires, so it should be denied
        """
        client_id, access_token, refresh_token, expires = self.test_get_token()
        del self.app.extra_environ['GRST_CRED_AURI_0']

        response = self.app.get(
            url="/whoami",
            headers={'Authorization': str('Bearer %s' % access_token)},
            status=200
        )
        whoami = json.loads(response.body)
        self.assertEqual('oauth2', whoami['method'])

        token = Session.query(OAuth2Token).get((client_id, refresh_token))
        token.expires = datetime.utcnow() - timedelta(hours=1)
        Session.merge(token)
        Session.commit()

        response = self.app.get(
            url="/whoami",
            headers={'Authorization': str('Bearer %s' % access_token)},
            status=403
        )
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:27,代码来源:test_oauth.py

示例8: _cancel_jobs

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
def _cancel_jobs(dn):
    """
    Cancel all jobs that belong to dn.
    Returns the list of affected jobs ids.
    """
    jobs = Session.query(Job.job_id).filter(Job.job_state.in_(JobActiveStates)).filter(Job.user_dn == dn)
    job_ids = map(lambda j: j[0], jobs)

    try:
        now = datetime.utcnow()
        for job_id in job_ids:
            Session.query(File).filter(File.job_id == job_id).filter(File.file_state.in_(FileActiveStates))\
                .update({
                    'file_state': 'CANCELED', 'reason': 'User banned',
                    'job_finished': now, 'finish_time': now
                }, synchronize_session=False)
            Session.query(Job).filter(Job.job_id == job_id)\
                .update({
                    'job_state': 'CANCELED', 'reason': 'User banned',
                    'job_finished': now, 'finish_time': now
                }, synchronize_session=False)
        Session.commit()
	Session.expire_all()
        return job_ids
    except Exception:
        Session.rollback()
        raise
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:29,代码来源:banning.py

示例9: popDelegation

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
	def popDelegation(self):
		cred = self.getUserCredentials()
		if cred and cred.delegation_id:
			delegated = Session.query(Credential).get((cred.delegation_id, cred.user_dn))
			if delegated:
				Session.delete(delegated)
				Session.commit()
开发者ID:mhellmic,项目名称:fts3,代码行数:9,代码来源:__init__.py

示例10: request

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def request(self, dlg_id, start_response):
        """
        First step of the delegation process: get a certificate request

        The returned certificate request must be signed with the user's original
        credentials.
        """
        user = request.environ['fts3.User.Credentials']

        if dlg_id != user.delegation_id:
            raise HTTPForbidden('The requested ID and the credentials ID do not match')

        credential_cache = Session.query(CredentialCache)\
            .get((user.delegation_id, user.user_dn))

        if credential_cache is None or credential_cache.cert_request is None:
            (x509_request, private_key) = _generate_proxy_request()
            credential_cache = CredentialCache(dlg_id=user.delegation_id, dn=user.user_dn,
                                               cert_request=x509_request.as_pem(),
                                               priv_key=private_key.as_pem(cipher=None),
                                               voms_attrs=' '.join(user.voms_cred))
            try:
                Session.merge(credential_cache)
                Session.commit()
            except Exception:
                Session.rollback()
                raise
            log.debug("Generated new credential request for %s" % dlg_id)
        else:
            log.debug("Using cached request for %s" % dlg_id)

        start_response('200 Ok', [('X-Delegation-ID', credential_cache.dlg_id),
                                  ('Content-Type', 'text/plain')])
        return [credential_cache.cert_request]
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:36,代码来源:delegation.py

示例11: update_app

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def update_app(self, client_id):
        """
        Update an application
        """
        user = pylons.request.environ['fts3.User.Credentials']
        app = Session.query(OAuth2Application).get(client_id)
        if not app:
            raise HTTPNotFound('Application not found')
        if app.owner != user.user_dn:
            raise HTTPForbidden()
        if pylons.request.headers['Content-Type'].startswith('application/json'):
            fields = json.loads(pylons.request.body)
        else:
            fields = pylons.request.POST

        try:
            if 'delete' not in fields:
                app.description = fields.get('description', '')
                app.website = fields.get('website', '')
                app.redirect_to = fields.get('redirect_to', '')
                Session.merge(app)
                Session.commit()
                redirect(url_for(controller='oauth2', action='get_app'), code=HTTPSeeOther.code)
            else:
                Session.delete(app)
                Session.query(OAuth2Token).filter(OAuth2Token.client_id == client_id).delete()
                Session.query(OAuth2Code).filter(OAuth2Code.client_id == client_id).delete()
                Session.commit()
                redirect(url_for(controller='oauth2', action='get_my_apps'), code=HTTPSeeOther.code)
        except:
            Session.rollback()
            raise
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:34,代码来源:oauth2.py

示例12: pop_delegation

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
 def pop_delegation(self):
     """
     Remove the mock proxy from the database
     """
     cred = self.get_user_credentials()
     if cred and cred.delegation_id:
         delegated = Session.query(Credential).get((cred.delegation_id, cred.user_dn))
         if delegated:
             Session.delete(delegated)
             Session.commit()
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:12,代码来源:__init__.py

示例13: tearDown

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
 def tearDown(self):
     """
     Called by the test framework at the end of each test
     """
     Session.query(Credential).delete()
     Session.query(CredentialCache).delete()
     Session.query(FileRetryLog).delete()
     Session.query(File).delete()
     Session.query(Job).delete()
     Session.query(OptimizerActive).delete()
     Session.commit()
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:13,代码来源:__init__.py

示例14: pushDelegation

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
	def pushDelegation(self, lifetime = timedelta(hours = 7)):
		creds = self.getUserCredentials()
		delegated = Credential()
		delegated.dlg_id     = creds.delegation_id
		delegated.dn         = creds.user_dn
		delegated.proxy      = '-NOT USED-'
		delegated.voms_attrs = None
		delegated.termination_time = datetime.now() + lifetime
		
		Session.merge(delegated)
		Session.commit()
开发者ID:mhellmic,项目名称:fts3,代码行数:13,代码来源:__init__.py

示例15: test_ban_dn_submission

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import commit [as 别名]
    def test_ban_dn_submission(self):
        """
        If a DN is banned, submissions from this user must not be accepted
        """
        banned = BannedDN()
        banned.dn = self.get_user_credentials().user_dn
        Session.merge(banned)
        Session.commit()

        self.push_delegation()
        self.app.post(url="/jobs", content_type='application/json', params='[]', status=403)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:13,代码来源:test_banning.py


注:本文中的fts3rest.lib.base.Session.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。