def write_file(paths, template, file, comment, force=False):
	(path, filename)  = os.path.split(file)
	ivwpy.util.mkdir(path)

	if os.path.exists(file) and not force:
		cp.print_error("... File exists: " + file + ", use --force or overwrite")
		return
	elif os.path.exists(file) and force:
		cp.print_warn("... Overwriting existing file")
	
	with open(file, "w") as f:	
		print(comment + f.name)
		f.write(make_template(template, paths.class_name, paths.module_define,  paths.api_def, paths.include_define))
Example #2
0
def write_file(paths, template, file, comment, author, force=False):
	(path, filename)  = os.path.split(file)
	ivwpy.util.mkdir(path)

	if os.path.exists(file) and not force:
		cp.print_error("... File exists: " + file + ", use --force or overwrite")
		return
	elif os.path.exists(file) and force:
		cp.print_warn("... Overwriting existing file")
	
	with open(file, "w") as f:	
		print(comment + f.name)
		f.write(make_template(template, paths.class_name, paths.module_define,  paths.api_def, paths.include_define, author))
						help="Don't add source file")
	parser.add_argument("-f", "--frag", action="store_true", dest="frag", 
						help="Add fragment shader file")
	parser.add_argument("-v", "--vert", action="store_true", dest="vert", 
						help="Add vertex shader file")
	parser.add_argument("-g", "--geom", action="store_true", dest="geom", 
						help="Add geometry shader file")

	parser.add_argument("-d", "--dummy", action="store_true", dest="dummy", 
						help="Write local testfiles instead")
	parser.add_argument("--force", action="store_true", dest="force", 
						help="Overwrite exsting files")

	args = parser.parse_args()

	cp.print_warn("Adding files to inwivo")
	ivwpath = ivwpy.ivwpaths.find_inv_path() if args.ivwpath == None else args.ivwpath

	if not ivwpy.ivwpaths.test_for_inviwo(ivwpath):
		cp.print_error("Error could not find the inviwo repository, use --inviwo to specify where the inviwo repository is.")
		sys.exit(1)

	templates = os.sep.join([ivwpath, 'tools', 'templates'])
		
	for name in args.names:
		paths = ivwpy.ivwpaths.IvwPaths(name)
		paths.info()
			
		cmakefile = ivwpy.cmake.CMakefile(paths.cmake_file)
			
		if not args.header:
Example #4
0
def make_module(ivwpath, path, name, verbose, dummy, templatesFolder, author,
                bNoEmptyDirs):
    if os.path.exists(os.sep.join([path, name])):
        cp.print_error("Error module: " + name + ", already exits")
        return

    cp.print_warn("Create module: " + name)
    uname = name.upper()
    lname = name.lower()

    dirs = [{
        "path": ["data"],
        "desc": "Folder for non code stuff"
    }, {
        "path": ["data", "images"],
        "desc": "Image resources"
    }, {
        "path": ["data", "volumes"],
        "desc": "Volume resources "
    }, {
        "path": ["data", "workspaces"],
        "desc": "Workspaces, listed in File::Examples::ExampleModule"
    }, {
        "path": ["docs"],
        "desc": "Put documentation here"
    }, {
        "path": ["docs", "images"],
        "desc": "Put images that should show up in doxygen here"
    }, {
        "path": ["processors"],
        "desc": "Put processors here"
    }, {
        "path": ["properties"],
        "desc": "Put properties here"
    }, {
        "path": ["tests"],
        "desc": "Test related things"
    }, {
        "path": ["tests", "unittests"],
        "desc": "Put unittests here"
    }, {
        "path": ["tests", "regression"],
        "desc":
        "Regression Test workspaces, listed in File::Test::ExampleModule." +
        " Automatically run in regression tests on Jenkins"
    }]

    if (bNoEmptyDirs): dirs = []

    templates = [{
        "file": "CMakeLists.txt",
        "prefix": "",
        "desc": "CMake project definition"
    }, {
        "file":
        "depends.cmake",
        "prefix":
        "",
        "desc":
        "List of dependencies to other modules / cmake packages"
    }, {
        "file": "module.cpp",
        "prefix": lname,
        "desc": "For module registration"
    }, {
        "file": "module.h",
        "prefix": lname,
        "desc": "For module registration"
    }, {
        "file": "moduledefine.h",
        "prefix": lname,
        "desc": "declspec defines"
    }, {
        "file": "readme.md",
        "prefix": "",
        "desc": "Description of the module, used by CMake"
    }]

    module_dir = os.sep.join([path, lname])

    print("... Create module dir: " + module_dir)
    if not dummy: os.mkdir(module_dir)
    for dir in dirs:
        print("... Create dir:  {0:.<30} {desc:<100}".format(
            os.sep.join([lname] + dir["path"]) + " ", **dir))
        if not dummy: os.mkdir(os.sep.join([module_dir] + dir["path"]))

    for template in templates:
        try:
            if verbose:
                print("")
                print("FILE: " + os.sep.join(
                    [module_dir, template["prefix"] + template["file"]]))
                print("#" * 60)

            newfilename = os.sep.join(
                [module_dir, template["prefix"] + template["file"]])
            templatefilename = os.sep.join([templatesFolder, template["file"]])
            comment = "... Create file: {0:.<30} {desc:<100}".format(
                os.sep.join([lname, template["prefix"] + template["file"]]) +
                " ", **template)
            ivwpy.util.writeTemplateFile(newfilename, templatefilename,
                                         comment, name, "<define>", "<api>",
                                         "<incfile>", author, True, verbose)

        except FileNotFoundError as err:
            cp.print_error(err)
            return

    print("... Done")
Example #5
0
        ivwpath = args.ivwpath

    if not ivwpy.ivwpaths.test_for_inviwo(ivwpath):
        cp.print_error("Error could not find the inviwo repository")
        parser.print_help()
        sys.exit(1)

    print("Path to inviwo: " + ivwpath)

    #Get the folder with the templates
    if args.templatesdir == "":
        templatesFolder = os.sep.join([ivwpath, 'tools', 'templates'])
    else:
        templatesFolder = args.templatesdir

    #Create module(s)
    for pathname in args.modules:
        path, name = os.path.split(pathname)
        if path == "": path = "."
        make_module(ivwpath, path, name, args.verbose, args.dummy,
                    templatesFolder, args.author, args.bNoEmptyDirs)

    #Run CMake, if desired
    if args.builddir != None:
        ivwpy.cmake.runCMake(str(args.builddir[0]),
                             ["-DIVW_MODULE_" + name.upper() + "=1"])
    else:
        cp.print_warn("Don't forget to rerun CMake with -DIVW_MODULE_" +
                      name.upper() + " to add the module")

    cp.print_warn("Done")
def make_module(ivwpath, path, name, verbose, dummy):
	if os.path.exists(os.sep.join([path, name])):
		cp.print_error("Error module: "+ name + ", already exits")
		return
	
	cp.print_warn("Create module: " + name)
	uname = name.upper()
	lname = name.lower()
	
	dirs = [
		{
			"path" : ["data"], 
			 "desc" : "Folder for non code stuff"
		}, 
		{
			"path" : ["data", "image"], 
		 	"desc" : "Image resources"
		}, 
		{
			"path" : ["data", "volumes"], 
		 	"desc" : "Volume resources "
		}, 
		{
			"path" : ["data", "workspaces"], 
		 	"desc" : "Workspaces, listed in File::Examples::ExampleModule"
		}, 
		{
			"path" : ["docs"], 
		 	"desc" : "Put documentation here"
		}, 
		{
			"path" : ["docs", "images"], 
		 	"desc" : "Put images that should show up in doxygen here"
		}, 
		{
			"path" : ["processors"], 
		 	"desc" : "Put processors here"
		},
		{
			"path" : ["properties"], 
		 	"desc" : "Put properties here"
		},
		{
			"path" : ["tests"], 
		 	"desc" : "Test related things"
		},
		{
			"path" : ["tests", "unittests"], 
		 	"desc" : "Put unittests here"
		},
		{
			"path" : ["tests", "regression"], 
		 	"desc" : "Regression Test workspaces, listed in File::Test::ExampleModule." 
		 			 + " Automatically run in regression tests on Jenkins"
		}
	]

	templates = [
		{"file" : "CMakeLists.txt" , "prefix" : ""    , "desc" : "CMake project definition"},
		{"file" : "depends.cmake"  , "prefix" : ""    , "desc" : "List of dependencies to other modules / cmake packages"},
		{"file" : "module.cpp"     , "prefix" : lname , "desc" : "For module registration"},
		{"file" : "module.h"       , "prefix" : lname , "desc" : "For module registration"},
		{"file" : "moduledefine.h" , "prefix" : lname , "desc" : "declspec defines"},
		{"file" : "readme.md"      , "prefix" : ""    , "desc" : "Description of the module, used by CMake"}
	]
	
	module_dir = os.sep.join([path, lname])
	
	print("... Create module dir: " + module_dir)
	if not dummy: os.mkdir(module_dir)
	for dir in dirs:
		print("... Create dir:  {0:.<30} {desc:<100}".format(os.sep.join([lname] + dir["path"])+" ", **dir))
		if not dummy: os.mkdir(os.sep.join([module_dir] + dir["path"]))
	
	for template in templates:
		try:
			with open(os.sep.join([ivwpath, 'tools', 'templates', template["file"]]),'r') as f:
				if verbose:
					print("")
					print("FILE: " + os.sep.join([module_dir, template["prefix"] + template["file"]]))
					print("#"*60)
					
				lines = []
				for line in f:
					line = line.replace("<name>", name)
					line = line.replace("<lname>", lname)
					line = line.replace("<uname>", uname)
					lines.append(line)
					if verbose: print(line, end='')
				
				if verbose: print("")
			
				print("... Create file: {0:.<30} {desc:<100}".format(os.sep.join([lname, template["prefix"] + template["file"]])+" ", **template))	
				if not dummy:
					with open(os.sep.join([module_dir, template["prefix"] + template["file"]]),'w') as f:
						for line in lines:
							f.write(line)
						if verbose: print(line)
	
		except FileNotFoundError as err:
			cp.print_error(err)
			return

					
	print("... Done")
	parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", 
		                help="Print extra information")
	parser.add_argument("-i", "--inviwo", type=str, default="", dest="ivwpath", 
		                help="Path to the inviwo repository. Tries to find it in the current path")
	parser.add_argument("-c", "--cmake", type=str, nargs=1, action="store", dest="builddir", 
						help="Rerun CMake in the specified build directory")
	args = parser.parse_args()

	if args.ivwpath == "":
		ivwpath = ivwpy.ivwpaths.find_inv_path()
	else:
		ivwpath = args.ivwpath

	if not ivwpy.ivwpaths.test_for_inviwo(ivwpath):
		cp.print_error("Error could not find the inviwo repository")
		parser.print_help()
		sys.exit(1)
	
	print("Path to inviwo: " + ivwpath)
		
	for pathname in args.modules:
		path, name = os.path.split(pathname)
		if path == "": path = "."
		make_module(ivwpath, path, name, args.verbose, args.dummy)

	if args.builddir != None:
		ivwpy.cmake.runCMake(str(args.builddir[0]), ["-DIVW_MODULE_"+name.upper()+"=1"])
	else: 
		cp.print_warn("Don't forget to rerun CMake with -DIVW_MODULE_"+name.upper()+ " to add the module")

	cp.print_warn("Done")
Example #8
0
                        dest="geom",
                        help="Add geometry shader file")

    parser.add_argument("-d",
                        "--dummy",
                        action="store_true",
                        dest="dummy",
                        help="Write local testfiles instead")
    parser.add_argument("--force",
                        action="store_true",
                        dest="force",
                        help="Overwrite exsting files")

    args = parser.parse_args()

    cp.print_warn("Adding files to inwivo")
    ivwpath = ivwpy.ivwpaths.find_inv_path(
    ) if args.ivwpath == None else args.ivwpath

    if not ivwpy.ivwpaths.test_for_inviwo(ivwpath):
        cp.print_error(
            "Error could not find the inviwo repository, use --inviwo to specify where the inviwo repository is."
        )
        sys.exit(1)

    templates = os.sep.join([ivwpath, 'tools', 'templates'])

    for name in args.names:
        paths = ivwpy.ivwpaths.IvwPaths(name)
        paths.info()