|
35 | 35 | #include "qgscustomization.h"
|
36 | 36 | #include "qgspluginregistry.h"
|
37 | 37 | #include "qgsmessagelog.h"
|
| 38 | +#include "qgspythonrunner.h" |
38 | 39 |
|
39 | 40 | #include <cstdio>
|
40 | 41 | #include <stdio.h>
|
@@ -106,6 +107,7 @@ void usage( std::string const & appName )
|
106 | 107 | << "\t[--nocustomization]\tdon't apply GUI customization\n"
|
107 | 108 | << "\t[--optionspath path]\tuse the given QSettings path\n"
|
108 | 109 | << "\t[--configpath path]\tuse the given path for all user configuration\n"
|
| 110 | + << "\t[--code path]\tRun the given python file on load. \n" |
109 | 111 | << "\t[--help]\t\tthis text\n\n"
|
110 | 112 | << " FILES:\n"
|
111 | 113 | << " Files specified on the command line can include rasters,\n"
|
@@ -266,6 +268,8 @@ int main( int argc, char *argv[] )
|
266 | 268 | QString configpath;
|
267 | 269 | QString optionpath;
|
268 | 270 |
|
| 271 | + QString pythonfile; |
| 272 | + |
269 | 273 | #if defined(ANDROID)
|
270 | 274 | QgsDebugMsg( QString( "Android: All params stripped" ) );// Param %1" ).arg( argv[0] ) );
|
271 | 275 | //put all QGIS settings in the same place
|
@@ -325,6 +329,10 @@ int main( int argc, char *argv[] )
|
325 | 329 | {
|
326 | 330 | configpath = argv[++i];
|
327 | 331 | }
|
| 332 | + else if ( i + 1 < argc && ( arg == "--code" || arg == "-f" ) ) |
| 333 | + { |
| 334 | + pythonfile = argv[++i]; |
| 335 | + } |
328 | 336 | else
|
329 | 337 | {
|
330 | 338 | myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
|
@@ -358,6 +366,7 @@ int main( int argc, char *argv[] )
|
358 | 366 | {"extent", required_argument, 0, 'e'},
|
359 | 367 | {"optionspath", required_argument, 0, 'o'},
|
360 | 368 | {"configpath", required_argument, 0, 'c'},
|
| 369 | + {"code", required_argument, 0, 'f'}, |
361 | 370 | {"android", required_argument, 0, 'a'},
|
362 | 371 | {0, 0, 0, 0}
|
363 | 372 | };
|
@@ -428,6 +437,10 @@ int main( int argc, char *argv[] )
|
428 | 437 | configpath = optarg;
|
429 | 438 | break;
|
430 | 439 |
|
| 440 | + case 'f': |
| 441 | + pythonfile = optarg; |
| 442 | + break; |
| 443 | + |
431 | 444 | case '?':
|
432 | 445 | usage( argv[0] );
|
433 | 446 | return 2; // XXX need standard exit codes
|
@@ -769,7 +782,16 @@ int main( int argc, char *argv[] )
|
769 | 782 | }
|
770 | 783 | }
|
771 | 784 |
|
772 |
| - ///////////////////////////////////////////////////////////////////// |
| 785 | + if ( !pythonfile.isEmpty() ) |
| 786 | + { |
| 787 | +#ifdef Q_WS_WIN |
| 788 | + //replace backslashes with forward slashes |
| 789 | + pythonfile.replace( "\\", "/" ); |
| 790 | +#endif |
| 791 | + QgsPythonRunner::run(QString("execfile('%1')").arg(pythonfile)); |
| 792 | + } |
| 793 | + |
| 794 | + /////////////////////////////////`//////////////////////////////////// |
773 | 795 | // Take a snapshot of the map view then exit if snapshot mode requested
|
774 | 796 | /////////////////////////////////////////////////////////////////////
|
775 | 797 | if ( mySnapshotFileName != "" )
|
@@ -797,7 +819,6 @@ int main( int argc, char *argv[] )
|
797 | 819 | return 1;
|
798 | 820 | }
|
799 | 821 |
|
800 |
| - |
801 | 822 | /////////////////////////////////////////////////////////////////////
|
802 | 823 | // Continue on to interactive gui...
|
803 | 824 | /////////////////////////////////////////////////////////////////////
|
|
0 commit comments