Beispiel #1
0
    def __init__(self, fcgi_bin):
        msg = 'FCGI binary not found at:\n{0}'.format(fcgi_bin)
        assert os.path.exists(fcgi_bin), msg

        msg = "FCGI binary not 'qgis_mapserv.fcgi':"
        assert fcgi_bin.endswith('qgis_mapserv.fcgi'), msg

        # hardcoded url, makes all this automated
        self._ip = '127.0.0.1'
        self._port = '8448'
        self._web_url = 'http://{0}:{1}'.format(self._ip, self._port)
        self._fcgibin_path = '/cgi-bin/qgis_mapserv.fcgi'
        self._fcgi_url = '{0}{1}'.format(self._web_url, self._fcgibin_path)
        self._conf_dir = unitTestDataPath('qgis_local_server')

        self._fcgiserv_process = self._webserv_process = None
        self._fcgiserv_bin = fcgi_bin
        self._fcgiserv_path = self._webserv_path = ''
        self._fcgiserv_kind = self._webserv_kind = ''
        self._temp_dir = ''
        self._web_dir = ''

        servers = [('spawn-fcgi', 'lighttpd')
                   #('fcgiwrap', 'nginx'),
                   #('uwsgi', 'nginx'),
                   ]

        chkd = ''
        for fcgi, web in servers:
            fcgi_path = getExecutablePath(fcgi)
            web_path = getExecutablePath(web)
            if fcgi_path and web_path:
                self._fcgiserv_path = fcgi_path
                self._webserv_path = web_path
                self._fcgiserv_kind = fcgi
                self._webserv_kind = web
                break
            else:
                chkd += "Find '{0}': {1}\n".format(fcgi, fcgi_path)
                chkd += "Find '{0}': {1}\n\n".format(web, web_path)

        if not (self._fcgiserv_path and self._webserv_path):
            raise ServerProcessError(
                'Could not locate server binaries', chkd,
                'Make sure one of the sets of servers is available on PATH')

        self._temp_dir = tempfile.mkdtemp()
        self._setup_temp_dir()

        # initialize the servers
        self._fcgiserv_process = FcgiServerProcess(
            self._fcgiserv_kind, self._fcgiserv_path, self._fcgibin_path,
            self._conf_dir, self._temp_dir)
        self._webserv_process = WebServerProcess(
            self._webserv_kind, self._webserv_path, self._conf_dir,
            self._temp_dir)

        # stop any leftover processes, if possible
        self.stop_processes()
    def _pdf_to_png(self, pdf_file_path, rendered_file_path, page, dpi=96):

        # PDF-to-image utility
        # look for Poppler w/ Cairo, then muPDF
        # * Poppler w/ Cairo renders correctly
        # * Poppler w/o Cairo does not always correctly render vectors in PDF to image
        # * muPDF renders correctly, but slightly shifts colors
        for util in [
            'pdftocairo',
            # 'mudraw',
        ]:
            PDFUTIL = getExecutablePath(util)
            if PDFUTIL:
                break

        # noinspection PyUnboundLocalVariable
        if not PDFUTIL:
            assert False, ('PDF-to-image utility not found on PATH: '
                           'install Poppler (with Cairo)')

        if PDFUTIL.strip().endswith('pdftocairo'):
            filebase = os.path.join(
                os.path.dirname(rendered_file_path),
                os.path.splitext(os.path.basename(rendered_file_path))[0]
            )
            call = [
                PDFUTIL, '-png', '-singlefile', '-r', str(dpi),
                '-x', '0', '-y', '0', '-f', str(page), '-l', str(page),
                pdf_file_path, filebase
            ]
        elif PDFUTIL.strip().endswith('mudraw'):
            call = [
                PDFUTIL, '-c', 'rgba',
                '-r', str(dpi), '-f', str(page), '-l', str(page),
                # '-b', '8',
                '-o', rendered_file_path, pdf_file_path
            ]
        else:
            return False, ''

        print("exportToPdf call: {0}".format(' '.join(call)))
        try:
            subprocess.check_call(call)
        except subprocess.CalledProcessError as e:
            assert False, ("exportToPdf failed!\n"
                           "cmd: {0}\n"
                           "returncode: {1}\n"
                           "message: {2}".format(e.cmd, e.returncode, e.message))
Beispiel #3
0
from test_qgspallabeling_tests import (
    TestPointBase,
    TestLineBase,
    suiteTests
)

# PDF-to-image utility
# look for Poppler w/ Cairo, then muPDF
# * Poppler w/ Cairo renders correctly
# * Poppler w/o Cairo does not always correctly render vectors in PDF to image
# * muPDF renders correctly, but sightly shifts colors
for util in [
    'pdftocairo',
    # 'mudraw',
]:
    PDFUTIL = getExecutablePath(util)
    if PDFUTIL:
        break

# noinspection PyUnboundLocalVariable
if not PDFUTIL:
    raise Exception('PDF-to-image utility not found on PATH: '
                    'install Poppler (with Cairo)')


# output kind enum
# noinspection PyClassHasNoInit
class OutputKind():
    Img, Svg, Pdf = list(range(3))

from utilities import (getTempfilePath, getExecutablePath, mapSettingsString)

from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (TestPointBase, TestLineBase, suiteTests)

# PDF-to-image utility
# look for Poppler w/ Cairo, then muPDF
# * Poppler w/ Cairo renders correctly
# * Poppler w/o Cairo does not always correctly render vectors in PDF to image
# * muPDF renders correctly, but sightly shifts colors
for util in [
        'pdftocairo',
        # 'mudraw',
]:
    PDFUTIL = getExecutablePath(util)
    if PDFUTIL:
        break

# noinspection PyUnboundLocalVariable
if not PDFUTIL:
    raise Exception('PDF-to-image utility not found on PATH: '
                    'install Poppler (with Cairo)')


# output kind enum
# noinspection PyClassHasNoInit
class OutputKind():
    Img, Svg, Pdf = list(range(3))

Beispiel #5
0
    def __init__(self, fcgi_bin):
        msg = 'FCGI binary not found at:\n{0}'.format(fcgi_bin)
        assert os.path.exists(fcgi_bin), msg

        msg = "FCGI binary not 'qgis_mapserv.fcgi':"
        assert fcgi_bin.endswith('qgis_mapserv.fcgi'), msg

        # hardcoded url, makes all this automated
        self._ip = '127.0.0.1'
        self._port = '8448'
        self._web_url = 'http://{0}:{1}'.format(self._ip, self._port)
        self._fcgibin_path = '/cgi-bin/qgis_mapserv.fcgi'
        self._fcgi_url = '{0}{1}'.format(self._web_url, self._fcgibin_path)
        self._conf_dir = unitTestDataPath('qgis_local_server')

        self._fcgiserv_process = self._webserv_process = None
        self._fcgiserv_bin = fcgi_bin
        self._fcgiserv_path = self._webserv_path = ''
        self._fcgiserv_kind = self._webserv_kind = ''
        self._temp_dir = ''
        self._web_dir = ''

        servers = [
            ('spawn-fcgi', 'lighttpd')
            # ('fcgiwrap', 'nginx'),
            # ('uwsgi', 'nginx'),
        ]

        chkd = ''
        for fcgi, web in servers:
            fcgi_path = getExecutablePath(fcgi)
            web_path = getExecutablePath(web)
            if fcgi_path and web_path:
                self._fcgiserv_path = fcgi_path
                self._webserv_path = web_path
                self._fcgiserv_kind = fcgi
                self._webserv_kind = web
                break
            else:
                chkd += "Find '{0}': {1}\n".format(fcgi, fcgi_path)
                chkd += "Find '{0}': {1}\n\n".format(web, web_path)

        if not (self._fcgiserv_path and self._webserv_path):
            raise ServerProcessError(
                'Could not locate server binaries',
                chkd,
                'Make sure one of the sets of servers is available on PATH'
            )

        self._temp_dir = tempfile.mkdtemp()
        self._setup_temp_dir()

        # initialize the servers
        self._fcgiserv_process = FcgiServerProcess(
            self._fcgiserv_kind, self._fcgiserv_path,
            self._fcgibin_path, self._conf_dir, self._temp_dir)
        self._webserv_process = WebServerProcess(
            self._webserv_kind, self._webserv_path,
            self._conf_dir, self._temp_dir)

        # stop any leftover processes, if possible
        self.stop_processes()