Skip to content

Commit

Permalink
Enable QGIS_PLUGINPATH for the folder where plugins are stored
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jun 16, 2022
1 parent 192a201 commit 2b748c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* If the environment variable `QGIS_PLUGINPATH` is set, this directory is used instead of the current directory
* Fix display issue when the error was printed many times in the terminal

## 1.1.2 - 2022-06-13

* Fix Python exception if the "init" or "update" commands were not executed
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ python3 -m pip install qgis-plugin-manager

## Utilisation

**Either** you need to go in the directory where you are storing plugins, **or** you can use the environment variable `QGIS_PLUGINPATH`.
You can read the [documentation](https://docs.qgis.org/3.22/en/docs/server_manual/config.html#environment-variables)
on QGIS Server about this variable.

```bash
cd /path/where/you/have/plugins
# usually
cd /usr/lib/qgis/plugins
```
It depends where you want to store QGIS plugins. On a server, you can use the variable `QGIS_PLUGINPATH`
according to the [documentation](https://docs.qgis.org/3.22/en/docs/server_manual/config.html#environment-variables)
if you don't want the default folder.

```bash
$ qgis-plugin-manager --help
Expand Down
21 changes: 14 additions & 7 deletions qgis_plugin_manager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__email__ = '[email protected]'

import argparse
import os

from pathlib import Path

Expand Down Expand Up @@ -73,21 +74,27 @@ def main(): # noqa: C901

exit_val = 0

# Default to the current directory
plugin_path = Path('.')
if os.environ.get('QGIS_PLUGINPATH'):
# Except if the QGIS_PLUGINPATH is set
plugin_path = Path(os.environ.get('QGIS_PLUGINPATH'))

if args.command == "update":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
remote.update()
elif args.command in ("list", "init", "upgrade"):
qgis = qgis_server_version()
if qgis:
print(f"QGIS server version : {qgis}")
plugins = LocalDirectory(Path('.'), qgis_version=qgis)
plugins = LocalDirectory(plugin_path, qgis_version=qgis)

if args.command == "list":
plugins.print_table()
elif args.command == "init":
plugins.init()
elif args.command == "upgrade":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
folders = plugins.plugin_list()
for folder in folders:
plugin_object = plugins.plugin_info(folder)
Expand All @@ -97,25 +104,25 @@ def main(): # noqa: C901
print(f"{Level.Warning}Tip{Level.End} : Do not forget to restart QGIS Server to reload plugins 😎")

elif args.command == "remote":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
remote.print_list()

elif args.command == "cache":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
latest = remote.latest(args.plugin_name)
if latest is None:
print(f"{Level.Warning}Plugin not found{Level.End}")
else:
print(f"Plugin {args.plugin_name} : {latest} available")

elif args.command == "search":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
results = remote.search(args.plugin_name)
for result in results:
print(result)

elif args.command == "install":
remote = Remote(Path('.'))
remote = Remote(plugin_path)
parameter = args.plugin_name.split('==')
result = remote.install(*parameter)
if not result:
Expand Down
25 changes: 15 additions & 10 deletions qgis_plugin_manager/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ def __init__(self, folder: Path):
self.folder = folder
self.list = None
self.list_plugins = None
self.setting_error = False

def remote_is_ready(self) -> bool:
""" Return if the remote is ready to be parsed. """
source_list = Path(self.folder / 'sources.list')
if not source_list.exists():
print(f"{Level.Critical}The sources.list file does not exist{Level.End}")
print("Use the 'init' command to create the file")
return False
if not self.setting_error:
print(f"{Level.Critical}The sources.list file does not exist{Level.End}")
print("Use the 'init' command to create the file")
self.setting_error = True
return False

if self.list is None:
self.remote_list()
Expand All @@ -42,13 +45,15 @@ def remote_is_ready(self) -> bool:
filename = self.server_cache_filename(cache, server)

if not filename.exists():
print(
f"{Level.Critical}"
f"The 'update' command has not been done before. "
f"The repository {server} has not been fetched before."
f"{Level.End}"
)
return False
if not self.setting_error:
print(
f"{Level.Critical}"
f"The 'update' command has not been done before. "
f"The repository {server} has not been fetched before."
f"{Level.End}"
)
self.setting_error = True
return False

return True

Expand Down

0 comments on commit 2b748c8

Please sign in to comment.