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


Python Helper.listAdd方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import listAdd [as 別名]
class Config:

	data = {}
	helper = False
	withDependencies = False

	def __init__(self, arg):
		self.withDependencies = arg
		self.helper = Helper()

	def getConf(self):
		return self.data

	# =================== Checking ====================== #

	def createQueue(self, conf):
		queue = []
		try:
			for key, vals in conf.iteritems():
				if (type(vals) is list):
					for val in vals:
						self.checkDependencies(key, val, conf, queue)
				elif (type(vals) is dict):
					for name, params in vals.iteritems():
						self.checkDependencies(key, name, conf, queue, params)
				else:
					self.checkDependencies(key, vals, conf, queue)

			return self.sortQueue(queue)
		except:
			print sys.exc_info()

	def checkDependencies(self, folder, className, conf, queue, params=False):
		curClass = self.helper.getClass(folder + '.' + self.helper.ucfirst(className))()
		if hasattr(curClass, 'dependencies') and self.withDependencies == '1':
			for val in curClass.dependencies:
				curVal = val.split('.')
				if curVal[0] in conf:
					if curVal[1] == conf[curVal[0]] or (hasattr(conf[curVal[0]], 'keys') and curVal[1] in conf[curVal[0]].keys()):
						continue

				self.checkDependencies(curVal[0], curVal[1], conf, queue)

		if params:
			curClass.attrs = {}
			for key, val in params.iteritems():
				curClass.attrs[key] = val
		self.helper.listAdd(curClass, queue)

	def sortQueue(self, queue):
		newQueue = []
		for val in queue:
			if hasattr(val, 'sortOrder'):
				for sortEl in val.sortOrder:
					self.helper.listFindAndAdd(sortEl, queue, newQueue)
			if hasattr(val, 'dependencies'):
				for sortEl in val.dependencies:
					self.helper.listFindAndAdd(sortEl, queue, newQueue)
		self.helper.listMerge(queue, newQueue)
		return newQueue

	# =================== Creation ====================== #

	def createConf(self):
		self.data['dist'] = self.setDist()
		self.data['language'] = self.setLang()
		self.data['server'] = self.setServer()
		# self.data['db'] = self.setDb()
		return self.getConf()

	def choice(self, arr, question, isRequired=False):
		string = '===== '+question+' =====\n'
		num = 0
		for key, val in arr.iteritems():
			string += str(num)+'. '+key+'\n'
			num += 1;

		if (isRequired is False): string += str(num)+'. Nothing\n'
		curChoice = raw_input(string+'Your choice? ')
		if (curChoice == str(num) and isRequired is False): print ''

		try:
			return arr.keys()[int(curChoice)]
		except:
			print 'not correct number'
			func = inspect.getouterframes(inspect.currentframe())[1][3]
			getattr(self, func)()

	def setDist(self):
		grep = self.helper.execute("cat /etc/lsb-release")
		dist = grep.split('\n')[0].split('=')[1].lower()
		if (dist in self.dist): 
			return self.dist[dist]
		else:
			dist = raw_input('type your linux distribution name? ').lower()
			if (dist in self.dist): 
				return dist
			else:
				sys.exit('Sorry, this distribution does not supported:(')

#.........這裏部分代碼省略.........
開發者ID:Sephirothus,項目名稱:unfolding,代碼行數:103,代碼來源:Config.py


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