Python-i18n: apply C++-coding style
This commit is contained in:
parent
538c59adb9
commit
5dc70ac261
@ -46,50 +46,50 @@ mount( const std::string& device_path,
|
|||||||
const std::string& options )
|
const std::string& options )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()->
|
||||||
mount( QString::fromStdString( device_path ),
|
mount( QString::fromStdString( device_path ),
|
||||||
QString::fromStdString( mount_point ),
|
QString::fromStdString( mount_point ),
|
||||||
QString::fromStdString( filesystem_name ),
|
QString::fromStdString( filesystem_name ),
|
||||||
QString::fromStdString( options ) );
|
QString::fromStdString( options ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
target_env_call( const std::string& command,
|
target_env_call( const std::string& command,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()->
|
||||||
targetEnvCall( QString::fromStdString( command ),
|
targetEnvCall( QString::fromStdString( command ),
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
timeout );
|
timeout );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
target_env_call( const bp::list& args,
|
target_env_call( const bp::list& args,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
for ( int i = 0; i < bp::len( args ); ++i )
|
for ( int i = 0; i < bp::len( args ); ++i )
|
||||||
{
|
{
|
||||||
list.append( QString::fromStdString(
|
list.append( QString::fromStdString(
|
||||||
bp::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()->
|
||||||
targetEnvCall( list,
|
targetEnvCall( list,
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
timeout );
|
timeout );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
check_target_env_call( const std::string& command,
|
check_target_env_call( const std::string& command,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
int ec = target_env_call( command, stdin, timeout );
|
int ec = target_env_call( command, stdin, timeout );
|
||||||
return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
||||||
@ -98,8 +98,8 @@ check_target_env_call( const std::string& command,
|
|||||||
|
|
||||||
int
|
int
|
||||||
check_target_env_call( const bp::list& args,
|
check_target_env_call( const bp::list& args,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
int ec = target_env_call( args, stdin, timeout );
|
int ec = target_env_call( args, stdin, timeout );
|
||||||
if ( !ec )
|
if ( !ec )
|
||||||
@ -109,7 +109,7 @@ check_target_env_call( const bp::list& args,
|
|||||||
for ( int i = 0; i < bp::len( args ); ++i )
|
for ( int i = 0; i < bp::len( args ); ++i )
|
||||||
{
|
{
|
||||||
failedCmdList.append( QString::fromStdString(
|
failedCmdList.append( QString::fromStdString(
|
||||||
bp::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) );
|
return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) );
|
||||||
@ -118,8 +118,8 @@ check_target_env_call( const bp::list& args,
|
|||||||
|
|
||||||
std::string
|
std::string
|
||||||
check_target_env_output( const std::string& command,
|
check_target_env_output( const std::string& command,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
QString output;
|
QString output;
|
||||||
int ec = CalamaresUtils::System::instance()->
|
int ec = CalamaresUtils::System::instance()->
|
||||||
@ -135,15 +135,15 @@ check_target_env_output( const std::string& command,
|
|||||||
|
|
||||||
std::string
|
std::string
|
||||||
check_target_env_output( const bp::list& args,
|
check_target_env_output( const bp::list& args,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
QString output;
|
QString output;
|
||||||
QStringList list;
|
QStringList list;
|
||||||
for ( int i = 0; i < bp::len( args ); ++i )
|
for ( int i = 0; i < bp::len( args ); ++i )
|
||||||
{
|
{
|
||||||
list.append( QString::fromStdString(
|
list.append( QString::fromStdString(
|
||||||
bp::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int ec = CalamaresUtils::System::instance()->
|
int ec = CalamaresUtils::System::instance()->
|
||||||
@ -165,8 +165,8 @@ _handle_check_target_env_call_error( int ec, const QString& cmd )
|
|||||||
|
|
||||||
QString raise = QString( "import subprocess\n"
|
QString raise = QString( "import subprocess\n"
|
||||||
"raise subprocess.CalledProcessError(%1,\"%2\")" )
|
"raise subprocess.CalledProcessError(%1,\"%2\")" )
|
||||||
.arg( ec )
|
.arg( ec )
|
||||||
.arg( cmd );
|
.arg( cmd );
|
||||||
bp::exec( raise.toStdString().c_str() );
|
bp::exec( raise.toStdString().c_str() );
|
||||||
bp::throw_error_already_set();
|
bp::throw_error_already_set();
|
||||||
return ec;
|
return ec;
|
||||||
@ -226,16 +226,16 @@ _gettext_languages()
|
|||||||
if ( lang_.canConvert< QString >() )
|
if ( lang_.canConvert< QString >() )
|
||||||
{
|
{
|
||||||
QString lang = lang_.value< QString >();
|
QString lang = lang_.value< QString >();
|
||||||
languages.append(lang);
|
languages.append( lang );
|
||||||
if ( lang.indexOf( '.' ) > 0)
|
if ( lang.indexOf( '.' ) > 0 )
|
||||||
{
|
{
|
||||||
lang.truncate( lang.indexOf( '.' ) );
|
lang.truncate( lang.indexOf( '.' ) );
|
||||||
languages.append(lang);
|
languages.append( lang );
|
||||||
}
|
}
|
||||||
if ( lang.indexOf( '_' ) > 0)
|
if ( lang.indexOf( '_' ) > 0 )
|
||||||
{
|
{
|
||||||
lang.truncate( lang.indexOf( '_' ) );
|
lang.truncate( lang.indexOf( '_' ) );
|
||||||
languages.append(lang);
|
languages.append( lang );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,21 +246,19 @@ bp::list
|
|||||||
gettext_languages()
|
gettext_languages()
|
||||||
{
|
{
|
||||||
bp::list pyList;
|
bp::list pyList;
|
||||||
for (auto lang : _gettext_languages())
|
for ( auto lang : _gettext_languages() )
|
||||||
pyList.append( lang.toStdString() );
|
pyList.append( lang.toStdString() );
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_add_localedirs(QStringList &pathList, const QString &candidate)
|
_add_localedirs( QStringList& pathList, const QString& candidate )
|
||||||
{
|
{
|
||||||
if (!candidate.isEmpty() && !pathList.contains(candidate))
|
if ( !candidate.isEmpty() && !pathList.contains( candidate ) )
|
||||||
{
|
{
|
||||||
pathList.prepend(candidate);
|
pathList.prepend( candidate );
|
||||||
if (QDir(candidate).cd("lang"))
|
if ( QDir( candidate ).cd( "lang" ) )
|
||||||
{
|
pathList.prepend( candidate + "/lang" );
|
||||||
pathList.prepend(candidate + "/lang");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,27 +267,25 @@ gettext_path()
|
|||||||
{
|
{
|
||||||
// TODO: distinguish between -d runs and normal runs
|
// TODO: distinguish between -d runs and normal runs
|
||||||
// TODO: can we detect DESTDIR-installs?
|
// TODO: can we detect DESTDIR-installs?
|
||||||
QStringList candidatePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory);
|
QStringList candidatePaths = QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory );
|
||||||
QString extra = QCoreApplication::applicationDirPath();
|
QString extra = QCoreApplication::applicationDirPath();
|
||||||
_add_localedirs(candidatePaths, extra); // Often /usr/local/bin
|
_add_localedirs( candidatePaths, extra ); // Often /usr/local/bin
|
||||||
if ( !extra.isEmpty() )
|
if ( !extra.isEmpty() )
|
||||||
{
|
{
|
||||||
QDir d(extra);
|
QDir d( extra );
|
||||||
if (d.cd("../share/locale")) // Often /usr/local/bin/../share/locale -> /usr/local/share/locale
|
if ( d.cd( "../share/locale" ) ) // Often /usr/local/bin/../share/locale -> /usr/local/share/locale
|
||||||
{
|
_add_localedirs( candidatePaths, d.canonicalPath() );
|
||||||
_add_localedirs(candidatePaths, d.canonicalPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_add_localedirs(candidatePaths, QDir().canonicalPath()); // .
|
_add_localedirs( candidatePaths, QDir().canonicalPath() ); // .
|
||||||
|
|
||||||
cDebug() << "Standard paths" << candidatePaths;
|
cDebug() << "Standard paths" << candidatePaths;
|
||||||
|
|
||||||
for (auto lang : _gettext_languages())
|
for ( auto lang : _gettext_languages() )
|
||||||
for (auto localedir : candidatePaths)
|
for ( auto localedir : candidatePaths )
|
||||||
{
|
{
|
||||||
QDir ldir(localedir);
|
QDir ldir( localedir );
|
||||||
cDebug() << "Checking" << lang << "in" <<ldir.canonicalPath();
|
cDebug() << "Checking" << lang << "in" <<ldir.canonicalPath();
|
||||||
if (ldir.cd(lang))
|
if ( ldir.cd( lang ) )
|
||||||
return bp::object( localedir.toStdString() );
|
return bp::object( localedir.toStdString() );
|
||||||
}
|
}
|
||||||
return bp::object(); // None
|
return bp::object(); // None
|
||||||
|
Loading…
Reference in New Issue
Block a user