Ejemplo n.º 1
0
std::ostream & Configuration::help(
  std::ostream & s,
  const boost::program_options::options_description & options) const {
version(s)
    << "\n"
    "Kvalobs check runner. This program may either run in daemon mode continuously\n"
    "checking all incoming observations to kvalobs. As an alternative, you may\n"
    "specify a single station, obstime and typeid to check. Daemon mode will not be\n"
    "entered if you do this.\n"
    "\n";

#ifdef QABASE_NO_SAVE
s << "This is a testing version which will not write any check results back to the\n"
"database.\n\n";
#endif

boost::filesystem::path defaultConfig = defaultConfigFile();
if (not defaultConfig.empty())
  s << "Additional configuration is read from <"
    << to_native_file(defaultConfig) << ">\n\n";

s << options << std::endl;

return s;
}
Ejemplo n.º 2
0
Configuration::Configuration(int & argc, char ** argv)
  : runNormally_(true),
    observationToCheck_(0),
    logLevel_(milog::DEBUG),
    port_(0) {
const char * USER = std::getenv("USER");
const std::string databaseUser = USER ? USER : "******";

options_description commandLine("Command-line options");

options_description observation("Single observation");
observation.add_options()("station,s", value<int>(), "Check the given station")(
    "obstime,o", value<std::string>(), "Check the given obstime")(
    "typeid,t", value<int>(), "Check the given typeid")(
    "qcx",
    value<std::string>(),
    "Only run the given check. This also means that control flags will not be reset before checks are run")(
    "model-source", value<std::string>(&modelDataName_)->default_value("yr"),
    "Get model data from the given source (from model table in database");

options_description logging("Logging");
logging.add_options()(
    "runloglevel", value<std::string>()->default_value("info"),
    "Set loglevel (debug_all, debug, info, warn, error or fatal")(
    "runlogfile",
    value<std::string>(&runLogFile_)->default_value(
        kvalobs::kvPath(kvalobs::logdir) + "/kvQabased.log"),
    "Set file name for run log")(
    "logdir",
    value<std::string>(&baseLogDir_)->default_value(
        kvalobs::kvPath(kvalobs::logdir) + "/checks/"),
    "Use the given directory as base directory for script logs");

options_description database("Database");
database.add_options()(
    "database,d", value<std::string>(&databaseName_)->default_value("kvalobs"),
    "Name of database to connect to")("host,h", value<std::string>(&host_),
                                      "Hostname of database")(
    "port,p", value<int>(&port_), "Port of database")(
    "user,U", value<std::string>(&user_)->default_value(databaseUser),
    "Database user");

options_description generic("Generic");
generic.add_options()
    ("process-count", value<unsigned>(& processCount_)->default_value(4), "Run the given number of processes")
    ("config", value<std::string>(), "Read configuration from the given file")
    ("version", "Produce version information")
    ("help", "Produce help message");

commandLine.add(observation).add(logging).add(database).add(generic);

parsed_options parsed = command_line_parser(argc, argv).options(commandLine).
//allow_unregistered().
    run();
variables_map vm;
store(parsed, vm);
notify(vm);

if (vm.count("version")) {
  version(std::cout);
  runNormally_ = false;
  return;
}
if (vm.count("help")) {
  help(std::cout, commandLine);
  runNormally_ = false;
  return;
}

options_description configFileOptions;
configFileOptions.add(logging).add(database);

if (vm.count("config"))
  parse(vm["config"].as<std::string>(), vm, configFileOptions);

boost::filesystem::path defaultConfig = defaultConfigFile();
if (not defaultConfig.empty())
  parse(defaultConfig, vm, configFileOptions);

if (vm.count("qcx")) {
  std::string qcxFilter = vm["qcx"].as<std::string>();
  qcxFilter_.push_back(qcxFilter);
}

if (vm.count("runloglevel")) {
  std::string wantedLevel = vm["runloglevel"].as<std::string>();
  if (wantedLevel == "debug_all")
    logLevel_ = milog::DEBUG1;
  else if (wantedLevel == "debug")
    logLevel_ = milog::DEBUG;
  else if (wantedLevel == "info")
    logLevel_ = milog::INFO;
  else if (wantedLevel == "warn")
    logLevel_ = milog::WARN;
  else if (wantedLevel == "error")
    logLevel_ = milog::ERROR;
  else if (wantedLevel == "fatal")
    logLevel_ = milog::FATAL;
  else
    throw std::runtime_error(wantedLevel + " is not a valid loglevel");
}
//milog::Logger::logger().logLevel(logLevel_);

observationToCheck_ = getStationInfo(vm);
}
Ejemplo n.º 3
0
bool AppearanceGTK2::saveSettings(const QString& gtkrcFile) const
{
    QFile gtkrc(gtkrcFile);
    gtkrc.remove();

    if(!gtkrc.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qWarning() << "There was unable to write the file .gtkrc-2.0";
        return false;
    }

    QTextStream flow(&gtkrc);

    flow << "# File created by KDE Gtk Config" << "\n"
         << "# Configs for GTK2 programs \n\n";

    QString themeGtkrcFile=themesGtkrcFile(getTheme());
    
    //TODO: is this really needed?
    if(!themeGtkrcFile.isEmpty())
        flow << "include \"" << themeGtkrcFile << "\"\n"; //We include the theme's gtkrc file
    
    if(QFile::exists("/etc/gtk-2.0/gtkrc"))
        flow  << "include \"/etc/gtk-2.0/gtkrc\"\n"; //We include the /etc's config file

    int nameEnd = m_settings["font"].lastIndexOf(QRegExp(" ([0-9]+|bold|italic)"));
    QString fontFamily = m_settings["font"].left(nameEnd);

    //TODO: is this really needed?
    flow << "style \"user-font\" \n"
            << "{\n"
            << "\tfont_name=\""<< fontFamily << "\"\n"
            << "}\n";
    
    flow << "widget_class \"*\" style \"user-font\"\n";
    flow << "gtk-font-name=\"" << m_settings["font"] << "\"\n";
    flow << "gtk-theme-name=\"" << m_settings["theme"] << "\"\n";
    flow << "gtk-icon-theme-name=\""<< m_settings["icon"] << "\"\n";
    flow << "gtk-fallback-icon-theme=\"" << m_settings["icon_fallback"] << "\"\n";
    flow << "gtk-cursor-theme-name=\"" << m_settings["cursor"] << "\"\n";
    flow << "gtk-toolbar-style=" << m_settings["toolbar_style"] << "\n";
    flow << "gtk-menu-images=" << m_settings["show_icons_menus"] << "\n";
    flow << "gtk-button-images=" << m_settings["show_icons_buttons"] << "\n";
    flow << "gtk-primary-button-warps-slider=" << m_settings["primary_button_warps_slider"] << "\n";
    
    //we're done with the  ~/.gtk-2.0 file
    gtkrc.close();
    
    //TODO: do we really need the linked file?
    if(QFile::remove(gtkrcFile+"-kde4"))
        qDebug() << "ready to create the symbolic link";
    
    if( !QFile::link(gtkrcFile, gtkrcFile+"-kde4") )
        qWarning() << "Couldn't create the symboling link to .gtkrc-2.0-kde4 :(";
//     else
//         qDebug() << "Symbolic link created for .gtkrc-2.0-kde4 :D";
    
    if(gtkrcFile==defaultConfigFile())
        QProcess::startDetached(QStandardPaths::findExecutable("reload_gtk_apps"));
    
    return true;
}