Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2496 from SebDieBln/App_OptionsAsFiles
Accept option '--' to mark all following arguments as files (refs #3714)
  • Loading branch information
wonder-sk committed Jan 27, 2016
2 parents 80e3f8f + b4561a9 commit 42ea15b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/app/main.cpp
Expand Up @@ -133,7 +133,8 @@ void usage( std::string const & appName )
<< "\t[--dxf-scale-denom scale]\tscale for dxf output\n"
<< "\t[--dxf-encoding encoding]\tencoding to use for dxf output\n"
<< "\t[--dxf-preset visiblity-preset]\tlayer visibility preset to use for dxf output\n"
<< "\t[--help]\t\tthis text\n\n"
<< "\t[--help]\t\tthis text\n"
<< "\t[--]\t\ttreat all following arguments as FILEs\n\n"
<< " FILE:\n"
<< " Files specified on the command line can include rasters,\n"
<< " vectors, and QGIS project files (.qgs): \n"
Expand Down Expand Up @@ -683,6 +684,11 @@ int main( int argc, char *argv[] )
{
dxfPreset = args[++i];
}
else if ( arg == "--" )
{
for ( i++; i < args.size(); ++i )
myFileList.append( QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() ) );
}
else
{
myFileList.append( QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() ) );
Expand Down
27 changes: 24 additions & 3 deletions tests/src/python/test_qgsappstartup.py
Expand Up @@ -24,6 +24,7 @@
import shutil
import subprocess
import tempfile
import errno

from utilities import unittest, unitTestDataPath

Expand All @@ -47,7 +48,7 @@ def tearDownClass(cls):
# TODO: refactor parameters to **kwargs to handle all startup combinations
def doTestStartup(self, option='', testDir='', testFile='',
loadPlugins=False, customization=False,
timeOut=15, env=None):
timeOut=15, env=None, additionalArguments = []):
"""Run QGIS with the given option. Wait for testFile to be created.
If time runs out, fail.
"""
Expand Down Expand Up @@ -75,19 +76,28 @@ def doTestStartup(self, option='', testDir='', testFile='',
myenv.update(env)

p = subprocess.Popen(
[QGIS_BIN, "--nologo", plugins, customize, option, testDir],
[QGIS_BIN, "--nologo", plugins, customize, option, testDir] + additionalArguments,
env=myenv)

s = 0
ok = True
while not os.path.exists(myTestFile):
p.poll()
if p.returncode is not None:
ok = False
break
time.sleep(1)
s += 1
if s > timeOut:
ok = False
break

p.terminate()
try:
p.terminate()
except OSError as e:
if e.errno != errno.ESRCH:
raise

return ok

def testOptionsPath(self):
Expand Down Expand Up @@ -155,6 +165,17 @@ def testPyQgisStartupEnvVar(self):
timeOut=120,
env={'PYQGIS_STARTUP': testmod}), msg

def testOptionsAsFiles(self):
# verify QGIS accepts filenames that match options after the special option '--'
# '--help' should return immediatly (after displaying the usage hints)
# '-- --help' should not exit but try (and probably fail) to load a layer called '--help'
for t in [(False, ['--help']), (True, ['--', '--help'])]:
assert t[0] == self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
testFile="qgis.db",
timeOut=15,
additionalArguments = t[1]), "additional arguments: %s" % ' '.join(t[1])


if __name__ == '__main__':
# look for qgis bin path
Expand Down

0 comments on commit 42ea15b

Please sign in to comment.