Merge branch 'fix-unpackfs-progress'

This is an ugly hack, using Bill Auger's support for Job weights.
The unpackfs job is arbitrarily awarded a weight of 12. That makes it
(in a Netrunner install) use progress from 12% to 40% or so, overall,
as all the files are unpacked.

Also fixes bug reported by Kevin Kofler that unpackfs was only reporting
progress when it hit an exact multiple of 100 (instead of over 100).

SEE #1176
This commit is contained in:
Adriaan de Groot 2020-01-25 11:53:31 +01:00
commit 96946a8447
6 changed files with 36 additions and 6 deletions

View File

@ -37,7 +37,12 @@ macro( _find_boost_python3_int boost_version componentname found_var )
find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
string( TOUPPER ${_fbp_name} _fbp_uc_name )
if( Boost_${_fbp_uc_name}_FOUND )
set( ${found_var} ${_fbp_uc_name} )
if( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
# No upcasing
set( ${found_var} ${_fbp_name} )
else()
set( ${found_var} ${_fbp_uc_name} )
endif()
break()
endif()
endforeach()
@ -63,7 +68,7 @@ macro( find_boost_python3 boost_version python_version found_var )
endif()
set( ${found_var} ${_fbp_found} )
# This is superfluous, but allows proper reporting in the features list
if ( _fbp_found )
find_package( Boost ${boost_version} COMPONENTS ${_fbp_found} )

View File

@ -96,6 +96,14 @@ public:
explicit Job( QObject* parent = nullptr );
virtual ~Job();
/** @brief The job's (relative) weight.
*
* The default implementation returns 1.0, which gives all jobs
* the same weight, so they advance the overall progress the same
* amount. This is nonsense, since some jobs take much longer than
* others; it's up to the individual jobs to say something about
* how much work is (relatively) done.
*/
virtual qreal getJobWeight() const;
virtual QString prettyName() const = 0;
virtual QString prettyDescription() const;

View File

@ -170,7 +170,8 @@ namespace Calamares
{
PythonJob::PythonJob( const QString& scriptFile,
PythonJob::PythonJob( const QString& instance,
const QString& scriptFile,
const QString& workingPath,
const QVariantMap& moduleConfiguration,
QObject* parent )
@ -179,12 +180,18 @@ PythonJob::PythonJob( const QString& scriptFile,
, m_workingPath( workingPath )
, m_description()
, m_configurationMap( moduleConfiguration )
, m_weight( (instance == QStringLiteral( "unpackfs" )) ? 12.0 : 1.0 )
{
}
PythonJob::~PythonJob() {}
qreal
PythonJob::getJobWeight() const
{
return m_weight;
}
QString
PythonJob::prettyName() const

View File

@ -21,6 +21,8 @@
#include "Job.h"
#include "modulesystem/InstanceKey.h"
#include <QVariant>
namespace CalamaresPython
@ -36,7 +38,8 @@ class PythonJob : public Job
{
Q_OBJECT
public:
explicit PythonJob( const QString& scriptFile,
explicit PythonJob( const QString& instance, // TODO: InstanceKey
const QString& scriptFile,
const QString& workingPath,
const QVariantMap& moduleConfiguration = QVariantMap(),
QObject* parent = nullptr );
@ -46,6 +49,8 @@ public:
QString prettyStatusMessage() const override;
JobResult exec() override;
virtual qreal getJobWeight() const override;
private:
friend class CalamaresPython::Helper;
friend class CalamaresPython::PythonJobInterface;
@ -56,6 +61,7 @@ private:
QString m_workingPath;
QString m_description;
QVariantMap m_configurationMap;
qreal m_weight;
};
} // namespace Calamares

View File

@ -49,7 +49,7 @@ PythonJobModule::loadSelf()
return;
}
m_job = Calamares::job_ptr( new PythonJob( m_scriptFileName, m_workingPath, m_configurationMap ) );
m_job = Calamares::job_ptr( new PythonJob( name(), m_scriptFileName, m_workingPath, m_configurationMap ) );
m_loaded = true;
}

View File

@ -132,6 +132,9 @@ def file_copy(source, entry, progress_cb):
process = subprocess.Popen(
args, env=at_env, bufsize=1, stdout=subprocess.PIPE, close_fds=ON_POSIX
)
# last_num_files_copied trails num_files_copied, and whenever at least 100 more
# files have been copied, progress is reported and last_num_files_copied is updated.
last_num_files_copied = 0
for line in iter(process.stdout.readline, b''):
# rsync outputs progress in parentheses. Each line will have an
@ -157,7 +160,8 @@ def file_copy(source, entry, progress_cb):
num_files_copied = num_files_total_local - num_files_remaining
# I guess we're updating every 100 files...
if num_files_copied % 100 == 0:
if num_files_copied - last_num_files_copied >= 100:
last_num_files_copied = num_files_copied
progress_cb(num_files_copied, num_files_total_local)
process.wait()