checkdep.py :  » Chart-Report » Matplotlib » matplotlib-0.99.1.1 » lib » matplotlib » config » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Matplotlib 
Matplotlib » matplotlib 0.99.1.1 » lib » matplotlib » config » checkdep.py
import os
import re
import sys
import warnings
import distutils.version as version

tex_req = '3.1415'
gs_req = '7.07'
gs_sugg = '8.60'
dvipng_req = '1.5'
pdftops_req = '3.0'

def dvipng():
    try:
        stdin, stdout = os.popen4('dvipng -version')
        return stdout.readlines()[1].split()[-1]
    except (IndexError, ValueError):
        return None

def ghostscript():
    try:
        if sys.platform == 'win32':
            command = 'gswin32c --version'
        else:
            command = 'gs --version'
        stdin, stdout = os.popen4(command)
        return stdout.read()[:-1]
    except (IndexError, ValueError):
        return None

def tex():
    try:
        stdin, stdout = os.popen4('tex -version')
        line = stdout.readlines()[0]
        pattern = '3\.1\d+'
        match = re.search(pattern, line)
        return match.group(0)
    except (IndexError, ValueError, AttributeError):
        return None

def pdftops():
    try:
        stdin, stdout = os.popen4('pdftops -v')
        for line in stdout.readlines():
            if 'version' in line:
                return line.split()[-1]
    except (IndexError, ValueError):
        return None

def compare_versions(a, b):
    "return True if a is greater than or equal to b"
    if a:
        a = version.LooseVersion(a)
        b = version.LooseVersion(b)
        if a>=b: return True
        else: return False
    else: return False

def ps_distiller(s):
    if not s:
        return False

    flag = True
    gs_v = ghostscript()
    if compare_versions(gs_v, gs_sugg): pass
    elif compare_versions(gs_v, gs_req):
        verbose.report(('ghostscript-%s found. ghostscript-%s or later '
                        'is recommended to use the ps.usedistiller option.') %\
                        (gs_v, gs_sugg))
    else:
        flag = False
        warnings.warn(('matplotlibrc ps.usedistiller option can not be used '
                       'unless ghostscript-%s or later is installed on your '
                       'system.') % gs_req)

    if s == 'xpdf':
        pdftops_v = pdftops()
        if compare_versions(pdftops_v, pdftops_req): pass
        else:
            flag = False
            warnings.warn(('matplotlibrc ps.usedistiller can not be set to '
                           'xpdf unless pdftops-%s or later is installed on '
                           'your system.') % pdftops_req)

    if flag:
        return s
    else:
        return False

def usetex(s):
    if not s:
        return False

    flag = True

    tex_v = tex()
    if compare_versions(tex_v, tex_req): pass
    else:
        flag = False
        warnings.warn(('matplotlibrc text.usetex option can not be used '
                       'unless TeX-%s or later is '
                       'installed on your system') % tex_req)

    dvipng_v = dvipng()
    if compare_versions(dvipng_v, dvipng_req): pass
    else:
        flag = False
        warnings.warn( 'matplotlibrc text.usetex can not be used with *Agg '
                       'backend unless dvipng-1.5 or later is '
                       'installed on your system')

    gs_v = ghostscript()
    if compare_versions(gs_v, gs_sugg): pass
    elif compare_versions(gs_v, gs_req):
        verbose.report(('ghostscript-%s found. ghostscript-%s or later is '
                        'recommended for use with the text.usetex '
                        'option.') % (gs_v, gs_sugg))
    else:
        flag = False
        warnings.warn(('matplotlibrc text.usetex can not be used '
                       'unless ghostscript-%s or later is '
                       'installed on your system') % gs_req)

    return flag
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.