def execute(): parser = argparse.ArgumentParser( description='Get a configuration skeleton for a module') parser.add_argument('--no-comment', '-o', action='store_true', help="Disable comments in the generated configuration") parser.add_argument( 'module', help="Name of the module to get the configuration from") args = parser.parse_args() tools.load_env() if not hf.module.moduleClassLoaded(args.module): print >> sys.stderr, sys.argv[ 0] + ": The module '%s' was not found" % args.module sys.exit(-1) ModuleClass = hf.module.getModuleClass(args.module) print '[INSTANCE_NAME]' print 'module =', args.module print 'name = ' print 'description = ' print 'instruction = ' print 'type = rated' print 'weight = 1.0' if not args.no_comment and len(ModuleClass.config_hint) > 0: print '# ' + ModuleClass.config_hint print '' print '' for key, (descr, default) in ModuleClass.config_keys.iteritems(): if not args.no_comment and len(descr) > 0: print '# ' + '\n# '.join(descr.split('\n')) print key, '=', default print ''
def execute(): parser = argparse.ArgumentParser(description="Get a configuration skeleton for a module") parser.add_argument( "--no-comment", "-o", action="store_true", help="Disable comments in the generated configuration" ) parser.add_argument("module", help="Name of the module to get the configuration from") args = parser.parse_args() tools.load_env() if not hf.module.moduleClassLoaded(args.module): print >> sys.stderr, sys.argv[0] + ": The module '%s' was not found" % args.module sys.exit(-1) ModuleClass = hf.module.getModuleClass(args.module) print "[INSTANCE_NAME]" print "module =", args.module print "name = " print "description = " print "instruction = " print "type = rated" print "weight = 1.0" if not args.no_comment and len(ModuleClass.config_hint) > 0: print "# " + ModuleClass.config_hint print "" print "" for key, (descr, default) in ModuleClass.config_keys.iteritems(): if not args.no_comment and len(descr) > 0: print "# " + "\n# ".join(descr.split("\n")) print key, "=", default print ""
def take_snapshot( cfg, force = True ): """ Take a new snapshot. cfg: config.Config instance force: take the snapshot even if it wouldn't need to or would be prevented (e.g. running on battery) """ tools.load_env(cfg.get_cron_env_file()) ret = snapshots.Snapshots( cfg ).take_snapshot( force ) return ret
def take_snapshot(cfg, force=True): """ Take a new snapshot. cfg: config.Config instance force: take the snapshot even if it wouldn't need to or would be prevented (e.g. running on battery) """ tools.load_env(cfg.get_cron_env_file()) ret = snapshots.Snapshots(cfg).take_snapshot(force) return ret
def test_load_env_do_not_overwrite_previous_values(self): test_env = configfile.ConfigFile() test_env.set_str_value('FOO', 'bar') test_env.set_str_value('ASDF', 'qwertz') test_env.save(self.temp_file) #add some environ vars that should not get overwritten os.environ['FOO'] = 'defaultFOO' os.environ['ASDF'] = 'defaultASDF' tools.load_env(self.temp_file) self.assertIn('FOO', os.environ) self.assertIn('ASDF', os.environ) self.assertEqual(os.environ['FOO'], 'defaultFOO') self.assertEqual(os.environ['ASDF'], 'defaultASDF')
def test_load_env_without_previous_values(self): test_env = configfile.ConfigFile() test_env.set_str_value('FOO', 'bar') test_env.set_str_value('ASDF', 'qwertz') test_env.save(self.temp_file) #make sure environ is clean self.assertNotIn('FOO', os.environ) self.assertNotIn('ASDF', os.environ) tools.load_env(self.temp_file) self.assertIn('FOO', os.environ) self.assertIn('ASDF', os.environ) self.assertEqual(os.environ['FOO'], 'bar') self.assertEqual(os.environ['ASDF'], 'qwertz')
def take_snapshot( cfg, force = True ): """ Take a new snapshot. Args: cfg (config.Config): config that should be used force (bool): take the snapshot even if it wouldn't need to or would be prevented (e.g. running on battery) Returns: bool: ``True`` if successful """ tools.load_env(cfg.get_cron_env_file()) ret = snapshots.Snapshots( cfg ).take_snapshot( force ) return ret
def execute(): parser = argparse.ArgumentParser(description="Remove old datasets from HappyFace database") # parser.add_argument("-d", "--days", nargs=1, metavar="N", # help="Operate on the data of the past N days") # parser.add_argument("-s", "--start", nargs=1, metavar="ISOSTART", # help="ISO-date when the selected timerange bla") parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Increase verbosity of output") subparsers = parser.add_subparsers(dest="subparser_name") parser_dict = {} sub = subparsers.add_parser("list-modules", help="List detected modules.") parser_dict[sub.prog.split()[-1]] = sub sub.add_argument( "-u", "--used", action="store_true", default=False, help="List only modules used by the configuration." ) sub.add_argument( "-n", "--not-used", action="store_true", default=False, help="List only modules found in the database but unreferenced in the configuration.", ) sub.set_defaults(func=_list_modules) sub = subparsers.add_parser( "clear", help="Remove unused data from configured modules.", description="""Remove all data from used modules in specified timerange. Data from unused tables is not removed. Database backend dependent cleanup, e.g. SQLite VACUUM is \033[1m\033[31mnot\033[0m performed.""", ) parser_dict[sub.prog.split()[-1]] = sub sub.add_argument( "-i", "--interactive", action="store_true", default=False, help="Ask before cleaning a table. Ignores --silent." ) sub.add_argument("--all", action="store_true", default=False, help="Remove all data from database.") sub.add_argument("-d", "--days", nargs=1, metavar="N", help="Remove data older than N days.") sub.add_argument( "--stop-date", nargs=1, metavar="ISODATE_STOP", help="Data before ISODATE_STOP is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'.", ) sub.add_argument( "--start-date", nargs=1, metavar="ISODATE_START", help="Data after ISODATE_START is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'. Be caution when using this, potentialy new and useful data is removed! Use with --stop-date.", ) sub.add_argument( "--silent", action="store_true", default=False, help="Do not ask for user confirmation on critical actions." ) sub.set_defaults(func=_clear) sub = subparsers.add_parser("vacuum", help="Clean database heuristicaly from old data.", description="""""") parser_dict[sub.prog.split()[-1]] = sub sub.add_argument( "-i", "--interactive", action="store_true", default=False, help="Ask before cleaning a table. Ignores --silent." ) sub.add_argument("--all", action="store_true", default=False, help="Remove all data from database.") sub.add_argument("-d", "--days", nargs=1, metavar="N", help="Remove data older than N days.") sub.add_argument( "--stop-date", nargs=1, metavar="ISODATE_STOP", help="Data before ISODATE_STOP is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'.", ) sub.add_argument( "--start-date", nargs=1, metavar="ISODATE_START", help="Data after ISODATE_START is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'. Be caution when using this, potentialy new and useful data is removed! Use with --stop-date.", ) sub.add_argument( "--silent", action="store_true", default=False, help="Do not ask for user confirmation on critical actions." ) sub.set_defaults(func=_vacuum) args = parser.parse_args() tools.load_env() logger = logging.getLogger() for handlers in logger.handlers: logger.removeHandler(handlers) logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setLevel(logging.INFO) formatter = logging.Formatter("%(levelname)s: %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) ch = logging.FileHandler(os.path.join(hf.hf_dir, "log", "tool-cleanup.log")) ch.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s:%(name)s:%(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) hf.database.metadata.reflect(hf.database.engine) args.func(parser_dict[args.subparser_name], args)
try: import gtk except: pass import password import password_ipc import tools import config if __name__ == '__main__': """ return password. """ cfg = config.Config() tools.load_env(cfg.get_cron_env_file()) profile_id = os.getenv('ASKPASS_PROFILE_ID', '1') mode = os.getenv('ASKPASS_MODE', 'local') temp_file = os.getenv('ASKPASS_TEMP') if temp_file is None: #normal mode, get password from module password pw = password.Password(cfg) print(pw.get_password(None, profile_id, mode)) sys.exit(0) #temp mode fifo = password_ipc.FIFO(temp_file) pw = fifo.read(5) if pw:
def execute(): parser = argparse.ArgumentParser(description="Remove old datasets from HappyFace database") #parser.add_argument("-d", "--days", nargs=1, metavar="N", #help="Operate on the data of the past N days") #parser.add_argument("-s", "--start", nargs=1, metavar="ISOSTART", #help="ISO-date when the selected timerange bla") parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Increase verbosity of output") subparsers = parser.add_subparsers(dest="subparser_name") parser_dict = {} sub = subparsers.add_parser("list-modules", help="List detected modules.") parser_dict[sub.prog.split()[-1]] = sub sub.add_argument("-u", "--used", action="store_true", default=False, help="List only modules used by the configuration.") sub.add_argument("-n", "--not-used", action="store_true", default=False, help="List only modules found in the database but unreferenced in the configuration.") sub.set_defaults(func=_list_modules) sub = subparsers.add_parser("clear", help="Remove unused data from configured modules.", description="""Remove all data from used modules in specified timerange. Data from unused tables is not removed. Database backend dependent cleanup, e.g. SQLite VACUUM is \033[1m\033[31mnot\033[0m performed.""") parser_dict[sub.prog.split()[-1]] = sub sub.add_argument("-i", "--interactive", action="store_true", default=False, help="Ask before cleaning a table. Ignores --silent.") sub.add_argument("--all", action="store_true", default=False, help="Remove all data from database.") sub.add_argument("-d", "--days", nargs=1, metavar="N", help="Remove data older than N days.") sub.add_argument("--stop-date", nargs=1, metavar="ISODATE_STOP", help="Data before ISODATE_STOP is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'.") sub.add_argument("--start-date", nargs=1, metavar="ISODATE_START", help="Data after ISODATE_START is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'. Be caution when using this, potentialy new and useful data is removed! Use with --stop-date.") sub.add_argument("--silent", action="store_true", default=False, help="Do not ask for user confirmation on critical actions.") sub.set_defaults(func=_clear) sub = subparsers.add_parser("vacuum", help="Clean database heuristicaly from old data.", description="""""") parser_dict[sub.prog.split()[-1]] = sub sub.add_argument("-i", "--interactive", action="store_true", default=False, help="Ask before cleaning a table. Ignores --silent.") sub.add_argument("--all", action="store_true", default=False, help="Remove all data from database.") sub.add_argument("-d", "--days", nargs=1, metavar="N", help="Remove data older than N days.") sub.add_argument("--stop-date", nargs=1, metavar="ISODATE_STOP", help="Data before ISODATE_STOP is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'.") sub.add_argument("--start-date", nargs=1, metavar="ISODATE_START", help="Data after ISODATE_START is removed from the database. Use ISO date format 'YYYY-MM-DD HH:MM'. Be caution when using this, potentialy new and useful data is removed! Use with --stop-date.") sub.add_argument("--silent", action="store_true", default=False, help="Do not ask for user confirmation on critical actions.") sub.set_defaults(func=_vacuum) args = parser.parse_args() tools.load_env() logger = logging.getLogger() for handlers in logger.handlers: logger.removeHandler(handlers) logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setLevel(logging.INFO) formatter = logging.Formatter('%(levelname)s: %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) ch = logging.FileHandler(os.path.join(hf.hf_dir, "log", "tool-cleanup.log")) ch.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s:%(name)s:%(levelname)s - %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) hf.database.metadata.reflect(hf.database.engine) args.func(parser_dict[args.subparser_name], args)