def read_file(file_path): Logger.d("Reading file: {0}".format(file_path)) with open(file_path, "r") as f: content = f.read() f.close() return content
def run_all_generators(options, model): package = pyginny.generators prefix = package.__name__ + "." for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix): Logger.d("Found submodule {0} (is a package: {1})".format(modname, ispkg)) module = __import__(modname + ".generator", fromlist=["dummy"]) Logger.d("Imported {0}".format(module)) obj = module.Generator(options=options, model=model) obj.run()
def write_to_file(dir_path, filename, content): Logger.d("Creating file {0} in directory {1} with {2} bytes...".format( filename, dir_path, len(content))) full_file_path = os.path.join(dir_path, filename) FileUtil.remove_file(full_file_path) FileUtil.create_dir(dir_path) with open(full_file_path, "w") as f: f.write(content) f.close() Logger.d("Created file {0} in directory {1}".format( filename, dir_path))
def get_all_generators_options(): package = pyginny.generators prefix = package.__name__ + "." result = "" for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix): Logger.d("Found submodule {0} (is a package: {1})".format(modname, ispkg)) module = __import__(modname + ".generator", fromlist=["dummy"]) Logger.d("Imported {0}".format(module)) obj = module.Generator(options=[], model=None) result = result + obj.get_usage_options() return result
def remove_file(filename): Logger.d("Remove file: {0}".format(filename)) if os.path.isfile(filename): os.remove(filename)
def remove_dir(dir_path): Logger.d("Remove dir: {0}".format(dir_path)) if os.path.isdir(dir_path): shutil.rmtree(dir_path)
def create_dir(dir_path): Logger.d("Create a new dir: {0}".format(dir_path)) if not os.path.isdir(dir_path): os.makedirs(dir_path)
def test_debug_with_debug_turned_off(self): Constants.DEBUG = False Logger.d("test_debug_with_debug_turned_off") self.assertTrue(True)
def test_debug_with_debug_turned_on(self): Constants.DEBUG = True Logger.d("test_debug_with_debug_turned_on") self.assertTrue(True)