mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[FEATURE] Add --code arg to run python code on qgis load
This commit is contained in:
parent
e3d30af735
commit
bfa08c5f06
@ -35,6 +35,7 @@
|
||||
#include "qgscustomization.h"
|
||||
#include "qgspluginregistry.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgspythonrunner.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdio.h>
|
||||
@ -106,6 +107,7 @@ void usage( std::string const & appName )
|
||||
<< "\t[--nocustomization]\tdon't apply GUI customization\n"
|
||||
<< "\t[--optionspath path]\tuse the given QSettings path\n"
|
||||
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
|
||||
<< "\t[--code path]\tRun the given python file on load. \n"
|
||||
<< "\t[--help]\t\tthis text\n\n"
|
||||
<< " FILES:\n"
|
||||
<< " Files specified on the command line can include rasters,\n"
|
||||
@ -266,6 +268,8 @@ int main( int argc, char *argv[] )
|
||||
QString configpath;
|
||||
QString optionpath;
|
||||
|
||||
QString pythonfile;
|
||||
|
||||
#if defined(ANDROID)
|
||||
QgsDebugMsg( QString( "Android: All params stripped" ) );// Param %1" ).arg( argv[0] ) );
|
||||
//put all QGIS settings in the same place
|
||||
@ -325,6 +329,10 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
configpath = argv[++i];
|
||||
}
|
||||
else if ( i + 1 < argc && ( arg == "--code" || arg == "-f" ) )
|
||||
{
|
||||
pythonfile = argv[++i];
|
||||
}
|
||||
else
|
||||
{
|
||||
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
|
||||
@ -358,6 +366,7 @@ int main( int argc, char *argv[] )
|
||||
{"extent", required_argument, 0, 'e'},
|
||||
{"optionspath", required_argument, 0, 'o'},
|
||||
{"configpath", required_argument, 0, 'c'},
|
||||
{"code", required_argument, 0, 'f'},
|
||||
{"android", required_argument, 0, 'a'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@ -428,6 +437,10 @@ int main( int argc, char *argv[] )
|
||||
configpath = optarg;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
pythonfile = optarg;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
usage( argv[0] );
|
||||
return 2; // XXX need standard exit codes
|
||||
@ -769,7 +782,16 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
if ( !pythonfile.isEmpty() )
|
||||
{
|
||||
#ifdef Q_WS_WIN
|
||||
//replace backslashes with forward slashes
|
||||
pythonfile.replace( "\\", "/" );
|
||||
#endif
|
||||
QgsPythonRunner::run(QString("execfile('%1')").arg(pythonfile));
|
||||
}
|
||||
|
||||
/////////////////////////////////`////////////////////////////////////
|
||||
// Take a snapshot of the map view then exit if snapshot mode requested
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
if ( mySnapshotFileName != "" )
|
||||
@ -797,7 +819,6 @@ int main( int argc, char *argv[] )
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Continue on to interactive gui...
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user