コード例 #1
0
ファイル: core.py プロジェクト: vdorr/bloced
def get_workbench_dependencies(fname) :
	"""
	return set of block types immediately needed by workbench file fname
	these block types may have other dependencies
	"""
	try :
		with open(fname, "rb") as f :
			version, meta, resources = serializer.unpickle_workbench_data(f)
	except Exception as e :
		print(here(), "error loading workbench file", fname, e)
		return None

	used_types = set()
#XXX type_names must be unique -> need to extend them with library path, including c modules
	for r_type, r_version, r_name, resrc in resources :
		if (r_type == serializer.RES_TYPE_SHEET and
				r_version == serializer.RES_TYPE_SHEET_VERSION and
				is_macro_name(r_name) ) :
			types, struct, meta = resrc
			for nr, block_type in types :
				lib_name, type_name = split_full_type_name(block_type)
				if lib_name :
					used_types.update((block_type,))

	return used_types
コード例 #2
0
ファイル: core.py プロジェクト: vdorr/bloced
def load_library_sheet(library, full_name, sheet_name, w_data=None) :
	"""
	search library for item full_name and return sheet with sheet_name from this context
	raises Exception if there is problem, returns None if just not found
	"""
	lib_data = library.get_block_and_lib(full_name)

	if lib_data is None :
		raise Exception("library item '" + full_name + "' not found")

	lib, (item, proto) = lib_data

	if w_data is None :
		with open(item.file_path, "rb") as f :
			w_data = serializer.unpickle_workbench_data(f)

	res_found = tuple(serializer.get_resource(w_data, serializer.RES_TYPE_SHEET, None, sheet_name))

	if res_found is None :
		raise Exception("can not load library item '" + full_name + "'")

	sheet_data, = res_found
	sheet = serializer.restore_dfs_model(*(sheet_data + (library,)))

	return sheet
コード例 #3
0
ファイル: core.py プロジェクト: vdorr/bloced
def load_workbench_library(lib_name, file_path, library=None, w_data=None) :
	"""
	lib_name - full library name, example 'logic.flipflops'
	"""
	if file_path is None :
		data = w_data
	else :
		with open(file_path, "rb") as f :
			data = serializer.unpickle_workbench_data(f)
	w = dfs.Workbench(
#		lib_dir=os.path.join(os.getcwd(), "library"),
		blockfactory=library,
		passive=True,
		do_create_block_factory=False)
	serializer.restore_workbench(data, w, library=library)
	return load_blocks_from_workbench(w, lib_name)