Skip to content
Permalink
Browse files

drop old user startup script in favour of the new system

User script should be placed into $HOME/.local/share/QGIS.
Additionally global scripts from /usr/local/share and
/usr/share will be loaded if present
  • Loading branch information
alexbruy committed Nov 3, 2016
1 parent 434bbea commit 373e591a80c17010db436440b5d83f6144e1a169
Showing with 16 additions and 17 deletions.
  1. +0 −5 python/user.py
  2. +14 −8 src/python/qgspythonutilsimpl.cpp
  3. +2 −4 src/python/qgspythonutilsimpl.h
@@ -55,14 +55,9 @@ def load_user_expressions(path):

userpythonhome = os.path.join(QgsApplication.qgisSettingsDirPath(), "python")
expressionspath = os.path.join(userpythonhome, "expressions")
startuppy = os.path.join(userpythonhome, "startup.py")

sys.path.append(userpythonhome)

# exec startup script
if os.path.exists(startuppy):
exec(compile(open(startuppy).read(), startuppy, 'exec'), locals(), globals())

if not os.path.exists(expressionspath):
os.makedirs(expressionspath)

@@ -210,14 +210,20 @@ bool QgsPythonUtilsImpl::checkQgisUser()
return true;
}

void QgsPythonUtilsImpl::doGlobalImports()
void QgsPythonUtilsImpl::doCustomImports()
{
QString startupPath = QStandardPaths::locate( QStandardPaths::AppDataLocation, "global_startup.py" );
//runString( "if os.path.exists(" + startuppath + "): from global_startup import *\n" );
if ( !startupPath.isEmpty() )
QStringList startupPaths = QStandardPaths::locateAll( QStandardPaths::AppDataLocation, "startup.py" );
if ( startupPaths.isEmpty() )
{
runString( "import importlib.util" );
runString( QString( "spec = importlib.util.spec_from_file_location('global_startup','%1')" ).arg( startupPath ) );
return;
}

runString( "import importlib.util" );

QStringList::const_iterator iter = startupPaths.constBegin();
for ( ; iter != startupPaths.constEnd(); ++iter )
{
runString( QString( "spec = importlib.util.spec_from_file_location('startup','%1')" ).arg( *iter ) );
runString( "module = importlib.util.module_from_spec(spec)" );
runString( "spec.loader.exec_module(module)" );
}
@@ -238,7 +244,7 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
exitPython();
return;
}
doGlobalImports();
doCustomImports();
finish();
}

@@ -264,7 +270,7 @@ void QgsPythonUtilsImpl::initServerPython( QgsServerInterface* interface )
// This is the other main difference with initInterface() for desktop plugins
runString( "qgis.utils.initServerInterface(" + QString::number(( unsigned long ) interface ) + ')' );

doGlobalImports();
doCustomImports();
finish();
}

@@ -126,13 +126,12 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
//@return true if qgis.user could be imported
bool checkQgisUser();

//! import global Python code
void doGlobalImports();
//! import custom user and global Python code (startup scripts)
void doCustomImports();

//! cleanup Python context
void finish();


void installErrorHook();

void uninstallErrorHook();
@@ -152,5 +151,4 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
bool mPythonEnabled;
};


#endif

0 comments on commit 373e591

Please sign in to comment.
You can’t perform that action at this time.