QGIS/python/plugins/processing/algs/saga/SagaDescriptionCreator.py

101 lines
3.4 KiB
Python
Raw Normal View History

2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
SagaDescriptionCreator.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from __future__ import print_function
2016-09-21 18:24:26 +02:00
from builtins import str
from builtins import object
2012-10-05 23:28:47 +02:00
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-05 23:28:47 +02:00
__revision__ = '$Format:%H$'
2012-09-15 18:25:25 +03:00
import subprocess
import os
2016-09-21 18:24:26 +02:00
class SagaDescriptionCreator(object):
2012-09-15 18:25:25 +03:00
def createLibraryFiles(self):
with open('c:\\saga\\sagalibs.txt') as f:
for lib in f:
lib = lib.strip('\n')
command = ['c:\\saga\\saga_cmd.exe', lib]
with open('c:\\saga\\desc\\' + lib + '.sagalib', 'w') as f2:
subprocess.Popen(
command,
shell=True,
stdout=f2,
stdin=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
2012-09-15 18:25:25 +03:00
def createLibraryMap(self):
self.map = {}
for libFile in os.listdir('c:\\saga\\desc'):
if libFile.endswith('sagalib'):
# fix_print_with_import
print(libFile)
2012-09-15 18:25:25 +03:00
algs = []
with open(os.path.join('c:\\saga\\desc', libFile)) as f:
for line in f:
line = line.strip('\n').strip(' ')
digit = line.split('\t')[0]
# fix_print_with_import
print(digit)
if digit.isdigit():
algs.append(digit)
self.map[libFile[:-8]] = algs
2012-09-15 18:25:25 +03:00
# fix_print_with_import
2016-09-21 18:24:26 +02:00
print(str(self.map))
2012-09-15 18:25:25 +03:00
def createDescriptionFiles(self):
2016-09-21 18:24:26 +02:00
for lib in list(self.map.keys()):
2012-09-15 18:25:25 +03:00
algs = self.map[lib]
for alg in algs:
command = ['c:\\saga\\saga_cmd.exe', lib, alg]
with open('c:\\saga\\desc\\' + lib + '_' + alg + '.txt', 'w') as f:
# fix_print_with_import
print(str(command))
subprocess.Popen(
command,
shell=True,
stdout=f,
stdin=subprocess.DEVNULL,
stderr=f,
universal_newlines=True,
)
2012-09-15 18:25:25 +03:00
def create(self):
self.createLibraryMap()
self.createDescriptionFiles()
2012-09-15 18:25:25 +03:00
def main():
SagaDescriptionCreator().create()
if __name__ == '__main__':
main()