Exemple #1
0
def main(argv=sys.argv):
	if len(argv) != 2:
		usage(argv)
	config_uri = argv[1]
	setup_logging(config_uri)
	settings = get_appsettings(config_uri)
	engine = engine_from_config(settings, 'sqlalchemy.')
	DBSession.configure(bind=engine)
	ModuleManager.prepare()
	Base.metadata.drop_all(engine)
Exemple #2
0
def module_list(args):
	"""
	List available/installed modules
	"""
	cfg = setup_app(args.ini_file, args.application)
	loc = get_loc(cfg)
	has_core = True
	flt = args.filter
	try:
		from netprofile_core.models import NPModule
	except ImportError:
		has_core = False

	tr_name = loc.translate(_('Name'))
	tr_avail = loc.translate(_('Available'))
	tr_inst = loc.translate(_('Installed'))
	tr_enab = loc.translate(_('Enabled'))
	mm = ModuleManager(cfg)
	tbl = PrettyTable((
		tr_name,
		tr_avail,
		tr_inst,
		tr_enab
	))
	tbl.align = 'l'
	tbl.align[tr_enab] = 'c'
	tbl.sortby = tr_name
	tbl.padding_width = 2

	installed = {}
	if has_core:
		sess = get_session()
		try:
			for mod in sess.query(NPModule):
				installed[mod.name] = (mod.current_version, mod.enabled)
		except ProgrammingError:
			has_core = False

	for moddef, data in mm.prepare().items():
		curversion = _('- N/A -')
		enabled = _('- N/A -')
		if moddef in installed:
			if installed[moddef][1] and (flt == 'disabled'):
				continue
			if (not installed[moddef][1]) and (flt == 'enabled'):
				continue
			curversion = installed[moddef][0]
			enabled = _('YES') if installed[moddef][1] else _('NO')
		elif flt in ('installed', 'enabled', 'disabled'):
			continue
		tbl.add_row((
			moddef,
			data[1],
			loc.translate(curversion),
			loc.translate(enabled)
		))

	return tbl