Ejemplo n.º 1
0
	def backupFile(cls, fileP, suffix = ".bak", copy = True):
		'''
		Creates a backup of the chosen file in the same directory as the file itself.
		If the file does not exist or isn't accessible then a BackupException will be raised.
		If a backup file already exists for the file and it wasn't created in this run then a BackupException will be raised.
		Remember to call restoreFiles to rollback the changes at cleanup.
		@param fileP: The absolute path to the file that is to be backed up.
		@param suffix: The suffix used for marking the backup file.
		@param copy: if True then the file will be copied and otherwise it will be moved.
		'''
		if fileP not in cls.files:
			if not os.path.isfile(fileP):
				raise BackupSourceException("File '%s' does not exist or is not accessible." % fileP)
			backup = "%s%s" % (fileP, suffix)
			if os.path.isfile(backup) and cls.ignore is False:
				raise BackupExistsException("Backup file '%s' already exists." % backup)
			if copy:
				shutil.copy2(fileP, backup)
				logging.debug("Backed up '%s' (Copy)" % fileP)
			else:
				shutil.move(fileP, backup)
				logging.debug("Backed up '%s' (Move)" % fileP)
			cls.files.add(fileP)
			return True
		else:
			logging.info("File '%s' already backed up in this session. Skipping." % fileP)
			return False
Ejemplo n.º 2
0
	def restoreFile(cls, fileP, suffix = ".bak"):
		'''
		Restores a backup of the chosen file.
		@param fileP: The absolute path to the file that was backed up (without the backup suffix).
		@param suffix: The suffix used for marking the backup file.
		'''
		backup = "%s%s" % (fileP, suffix)
		if os.path.isfile(backup):
			shutil.move(backup, fileP)
			logging.debug("Restored '%s' from backup" % fileP)
Ejemplo n.º 3
0
	def __init__(self, jobId = 1):
		'''
		Gathers all information about job from "hc j d".
		@param jobId: The id of the job about which the details will be gathered.
		'''
		self.jobId = jobId
		lines = Console.call("hc j d %s" % self.jobId)[1].split('\n')
		for line in lines:
			if re.search(r'^\s', line) is None:
				continue
			elif re.search(r'task_count', line) is None:
				ret = re.search(r'\s*(\S+)\s*(\S.*)', line) #\s*([A-Z]+)
				if ret is None:
					logging.warning("job details fail: %s" % line)
					continue
				logging.debug("job details: %s = %s" % (ret.group(1), ret.group(2)))
				self.properties[ret.group(1)] = '%s' % ret.group(2)
			else:
				ret = re.search(r'\s*task_count_(\S+)\s*(\d+)\/(\d+)', line)
				if ret is None:
					logging.error("job details fail: %s" % line)
					continue
				logging.debug("job details: task_count_%s = %s/%s" % (ret.group(1), ret.group(2), ret.group(3)))
				self.properties[ret.group(1)] = (ret.group(2), ret.group(3))