diff options
Diffstat (limited to 'webmap-import')
-rwxr-xr-x | webmap-import | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/webmap-import b/webmap-import index 37826cf..bfee9dc 100755 --- a/webmap-import +++ b/webmap-import @@ -18,7 +18,9 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. #---------------------------------------------------------------------- +from os import O_WRONLY, O_CREAT, O_TRUNC, O_CLOEXEC import os +from fcntl import flock, LOCK_EX import logging import argparse import tempfile @@ -1193,6 +1195,8 @@ if __name__ == '__main__': help=f'cache directory (default: {os.curdir})') parser.add_argument('--debug', action='count', default=0, help=argparse.SUPPRESS) + parser.add_argument('--lockfile', default=None, + help=f'obtain an exclusive lock before starting unpacking and importing') parser.add_argument('groupname', nargs='*', help='group layer name(s) to process') args = parser.parse_args() @@ -1244,6 +1248,12 @@ if __name__ == '__main__': srs = getSRS(common.config.get('SRS', None)) extent = getExtent(common.config.get('extent', None), srs=srs) + if args.lockfile is not None: + # obtain an exclusive lock and don't release it until exiting the program + lock_fd = os.open(args.lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, mode=0o644) + logging.debug('flock("%s", LOCK_EX)', args.lockfile) + flock(lock_fd, LOCK_EX) + cachedir = Path(args.cachedir) if args.cachedir is not None else None rv = 0 for layername, layerdef in layers.items(): |