qgis_homedir_plugins.diff

patch to allow python plugins in the user's home dir - perrygeo -, 2007-10-21 01:20 PM

Download (4.22 KB)

View differences:

app/qgspythonutils.h (working copy)
15 15
/* $Id$ */
16 16

  
17 17
#include <QString>
18
#include <QStringList>
18 19

  
19 20
// forward declaration for PyObject
20 21
#ifndef PyObject_HEAD
......
84 85
    
85 86
    //! return current path for python plugins
86 87
    static QString pluginsPath();
87
    
88

  
89
    //! return current path for home directory python plugins
90
    static QString homePluginsPath();
91

  
92
    //! return list of all available python plugins
93
    static QStringList pluginList();
94
        
88 95
    //! load python plugin (import)
89 96
    static bool loadPlugin(QString packageName);
90 97
    
app/qgspluginmanager.cpp (working copy)
83 83
  if (!QgsPythonUtils::isEnabled())
84 84
    return;
85 85
  
86
  // look for plugins
87
  QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
88
                 QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
89

  
90
  for (uint i = 0; i < pluginDir.count(); i++)
86
  // look for plugins systemwide
87
  QStringList pluginList = QgsPythonUtils::pluginList();
88
  
89
  for (uint i = 0; i < pluginList.size(); i++)
91 90
  {
92
    QString packageName = pluginDir[i];
93
    
91
    QString packageName = pluginList[i];
92

  
94 93
    // import plugin's package
95 94
    QgsPythonUtils::loadPlugin(packageName);
96 95
    
......
125 124
        pl->setOn(true);
126 125
      }
127 126
    }
128
  
129 127
  }
130 128
#endif
131 129
}
app/qgspythonutils.cpp (working copy)
24 24
#include "qgslogger.h"
25 25

  
26 26
#include <QMessageBox>
27
#include <QStringList>
28
#include <QDir>
27 29

  
28

  
29 30
QString QgsPythonUtils::mPluginsPath;
30 31
PyObject* QgsPythonUtils::mMainModule;
31 32
PyObject* QgsPythonUtils::mMainDict;
......
47 48
  
48 49
  // expect that bindings are installed locally, so add the path to modules
49 50
  // also add path to plugins
50
  runString("sys.path = [\"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");
51
  runString("sys.path = [\"" + homePluginsPath()  + "\", \"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");
51 52

  
52 53
  // import SIP
53 54
  if (!runString("from sip import wrapinstance, unwrapinstance"))
......
284 285
  return pythonPath() + "/plugins";
285 286
}
286 287

  
288
QString QgsPythonUtils::homePluginsPath()
289
{
290
  return QgsApplication::qgisSettingsDirPath() + "/python/plugins/";
291
}
292

  
293
QStringList QgsPythonUtils::pluginList()
294
{
295
  QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
296
                 QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
297

  
298
  QDir homePluginDir(QgsPythonUtils::homePluginsPath(), "*",
299
		     QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
300

  
301
  QStringList pluginList = pluginDir.entryList();
302

  
303
  for (uint i = 0; i < homePluginDir.count(); i++)
304
  {
305
    QString packageName = homePluginDir[i];
306
    if(!pluginList.contains(packageName))
307
        pluginList.append(packageName); 
308

  
309
  }
310

  
311
  return pluginList;
312
}
313

  
287 314
QString QgsPythonUtils::getPluginMetadata(QString pluginName, QString function)
288 315
{
289 316
  QString command = pluginName + "." + function + "()";
app/qgisapp.cpp (working copy)
1563 1563
  if (QgsPythonUtils::isEnabled())
1564 1564
  {
1565 1565
  
1566
    // check for python plugins
1567
    QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
1568
                  QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
1569
  
1570
    for (uint i = 0; i < pluginDir.count(); i++)
1566
    // check for python plugins system-wide
1567
    QStringList pluginList = QgsPythonUtils::pluginList();
1568

  
1569
    for (uint i = 0; i < pluginList.size(); i++)
1571 1570
    {
1572
      QString packageName = pluginDir[i];
1573
      
1571
      QString packageName = pluginList[i];
1572
   
1574 1573
      // import plugin's package
1575 1574
      if (!QgsPythonUtils::loadPlugin(packageName))
1576 1575
        continue;
......
1596 1595
        loadPythonPlugin(packageName, pluginName);
1597 1596
      }
1598 1597
    }
1599
  
1600 1598
  }
1601 1599
#endif
1602 1600
}