Exemple #1
0
void
ViewModule::loadSelf()
{
    if ( m_loader )
    {
        PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
        if ( !pf )
        {
            cWarning() << Q_FUNC_INFO << "No factory:" << m_loader->errorString();
            return;
        }

        m_viewStep = pf->create< Calamares::ViewStep >();
        if ( !m_viewStep )
        {
            cWarning() << Q_FUNC_INFO << "create() failed" << m_loader->errorString();
            return;
        }
    }

    // TODO: allow internal view steps to be created here; they would
    //       have to be linked into the main application somehow.

    // If any method created the view step, use it now.
    if ( m_viewStep )
    {
        m_viewStep->setModuleInstanceKey( instanceKey() );
        m_viewStep->setConfigurationMap( m_configurationMap );
        ViewManager::instance()->addViewStep( m_viewStep );
        m_loaded = true;
        cDebug() << "ViewModule" << instanceKey() << "loading complete.";
    }
    else
        cWarning() << Q_FUNC_INFO << "No view step was created";
}
Exemple #2
0
GeoIP::RegionZonePair
GeoIPXML::processReply( const QByteArray& data )
{
    QString domError;
    int errorLine, errorColumn;

    QDomDocument doc;
    if ( doc.setContent( data, false, &domError, &errorLine, &errorColumn ) )
    {
        const auto tzElements = doc.elementsByTagName( m_element );
        cDebug() << "GeoIP found" << tzElements.length() << "elements";
        for ( int it = 0; it < tzElements.length(); ++it )
        {
            auto e = tzElements.at(it).toElement();
            auto tz = splitTZString( e.text() );
            if ( !tz.first.isEmpty() )
                return tz;
        }

        // None of them valid
        cWarning() << "GeopIP XML had no recognizable timezone";
        return qMakePair( QString(), QString() );
    }
    else
    {
        cWarning() << "GeoIP XML data error:" << domError << "(line" << errorLine << errorColumn << ')';
    }

    return qMakePair( QString(), QString() );
}
Exemple #3
0
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
    foreach ( const QString& path, moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName ) )
    {
        QFile configFile( path );
        if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )
        {
            QByteArray ba = configFile.readAll();

            YAML::Node doc = YAML::Load( ba.constData() );
            if ( doc.IsNull() )
            {
                cDebug() << "Found empty module configuration" << path;
                // Special case: empty config files are valid,
                // but aren't a map.
                return;
            }
            if ( !doc.IsMap() )
            {
                cWarning() << "Bad module configuration format" << path;
                return;
            }

            cDebug() << "Loaded module configuration" << path;
            m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap();
            m_emergency = m_maybe_emergency
                          && m_configurationMap.contains( EMERGENCY )
                          && m_configurationMap[ EMERGENCY ].toBool();
            return;
        }
    }
void Config::saveStateCache()
{
    Eet_File *ef;
    std::string file = Utils::getCacheFile("iostates.cache");
    std::string tmp = file + "_tmp";
    ConfigStateCache *cache;

    cache = new ConfigStateCache;
    cache->version = CONFIG_STATES_CACHE_VERSION;
    cache->states = cache_states;

    ef = eet_open(tmp.c_str(), EET_FILE_MODE_WRITE);
    if (!ef)
    {
        cWarning() <<  "Could not open iostates.cache for write !";
        delete cache;
        return;
    }

    Eina_Bool ret = eet_data_write(ef, edd_cache, "calaos/states/cache", cache, EINA_TRUE);

    eet_close(ef);
    delete cache;

    if (ret)
    {
        ecore_file_unlink(file.c_str());
        ecore_file_mv(tmp.c_str(), file.c_str());
    }

    cInfo() <<  "State cache file written successfully (" << file << ")";
}
void Config::loadStateCache()
{
    ConfigStateCache *cache;
    std::string file = Utils::getCacheFile("iostates.cache");

    Eet_File *ef = eet_open(file.c_str(), EET_FILE_MODE_READ);
    if (!ef)
    {
        cWarning() <<  "Could not open iostates.cache for read !";
        return;
    }

    cache = (ConfigStateCache *)eet_data_read(ef, edd_cache, "calaos/states/cache");
    if (!cache)
    {
        eet_close(ef);
        cWarning() <<  "Could not read iostates.cache, corrupted file?";
        return;
    }

    if (cache->version < CONFIG_STATES_CACHE_VERSION)
    {
        cWarning() <<  "File version too old, upgrading to new format";
        cache->version = CONFIG_STATES_CACHE_VERSION;
    }

    //read all states and put it in cache_states
    Eina_Iterator *it = eina_hash_iterator_tuple_new(cache->states);
    void *data;
    while (eina_iterator_next(it, &data))
    {
        Eina_Hash_Tuple *t = (Eina_Hash_Tuple *)data;
        ConfigStateValue *state = (ConfigStateValue *)t->data;
        std::string skey = state->id;
        std::string svalue = state->value;
        SaveValueIO(skey, svalue, false);
    }
    eina_iterator_free(it);

    eina_hash_free(cache->states);
    free(cache);
    eet_close(ef);

    cInfo() <<  "States cache read successfully.";
}
Exemple #6
0
void
ModuleManager::doInit()
{
    // We start from a list of paths in m_paths. Each of those is a directory that
    // might (should) contain Calamares modules of any type/interface.
    // For each modules search path (directory), it is expected that each module
    // lives in its own subdirectory. This subdirectory must have the same name as
    // the module name, and must contain a settings file named module.desc.
    // If at any time the module loading procedure finds something unexpected, it
    // silently skips to the next module or search path. --Teo 6/2014
    for ( const QString& path : m_paths )
    {
        QDir currentDir( path );
        if ( currentDir.exists() && currentDir.isReadable() )
        {
            const QStringList subdirs = currentDir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot );
            for ( const QString& subdir : subdirs )
            {
                currentDir.setPath( path );
                bool success = currentDir.cd( subdir );
                if ( success )
                {
                    QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( QLatin1Literal( "module.desc") ) );
                    if ( ! ( descriptorFileInfo.exists() && descriptorFileInfo.isReadable() ) )
                    {
                        cDebug() << Q_FUNC_INFO << "unreadable file: "
                                 << descriptorFileInfo.absoluteFilePath();
                        continue;
                    }

                    bool ok = false;
                    QVariantMap moduleDescriptorMap = CalamaresUtils::loadYaml( descriptorFileInfo, &ok );
                    QString moduleName = ok ? moduleDescriptorMap.value( "name" ).toString() : QString();

                    if ( ok && ( moduleName == currentDir.dirName() ) &&
                            !m_availableDescriptorsByModuleName.contains( moduleName ) )
                    {
                        m_availableDescriptorsByModuleName.insert( moduleName, moduleDescriptorMap );
                        m_moduleDirectoriesByModuleName.insert( moduleName,
                                                                descriptorFileInfo.absoluteDir().absolutePath() );
                    }
                }
                else
                {
                    cWarning() << "Cannot cd into module directory "
                               << path << "/" << subdir;
                }
            }
        }
        else
            cDebug() << "ModuleManager bad search path" << path;
    }
    // At this point m_availableModules is filled with whatever was found in the
    // search paths.
    emit initDone();
}
Exemple #7
0
static CommandLine get_variant_object( const QVariantMap& m )
{
    QString command = CalamaresUtils::getString( m, "command" );
    int timeout = CalamaresUtils::getInteger( m, "timeout", CommandLine::TimeoutNotSet );

    if ( !command.isEmpty() )
        return CommandLine( command, timeout );
    cWarning() << "Bad CommandLine element" << m;
    return CommandLine();
}
Exemple #8
0
/** @brief Helper function to grab a bool out of the config, and to warn if not present. */
static bool
requireBool( const YAML::Node& config, const char* key, bool d )
{
    auto v = config[ key ];
    if ( hasValue(v) )
        return v.as< bool >();
    else
    {
        cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
        return d;
    }
}
Exemple #9
0
/** @brief Helper function to grab a QString out of the config, and to warn if not present. */
static QString
requireString( const YAML::Node& config, const char* key )
{
    auto v = config[ key ];
    if ( hasValue(v) )
        return QString::fromStdString( v.as< std::string >() );
    else
    {
        cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
        return QString();
    }
}
Exemple #10
0
static void ImpCreateNewThreadQueue(
    CString const& name, ShPtr<RuntimeQueue::semaphore_t>* sem)
{
    runtime_queue_error ec;

    ShPtr<RuntimeQueue::semaphore_t> sem_ = *sem;

#ifndef COFFEE_LOWFAT
    try
    {
#endif
        /* Enable profiler and etc. */
        State::SetInternalThreadState(State::CreateNewThreadState());

        /* First create the queue object... */
        RuntimeQueue* queue = RuntimeQueue::CreateNewQueue(name);

        /* Then notify our parent that everything is done */
        sem_->condition.notify_one();

        /* We use a mutex to allow our parent to notify us of work
         *  or changes in the queue, to allow rescheduling. */
        UqLock thread_lock(sem_->mutex);

        {
            DProfContext _(RQ_API "Running queue");
            while(sem_->running)
            {
                queue->executeTasks();

                ThreadQueueSleep(queue, thread_lock, sem_.get());
            }
        }

#ifndef COFFEE_LOWFAT
    } catch(std::exception const& e)
    {
        ec = RQE::UncaughtException;
        ec = Stacktracer::DemangleSymbol(typeid(e).name()) + ": " + e.what();
    }
#endif

    if(ec)
        cWarning(
            RQ_API "Uncaught exception!\n"
                   "\n"
                   "{0}: {1}"
                   "\n",
            ec.message(),
            ec.error_message);
}
Exemple #11
0
CommandList::CommandList::CommandList( const QVariant& v, bool doChroot, int timeout )
    : CommandList( doChroot, timeout )
{
    if ( v.type() == QVariant::List )
    {
        const auto v_list = v.toList();
        if ( v_list.count() )
            append( get_variant_stringlist( v_list ) );
        else
            cWarning() << "Empty CommandList";
    }
    else if ( v.type() == QVariant::String )
        append( v.toString() );
    else if ( v.type() == QVariant::Map )
    {
        auto c( get_variant_object( v.toMap() ) );
        if ( c.isValid() )
            append( c );
        // Otherwise warning is already given
    }
    else
        cWarning() << "CommandList does not understand variant" << v.type();
}
void EventManager::appendEvent(const CalaosEvent &ev)
{
    if (ev.getType() == CalaosEvent::EventUnkown)
    {
        cWarning() << "Event type Unkown added to queue, dropping...";
        return;
    }

    if (eventsQueue.empty())
    {
        //start idler if it was stopped
        idler = ecore_idle_enterer_add(EventManager_event_idler, this);
    }

    eventsQueue.push(ev);
}
Exemple #13
0
Settings::Settings( const QString& settingsFilePath,
                    bool debugMode,
                    QObject* parent )
    : QObject( parent )
    , m_debug( debugMode )
    , m_doChroot( true )
    , m_promptInstall( false )
    , m_disableCancel( false )
    , m_disableCancelDuringExec( false )
{
    cDebug() << "Using Calamares settings file at" << settingsFilePath;
    QFile file( settingsFilePath );
    if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
    {
        QByteArray ba = file.readAll();

        try
        {
            YAML::Node config = YAML::Load( ba.constData() );
            Q_ASSERT( config.IsMap() );

            interpretModulesSearch( debugMode, CalamaresUtils::yamlToStringList( config[ "modules-search" ] ), m_modulesSearchPaths );
            interpretInstances( config[ "instances" ], m_customModuleInstances );
            interpretSequence( config[ "sequence" ], m_modulesSequence );

            m_brandingComponentName = requireString( config, "branding" );
            m_promptInstall = requireBool( config, "prompt-install", false );
            m_doChroot = !requireBool( config, "dont-chroot", false );
            m_isSetupMode = requireBool( config, "oem-setup", !m_doChroot );
            m_disableCancel = requireBool( config, "disable-cancel", false );
            m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false );
        }
        catch ( YAML::Exception& e )
        {
            CalamaresUtils::explainYamlException( e, ba, file.fileName() );
        }
    }
    else
    {
        cWarning() << "Cannot read settings file" << file.fileName();
    }

    s_instance = this;
}
Exemple #14
0
static CommandList_t get_variant_stringlist( const QVariantList& l )
{
    CommandList_t retl;
    unsigned int count = 0;
    for ( const auto& v : l )
    {
        if ( v.type() == QVariant::String )
            retl.append( CommandLine( v.toString(), CommandLine::TimeoutNotSet ) );
        else if ( v.type() == QVariant::Map )
        {
            auto command( get_variant_object( v.toMap() ) );
            if ( command.isValid() )
                retl.append( command );
            // Otherwise warning is already given
        }
        else
            cWarning() << "Bad CommandList element" << count << v.type() << v;
        ++count;
    }
    return retl;
}
QModelIndex
PartitionModel::parent( const QModelIndex& child ) const
{
    if ( !child.isValid() )
        return QModelIndex();
    Partition* partition = partitionForIndex( child );
    if ( !partition )
        return QModelIndex();
    PartitionNode* parentNode = partition->parent();
    if ( parentNode == m_device->partitionTable() )
        return QModelIndex();

    int row = 0;
    for ( auto p : m_device->partitionTable()->children() )
    {
        if ( parentNode == p )
            return createIndex( row, 0, parentNode );
        ++row;
    }
    cWarning() << "No parent found!";
    return QModelIndex();
}
Exemple #16
0
GeoIP::RegionZonePair
GeoIPJSON::processReply( const QByteArray& data )
{
    try
    {
        YAML::Node doc = YAML::Load( data );

        QVariant var = CalamaresUtils::yamlToVariant( doc );
        if ( !var.isNull() &&
            var.isValid() &&
            var.type() == QVariant::Map )
        {
            return splitTZString( selectMap( var.toMap(), m_element.split('.'), 0 ) );
        }
        else
            cWarning() << "Invalid YAML data for GeoIPJSON";
    }
    catch ( YAML::Exception& e )
    {
        CalamaresUtils::explainYamlException( e, data, "GeoIP data");
    }

    return qMakePair( QString(), QString() );
}
Exemple #17
0
void
PartitionPage::updateButtons()
{
    bool create = false, createTable = false, edit = false, del = false, currentDeviceIsVG = false, isDeactivable = false;
    bool isRemovable = false, isVGdeactivated = false;

    QModelIndex index = m_ui->partitionTreeView->currentIndex();
    if ( index.isValid() )
    {
        const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
        Q_ASSERT( model );
        Partition* partition = model->partitionForIndex( index );
        Q_ASSERT( partition );
        bool isFree = KPMHelpers::isPartitionFreeSpace( partition );
        bool isExtended = partition->roles().has( PartitionRole::Extended );

        bool isInVG = m_core->isInVG( partition );

        create = isFree;

        // Keep it simple for now: do not support editing extended partitions as
        // it does not work with our current edit implementation which is
        // actually remove + add. This would not work with extended partitions
        // because they need to be created *before* creating logical partitions
        // inside them, so an edit must be applied without altering the job
        // order.
        // TODO: See if LVM PVs can be edited in Calamares
        edit = !isFree && !isExtended;
        del = !isFree && !isInVG;
    }

    if ( m_ui->deviceComboBox->currentIndex() >= 0 )
    {
        Device* device = nullptr;
        QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
        if ( deviceIndex.isValid() )
            device = m_core->deviceModel()->deviceForIndex( deviceIndex );
        if ( !device )
            cWarning() << "Device for updateButtons is nullptr";
        else if ( device->type() != Device::Type::LVM_Device )
        {
            createTable = true;

#ifdef WITH_KPMCORE4API
            if ( device->type() == Device::Type::SoftwareRAID_Device &&
                 static_cast< SoftwareRAID* >(device)->status() == SoftwareRAID::Status::Inactive )
            {
                createTable = false;
                create = false;
            }
#endif
        }
        else
        {
            currentDeviceIsVG = true;

            LvmDevice* lvmDevice = dynamic_cast<LvmDevice*>(m_core->deviceModel()->deviceForIndex( deviceIndex ));

            isDeactivable = DeactivateVolumeGroupOperation::isDeactivatable( lvmDevice );
            isRemovable = RemoveVolumeGroupOperation::isRemovable( lvmDevice );

            isVGdeactivated = m_core->isVGdeactivated( lvmDevice );

            if ( isVGdeactivated )
                m_ui->revertButton->setEnabled( true );
        }
    }

    m_ui->createButton->setEnabled( create );
    m_ui->editButton->setEnabled( edit );
    m_ui->deleteButton->setEnabled( del );
    m_ui->newPartitionTableButton->setEnabled( createTable );
    m_ui->resizeVolumeGroupButton->setEnabled( currentDeviceIsVG && !isVGdeactivated );
    m_ui->deactivateVolumeGroupButton->setEnabled( currentDeviceIsVG && isDeactivable && !isVGdeactivated );
    m_ui->removeVolumeGroupButton->setEnabled( currentDeviceIsVG && isRemovable );
}
Exemple #18
0
void
warning( const std::string& s )
{
    cWarning() << "[PYTHON JOB]: " << QString::fromStdString( s );
}
Exemple #19
0
QColor
colorForPartition( Partition* partition )
{
    if ( !partition )
    {
        cWarning() << "NULL partition";
        return FREE_SPACE_COLOR;
    }

    if ( KPMHelpers::isPartitionFreeSpace( partition ) )
        return FREE_SPACE_COLOR;
    if ( partition->roles().has( PartitionRole::Extended ) )
        return EXTENDED_COLOR;

    if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
         !partition->fileSystem().uuid().isEmpty() )
    {
        if ( partition->fileSystem().type() == FileSystem::Luks )
        {
            FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
            if ( !luksFs.outerUuid().isEmpty() &&
                 s_partitionColorsCache.contains( luksFs.outerUuid() ) )
                return s_partitionColorsCache[ luksFs.outerUuid() ];
        }

        if ( s_partitionColorsCache.contains( partition->fileSystem().uuid() ) )
            return s_partitionColorsCache[ partition->fileSystem().uuid() ];
    }

    // No partition-specific color needed, pick one from our list, but skip
    // free space: we don't want a partition to change colors if space before
    // it is inserted or removed
    PartitionNode* parent = _findRootForPartition( partition );
    PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
    Q_ASSERT( table );
    int colorIdx = 0;
    int newColorIdx = 0;
    for ( PartitionIterator it = PartitionIterator::begin( table );
          it != PartitionIterator::end( table );
          ++it )
    {
        Partition* child = *it;
        if ( child == partition )
            break;
        if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
             !child->hasChildren() )
        {
            if ( KPMHelpers::isPartitionNew( child ) )
                ++newColorIdx;
            ++colorIdx;
        }
    }

    if ( KPMHelpers::isPartitionNew( partition ) )
        return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];

    if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
         !partition->fileSystem().uuid().isEmpty() )
    {
        if ( partition->fileSystem().type() == FileSystem::Luks )
        {
            FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
            if ( !luksFs.outerUuid().isEmpty() )
            {
                s_partitionColorsCache.insert( luksFs.outerUuid(),
                                               PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
            }
        }
        else
            s_partitionColorsCache.insert( partition->fileSystem().uuid(),
                                           PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
    }
    return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
}