當前位置: 首頁>>代碼示例>>Python>>正文


Python Source.invalidate方法代碼示例

本文整理匯總了Python中source.Source.invalidate方法的典型用法代碼示例。如果您正苦於以下問題:Python Source.invalidate方法的具體用法?Python Source.invalidate怎麽用?Python Source.invalidate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在source.Source的用法示例。


在下文中一共展示了Source.invalidate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Derivative

# 需要導入模塊: from source import Source [as 別名]
# 或者: from source.Source import invalidate [as 別名]
class Derivative(Asset):
	def __init__(self, inflate=None, _id=None, submission=None):
		
		super(Derivative, self).__init__(
			inflate=inflate,
			_id=_id,
			db="derivatives",
			extra_omits=['submission','source','j3m']
		)
		
		if not hasattr(self, 'submission_id'):
			self.invalidate(
				invalidate['codes']['submission_undefined'],
				invalidate['reasons']['submission_undefined']
			)
			return
		
		from submission import Submission
		if submission is None:
			self.submission = Submission(_id=self.submission_id)
		else:
			self.submission = submission
			
		j3m = open(
			os.path.join(self.submission.asset_path, self.submission.j3m), 'r'
		).read()
		
		try:
			self.j3m = json.loads(j3m)
		except:
			self.submission.invalidate(
				invalidate['codes']['submission_invalid_j3m'],
				invalidate['reasons']['submission_invalid_j3m']
			)
			
			self.invalidate(
				invalidate['codes']['submission_invalid_j3m'],
				invalidate['reasons']['submission_invalid_j3m']
			)
			return
		
		self.getSource()
			
		if _id is None:
			setattr(self, 'date_created', self.j3m['genealogy']['dateCreated'])
			setattr(self, 'mime_type', self.submission.mime_type)
			self.save()
			
			self.parseLocationEntries()
			self.parseAnnotationEntries()
			
	def getSource(self):
		from source import Source
		if hasattr(self, 'source_id'):
			self.source = Source(_id=self.source_id)
		else:
			fingerprint = None
			try:
				fingerprint = self.j3m['intent']['pgpKeyFingerprint'].lower()
			except KeyError as e:
				print "NO FINGERPRINT???"
				self.source = Source(inflate={
					'invalid': {
						'error_code' : invalidate['codes']['source_missing_pgp_key'],
						'reason' : invalidate['reasons']['source_missing_pgp_key']
					}
				})
				
			if fingerprint is not None:
				source = self.submission.db.query(
					'_design/sources/_view/getSourceByFingerprint', 
					params={
						'fingerprint' : fingerprint
					}
				)[0]
			
				if source:
					self.source = Source(_id=source['_id'])
				else:
					# we didn't have the pgp key.  
					# so init a new source and set an invalid flag about that.
				
					inflate = {
						'fingerprint' : fingerprint
					}
				
					## TODO: ACTUALLY THIS IS CASE-SENSITIVE!  MUST BE UPPERCASE!
					self.source = Source(inflate=inflate)
					self.source.invalidate(
						invalidate['codes']['source_missing_pgp_key'],
						invalidate['reasons']['source_missing_pgp_key']
					)
			
			
			setattr(self, 'source_id', self.source._id)
			self.save()
		
		if hasattr(self, 'source_id'):
			return True
		else:
#.........這裏部分代碼省略.........
開發者ID:harlo,項目名稱:InformaCam-Service,代碼行數:103,代碼來源:derivative.py


注:本文中的source.Source.invalidate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。