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


Python GPG.make_args方法代码示例

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


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

示例1: WebofTrustVisualization

# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import make_args [as 别名]
class WebofTrustVisualization():
	def __init__(self, folder, pubkey=None):
		self.folder = folder
		self.gpg2_dir = os.path.join(folder, "gnupg")
		if not os.path.exists(self.folder):
			os.mkdir(self.folder)
		if os.path.exists(os.path.join(self.gpg2_dir, "pubring.gpg")) and not pubkey:
			print ("Continuing...")
			self.getNumber()
			self.gpg2 = GPG(gpgbinary="gpg2", gnupghome=self.gpg2_dir)
		elif not os.path.exists(self.gpg2_dir) and pubkey:
			print ("Initializing with key {}...".format(pubkey))
			os.mkdir(self.gpg2_dir, mode=0o700)
			self.gpg2 = GPG(gpgbinary="gpg2", gnupghome=self.gpg2_dir)
			self.recv_keys(pubkey)
			self.number = 0
			self.saveNumber()
		else:
			raise InvalidArgumentException

	def recv_keys(self, *pubkeys):
		self.gpg2.recv_keys("pgp.mit.edu", *pubkeys)

	def gendot(self):
		with open(os.path.join(self.folder, "{}.dot".format(self.number)), "w") as dot:
			with Popen(self.gpg2.make_args(["--list-sigs"], False), stdout=PIPE) as gpg2:
				Popen(["sig2dot", "-a"], stdin=gpg2.stdout, stdout=dot).wait()

	def draw(self, format="ps"):
		with open("{}.{}".format(os.path.join(self.folder, str(self.number)), format), "w") as drawing:
			Popen(["dot", "-T{}".format(format), "{}.dot".format(os.path.join(self.folder, str(self.number)))], stdout=drawing).wait()

	def nextRound(self):
		sigs_missing = []
		print ("gpg2")
		with Popen(self.gpg2.make_args(["--list-sigs"], False), stdout=PIPE, env={"LANG": "C.UTF-8"}) as gpg2:
			for sig in gpg2.stdout.read().splitlines():
				if b"[User ID not found]" in sig:
					for elem in sig.split():
						if len(elem) == 8:
							if elem.decode() not in sigs_missing: #we need each key only once
								sigs_missing.append(elem.decode())
		self.number += 1 #better safe than sorry
		self.saveNumber()
		self.recv_keys(*sigs_missing)

	def getNumber(self):
		with open(os.path.join(self.folder, "number"), "r") as number:
			self.number = int(number.read().strip())

	def saveNumber(self):
		with open(os.path.join(self.folder, "number"), "w") as number:
			number.write(str(self.number))
开发者ID:YtvwlD,项目名称:visualwot,代码行数:55,代码来源:generate.py


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