Ejemplo n.º 1
0
 def read_multiple(self, reg_names):
     """
     Read multiple register of Outback
     :param name:
     :return:
     """
     fields = []
     blocks = []
     for name in reg_names:
         reg = self.get_register(name)
         if reg is not None:
             fields.append(reg.field)
             blocks.append(reg.block)
         else:
             logger.error(name + " not present")
     return register.read_multiple_reg(self.ip, fields, blocks)
Ejemplo n.º 2
0
 def get_chain(self, start='', count=NUM_BLOCKS_PER_REQUEST):
     "return 'count' blocks starting from head or start"
     logger.debug("get_chain: start:%s count%d", start.encode('hex'), count)
     blocks = []
     block = self.head
     if start:
         if start not in self:
             return []
         block = self.get(start)
         if not self.in_main_branch(block):
             return []
     for i in range(count):
         blocks.append(block)
         if block.is_genesis():
             break
         block = block.get_parent()
     return blocks
Ejemplo n.º 3
0
 def get_chain(self, start='', count=NUM_BLOCKS_PER_REQUEST):
     "return 'count' blocks starting from head or start"
     logger.debug("get_chain: start:%s count%d", start.encode('hex'), count)
     blocks = []
     block = self.head
     if start:
         if start in self.index.db:
             return []
         block = self.get(start)
         if not self.in_main_branch(block):
             return []
     for i in range(count):
         blocks.append(block)
         if block.is_genesis():
             break
         block = block.get_parent()
     return blocks
Ejemplo n.º 4
0
def parse_task(task_name,dep_str,lines,pipeline_file,lineno):
	"""
	Parse the task.

	lineno is the line number where the task definition starts - on which the
	task_name and dependencies string appears.

	Raise exception if the task was invalid otherwise, 
	return (next_lineno,Task)
	"""
	indention_pattern = re.compile('^(\s+)[^\s]')
	live_deps_string = re.compile('^([^#]*)')
	valid_dep_string = re.compile('^%s(\.%s)?$' % (VAR_PATTERN,VAR_PATTERN))
	var_assignment_pattern = re.compile('^(%s)\s*=(.*)$' % VAR_PATTERN)
	delete_var_pattern = re.compile('^unset\s+(%s)$' % VAR_PATTERN)
	code_pattern = None #re.compile('^\tcode\.(\w+):(.*)$')
	export_pattern = None #re.compile('^\texport:(.*)$')

	start_lineno = lineno

	####
	# parse the dependency list

	# drop any comment end part
	m = live_deps_string.match(dep_str)
	dep_str = m.group(1)

	# extract the dependencies
	dependencies = dep_str.split()
	
	for dep in dependencies:
		if valid_dep_string.match(dep) is None:
			raise ParseException(pipeline_file,lineno,'expected a dependency, got: %s' % dep)

	lineno += 1

	# now parse blocks
	blocks = []
	in_task = True	
	in_comment_block = False

	im = find_indentation_match(lines,lineno,indention_pattern) 
	logger.debug('match = %s' % im)
	indent_seq = None
	if im is not None:
		# there's valid content
		indent_seq = im.group(1)
		logger.debug('indent_seq len = %d' % len(indent_seq))
		code_pattern = re.compile('^%scode\.(\w+):(.*)$' % indent_seq)
		export_pattern = re.compile('^%sexport:(.*)$' % indent_seq)
	else:
		in_task = False

	while lineno < len(lines) and in_task:
		cur_line = lines[lineno].rstrip()

		if in_comment_block:
			if not cur_line.startswith(indent_seq):
				raise ParseException(pipeline_file,lineno,'all lines in a comment block must be indented')
			lineno += 1
			if cur_line.rstrip() == ('%s###' % indent_seq):
				in_comment_block = False
			continue

		mc = code_pattern.match(cur_line)
		me = export_pattern.match(cur_line)

		if cur_line.startswith('%s###' % indent_seq):
			# we're starting a multi-line comment block
			in_comment_block = True
			lineno += 1
		if cur_line.startswith('%s#' % indent_seq) or len(cur_line.strip()) == 0:
			lineno += 1
		elif mc:
			lang = mc.group(1)
			arg_str = mc.group(2)
			logger.debug('found code block at line %d' % lineno)
			block_lineno = lineno
			lineno,content,content_linenos = read_block_content(lines,lineno+1,indent_seq)

			blocks.append(CodeBlock(lang,arg_str,content,pipeline_file,block_lineno))
		elif me:
			arg_str = me.group(1).strip()
			logger.debug('found export block at line %d' % lineno)
			export_lineno = lineno

			if len(arg_str) > 0:
				raise ParseException(pipeline_file,lineno,
					'export block does not accept an argument string')

			new_lineno,content,content_linenos = read_block_content(lines,lineno+1,indent_seq)
			
			# parse the content as variable assignments
			statements = []
			for ln,line in zip(content_linenos,content):
				line = line.rstrip()
				ma = var_assignment_pattern.match(line)
				md = delete_var_pattern.match(line)
				if ma:
					statements.append(VariableAssignment(ma.group(1),ma.group(2),
														pipeline_file,ln))
				elif md:
					statements.append(DeleteVariable(ma.group(1),pipeline_file,ln))
				elif len(line) == 0:
					pass
				else:
					raise ParseException(pipeline_file,ln,
							'expected a variable assignment, got: %s' % line)

			blocks.append(ExportBlock(statements,pipeline_file,export_lineno))
			lineno = new_lineno
		else:
			in_task = False	

	return lineno,Task(task_name,dependencies,blocks,pipeline_file,start_lineno)
Ejemplo n.º 5
0
def parse_task(task_name,dep_str,lines,pipeline_file,lineno):
	"""
	Parse the task.

	lineno is the line number where the task definition starts - on which the
	task_name and dependencies string appears.

	Raise exception if the task was invalid otherwise, 
	return (next_lineno,Task)
	"""
	indention_pattern = re.compile('^(\s+)[^\s]')
	live_deps_string = re.compile('^([^#]*)')
	valid_dep_string = re.compile('^%s(\.%s)?$' % (VAR_PATTERN,VAR_PATTERN))
	var_assignment_pattern = re.compile('^(%s)\s*=(.*)$' % VAR_PATTERN)
	delete_var_pattern = re.compile('^unset\s+(%s)$' % VAR_PATTERN)
	code_pattern = None #re.compile('^\tcode\.(\w+):(.*)$')
	export_pattern = None #re.compile('^\texport:(.*)$')

	start_lineno = lineno

	####
	# parse the dependency list

	# drop any comment end part
	m = live_deps_string.match(dep_str)
	dep_str = m.group(1)

	# extract the dependencies
	dependencies = dep_str.split()
	
	for dep in dependencies:
		if valid_dep_string.match(dep) is None:
			raise ParseException(pipeline_file,lineno,'expected a dependency, got: %s' % dep)

	lineno += 1

	# now parse blocks
	blocks = []
	in_task = True	
	in_comment_block = False

	im = find_indentation_match(lines,lineno,indention_pattern) 
	logger.debug('match = %s' % im)
	indent_seq = None
	if im is not None:
		# there's valid content
		indent_seq = im.group(1)
		logger.debug('indent_seq len = %d' % len(indent_seq))
		code_pattern = re.compile('^%scode\.(\w+):(.*)$' % indent_seq)
		export_pattern = re.compile('^%sexport:(.*)$' % indent_seq)
	else:
		in_task = False

	while lineno < len(lines) and in_task:
		cur_line = lines[lineno].rstrip()

		if in_comment_block:
			if not cur_line.startswith(indent_seq):
				raise ParseException(pipeline_file,lineno,'all lines in a comment block must be indented')
			lineno += 1
			if cur_line.rstrip() == ('%s###' % indent_seq):
				in_comment_block = False
			continue

		mc = code_pattern.match(cur_line)
		me = export_pattern.match(cur_line)

		if cur_line.startswith('%s###' % indent_seq):
			# we're starting a multi-line comment block
			in_comment_block = True
			lineno += 1
		if cur_line.startswith('%s#' % indent_seq) or len(cur_line.strip()) == 0:
			lineno += 1
		elif mc:
			lang = mc.group(1)
			arg_str = mc.group(2)
			logger.debug('found code block at line %d' % lineno)
			block_lineno = lineno
			lineno,content,content_linenos = read_block_content(lines,lineno+1,indent_seq)

			blocks.append(CodeBlock(lang,arg_str,content,pipeline_file,block_lineno))
		elif me:
			arg_str = me.group(1).strip()
			logger.debug('found export block at line %d' % lineno)
			export_lineno = lineno

			if len(arg_str) > 0:
				raise ParseException(pipeline_file,lineno,
					'export block does not accept an argument string')

			new_lineno,content,content_linenos = read_block_content(lines,lineno+1,indent_seq)
			
			# parse the content as variable assignments
			statements = []
			for ln,line in zip(content_linenos,content):
				line = line.rstrip()
				ma = var_assignment_pattern.match(line)
				md = delete_var_pattern.match(line)
				if ma:
					statements.append(VariableAssignment(ma.group(1),ma.group(2),
														pipeline_file,ln))
				elif md:
					statements.append(DeleteVariable(ma.group(1),pipeline_file,ln))
				elif len(line) == 0:
					pass
				else:
					raise ParseException(pipeline_file,ln,
							'expected a variable assignment, got: %s' % line)

			blocks.append(ExportBlock(statements,pipeline_file,export_lineno))
			lineno = new_lineno
		else:
			in_task = False	

	return lineno,Task(task_name,dependencies,blocks,pipeline_file,start_lineno)