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


Python FileDict.load方法代码示例

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


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

示例1: fromDir

# 需要导入模块: from FileDict import FileDict [as 别名]
# 或者: from FileDict.FileDict import load [as 别名]
class Job:

	@staticmethod
	def fromDir(jobDir, interactive=False, quiet=False):
		if not os.path.isdir(jobDir):
			raise Exception('you must give a directory: ' + jobDir)
		home, name = os.path.split(jobDir)
		return Job(home, name, interactive, newjob=False, quiet=quiet)
	
	@staticmethod
	def jobsRunning():
		jobs = set()
		lines = subprocess.check_output('qstat').strip()
		if len(lines) == 0:
			return jobs
		ar = lines.split('\n')
		assert len(ar) >= 3	# first two lines are formatting
		for jstr in ar[2:]:
			jobs.add(int(jstr.split()[0]))
		return jobs

	@staticmethod
	def killEverything():
		for jid in Job.jobsRunning():
			os.system('qdel '+jid)

	def __init__(self, homeDir, name, f_hasFailed, interactive=False, newjob=True, quiet=False):
		"""
			homeDir is where experiments are stored
			name is the name of this experiment
				if there is another job with the same name, they are assumed
				to be the same. delete old jobs that you do not want to be confused with
			f_hasFailed is a function that takes a log file and returns a boolean for
				whether or not the job has failed
			if in interactive mode, will prompt user for input
				this should not be used for scripts, which would hang forever in these cases
		"""
		self.name = name
		self.home = os.path.join(homeDir, name)
		self.logDir = os.path.join(self.home, 'log')
		self.f_hasFailed = f_hasFailed

		if os.path.isfile(self.home):
			raise Exception('you the home directory you gave must not have any files or folders that match the name you gave')

		if newjob:
			print 'creating new job:', self.home
			if os.path.isdir(self.home):
				if interactive:
					print "the directory %s already exists" % (self.home)
					r = raw_input('would you like me to delete it for you? [y|n] ')
					if str2bool(r):
						os.system('rm -r ' + self.home)
						os.system('mkdir ' + self.home)
					else:
						raise Exception('cannot proceed')
				else:
					raise Exception('please give a unique name or delete old jobs: ' + self.home)
			elif 0 != os.system('mkdir -p ' + self.home):
				raise Exception('cannot make home directory!')

			if not os.path.isdir(self.logDir) and 0 != os.system('mkdir -p ' + self.logDir):
				raise Exception('cannot make log directory!')
		else:
			assert os.path.isdir(self.home)
			assert os.path.isdir(self.logDir)
			if not quiet: print 'loading existing job:', self.home

		self.javaOpt = FileDict(os.path.join(self.home, 'java.settings'), exists=not newjob)	# start with "-D"
		self.metaOpt = FileDict(os.path.join(self.home, 'meta.settings'), exists=not newjob)	# xmx, jar, profile, etc
		self.qsubOpt = FileDict(os.path.join(self.home, 'qsub.settings'), exists=not newjob)	# mem_free, h_rt

		self.prepared = False
	
	def getResourceDirectory(self, parentFolderName, childFolderName, overwrite=True):
		'''see getResourceFile for details'''
		folder = os.path.join(self.home, parentFolderName, childFolderName)
		if os.path.isdir(folder):
			if not overwrite: raise
		else:
			os.system('mkdir -p ' + folder)
		return folder

	def getResourceFile(self, folderName, fileName, overwrite=True):
		'''
			example usage: folderName='diagnostics', fileName='parameters.txt',
			this just returns a path to home/diagnostics/parameters.txt
			resources are usefule for job-specific output (avoid job output collision)
		'''
		folder = os.path.join(self.home, folderName)
		if not os.path.isdir(folder):
			os.system('mkdir ' + folder)
		f = os.path.join(folder, fileName)
		if not overwrite and os.path.isfile(f):
			raise Exception('this file already exists! ' + f)
		return f

	def addLib(self, dirOrFile):
		if os.path.isfile(dirOrFile):
			cp = selt.class_path() + ':' + dirOrFile
#.........这里部分代码省略.........
开发者ID:twolfe18,项目名称:twpt,代码行数:103,代码来源:tsub.py


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