Exemple #1
0
def _processPackageDir(p,dn,P,allowCompiled=True):
	if _ofile: print('searching package', p, 'dn=',dn, file=_ofile)
	from reportlab.lib.utils import rl_glob, rl_isfile, rl_isdir, isCompactDistro
	if isCompactDistro():
		ext = '.pyc'
		init = '__init__'+ext
		FN = [normpath(x) for x in rl_glob(path_join(dn,'*'))]
		D = []
		dn = normpath(dn)
		for x in FN:
			x = path_dirname(x)
			if x not in D and rl_isdir(x) and path_dirname(x)==dn and rl_isfile(path_join(x,init)): D.append(x)
		F = [x for x in FN if x.endswith(ext) and path_dirname(x)==dn and not path_basename(x).startswith('__init__.')]
	else:
		ext = '.py'
		init = '__init__'+ext
		FN = [path_join(dn,x) for x in os.listdir(dn)]
		D = [x for x in FN if path_isdir(x) and isPyFile(path_join(x,init))]
		F = [x for x in FN if (x.endswith(ext) or (allowCompiled and (x.endswith(ext+'c') or x.endswith(ext+'o')))) and not path_basename(x).startswith('__init__.')]
	for f in F:
		mn = path_splitext(path_basename(f))[0]
		if p: mn = p+'.'+mn
		if mn not in P:
			if _ofile: print('appending 1',mn, file=_ofile)
			P.append(mn)
	for f in D:
		mn = p+('.'+path_basename(f))
		if mn not in P:
			if _ofile: print('appending 2',mn, file=_ofile)
			P.append(mn)
def _startUp():
    '''This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default'''
    import os, sys
    global sys_version, _unset_
    sys_version = sys.version.split()[0]  #strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED == {}:
        _unset_ = getattr(sys, '_rl_config__unset_', None)
        if _unset_ is None:

            class _unset_:
                pass

            sys._rl_config__unset_ = _unset_ = _unset_()
        global __all__
        A = list(__all__)
        for k, v in _DEFAULTS.items():
            _SAVED[k] = globals()[k] = v
            if k not in __all__:
                A.append(k)
        __all__ = tuple(A)

    #places to search for Type 1 Font files
    import reportlab
    D = {
        'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
        'CWD': os.getcwd(),
        'disk': os.getcwd().split(':')[0],
        'sys_version': sys_version,
        'XDG_DATA_HOME': os.environ.get('XDG_DATA_HOME', '~/.local/share'),
    }

    for k in _SAVED:
        if k.endswith('SearchPath'):
            P = []
            for p in _SAVED[k]:
                d = (p % D).replace('/', os.sep)
                if '~' in d:
                    try:
                        d = os.path.expanduser(
                            d
                        )  #appengine fails with KeyError/ImportError (dev/live)
                    except (KeyError, ImportError):
                        continue
                if rl_isdir(d): P.append(d)
            _setOpt(k, os.pathsep.join(P), lambda x: x.split(os.pathsep))
            globals()[k] = list(filter(rl_isdir, globals()[k]))
        else:
            v = _SAVED[k]
            if isinstance(v, (int, float)): conv = type(v)
            elif k == 'defaultPageSize':
                conv = lambda v, M=pagesizes: getattr(M, v)
            else:
                conv = None
            _setOpt(k, v, conv)
def bruteForceSearchForFile(fn,searchPath=None):
    if searchPath is None: from reportlab.rl_config import T1SearchPath as searchPath
    if rl_isfile(fn): return fn
    bfn = os.path.basename(fn)
    for dirname in searchPath:
        if not rl_isdir(dirname): continue
        tfn = os.path.join(dirname,bfn)
        if rl_isfile(tfn): return tfn
    return fn
Exemple #4
0
 def addDirectory(self, dirName, recur=None):
     #aesthetics - if there are 2 copies of a font, should the first or last
     #be picked up?  might need reversing
     if rl_isdir(dirName):
         self._dirs.add(dirName)
         if recur if recur is not None else self._recur:
             for r, D, F in os.walk(dirName):
                 for d in D:
                     self._dirs.add(os.path.join(r, d))
Exemple #5
0
 def addDirectory(self, dirName, recur=None):
     #aesthetics - if there are 2 copies of a font, should the first or last
     #be picked up?  might need reversing
     if rl_isdir(dirName):
         self._dirs.add(dirName)
         if recur if recur is not None else self._recur:
             for r,D,F in os.walk(dirName):
                 for d in D:
                     self._dirs.add(os.path.join(r,d))
Exemple #6
0
def _startUp():
    '''This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default'''
    import os, sys
    global sys_version, _unset_
    sys_version = sys.version.split()[0]        #strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED=={}:
        _unset_ = getattr(sys,'_rl_config__unset_',None)
        if _unset_ is None:
            class _unset_: pass
            sys._rl_config__unset_ = _unset_ = _unset_()
        global __all__
        A = list(__all__)
        for k,v in _DEFAULTS.items():
            _SAVED[k] = globals()[k] = v
            if k not in __all__:
                A.append(k)
        __all__ = tuple(A)

    #places to search for Type 1 Font files
    import reportlab
    D = {'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
        'CWD': os.getcwd(),
        'disk': os.getcwd().split(':')[0],
        'sys_version': sys_version,
        'XDG_DATA_HOME': os.environ.get('XDG_DATA_HOME','~/.local/share'),
        }

    for k in _SAVED:
        if k.endswith('SearchPath'):
            P=[]
            for p in _SAVED[k]:
                d = (p % D).replace('/',os.sep)
                if '~' in d:
                    try:
                        d = os.path.expanduser(d)   #appengine fails with ImportError
                    except ImportError:
                        continue
                if rl_isdir(d): P.append(d)
            _setOpt(k,os.pathsep.join(P),lambda x:x.split(os.pathsep))
            globals()[k] = list(filter(rl_isdir,globals()[k]))
        else:
            v = _SAVED[k]
            if isinstance(v,(int,float)): conv = type(v)
            elif k=='defaultPageSize': conv = lambda v,M=pagesizes: getattr(M,v)
            else: conv = None
            _setOpt(k,v,conv)
def bruteForceSearchForAFM(faceName):
    """Looks in all AFM files on path for face with given name.

    Returns AFM file name or None.  Ouch!"""
    from reportlab.rl_config import T1SearchPath

    for dirname in T1SearchPath:
        if not rl_isdir(dirname): continue
        possibles = rl_glob(dirname + os.sep + '*.[aA][fF][mM]')
        for possible in possibles:
            (topDict, glyphDict) = parseAFMFile(possible)
            if topDict['FontName'] == faceName:
                return possible
    return None
Exemple #8
0
def bruteForceSearchForAFM(faceName):
    """Looks in all AFM files on path for face with given name.

    Returns AFM file name or None.  Ouch!"""
    from reportlab.rl_config import T1SearchPath

    for dirname in T1SearchPath:
        if not rl_isdir(dirname): continue
        possibles = rl_glob(dirname + os.sep + '*.[aA][fF][mM]')
        for possible in possibles:
            (topDict, glyphDict) = parseAFMFile(possible)
            if topDict['FontName'] == faceName:
                return possible
    return None
 def __init__(self, directory, pattern='*'):
     self.index = 0
     self.pattern = pattern
     directory.replace('/',os.sep)
     if os.path.isdir(directory):
         self.stack = [directory]
         self.files = []
     else:
         if not isCompactDistro() or not __loader__ or not rl_isdir(directory):
             raise ValueError('"%s" is not a directory' % directory)
         self.directory = directory[len(__loader__.archive)+len(os.sep):]
         pfx = self.directory+os.sep
         n = len(pfx)
         self.files = list(map(lambda x, n=n: x[n:],list(filter(lambda x,pfx=pfx: x.startswith(pfx),list(__loader__._files.keys())))))
         self.stack = []
Exemple #10
0
 def __init__(self, directory, pattern='*'):
     self.index = 0
     self.pattern = pattern
     directory.replace('/',os.sep)
     if os.path.isdir(directory):
         self.stack = [directory]
         self.files = []
     else:
         from reportlab.lib.utils import isCompactDistro, __loader__, rl_isdir
         if not isCompactDistro() or not __loader__ or not rl_isdir(directory):
             raise ValueError('"%s" is not a directory' % directory)
         self.directory = directory[len(__loader__.archive)+len(os.sep):]
         pfx = self.directory+os.sep
         n = len(pfx)
         self.files = map(lambda x, n=n: x[n:],filter(lambda x,pfx=pfx: x.startswith(pfx),__loader__._files.keys()))
         self.stack = []
Exemple #11
0
def _startUp():
    '''This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default'''
    V = ('T1SearchPath','CMapSearchPath', 'TTFSearchPath',
                'shapeChecking', 'defaultEncoding',
                'pageCompression', 'defaultPageSize', 'defaultImageCaching',
                'ZLIB_WARNINGS', 'warnOnMissingFontGlyphs', 'verbose', 'emptyTableAction',
                'invariant','eps_preview_transparent',
                )
    import os, sys, string
    global sys_version, _unset_
    sys_version = string.split(sys.version)[0]      #strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED=={}:
        _unset_ = getattr(sys,'_rl_config__unset_',None)
        if _unset_ is None:
            class _unset_: pass
            sys._rl_config__unset_ = _unset_ = _unset_()
        for k in V:
            _SAVED[k] = globals()[k]

    #places to search for Type 1 Font files
    import reportlab
    D = {'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
        'HOME': os.environ.get('HOME',os.getcwd()),
        'disk': string.split(os.getcwd(), ':')[0],
        'sys_version': sys_version,
        }

    for name in ('T1SearchPath','TTFSearchPath','CMapSearchPath'):
        P=[]
        for p in _SAVED[name]:
            d = string.replace(p % D,'/',os.sep)
            if rl_isdir(d): P.append(d)
        _setOpt(name,P)

    for k in V[3:]:
        v = _SAVED[k]
        if type(v)==type(1): conv = int
        elif k=='defaultPageSize': conv = lambda v,M=pagesizes: getattr(M,v)
        else: conv = None
        _setOpt(k,v,conv)
def bruteForceSearchForAFM(faceName):
    """Looks in all AFM files on path for face with given name.

    Returns AFM file name or None.  Ouch!"""
    from reportlab.rl_config import T1SearchPath

    for dirname in T1SearchPath:
        if not rl_isdir(dirname): continue
        possibles = rl_glob(dirname + os.sep + '*.[aA][fF][mM]')
        for possible in possibles:
            try:
                topDict, glyphDict = parseAFMFile(possible)
                if topDict['FontName'] == faceName:
                    return possible
            except:
                t,v,b=sys.exc_info()
                v.args = (' '.join(map(str,v.args))+', while looking for faceName=%r' % faceName,)
                raise 
    def __init__(self, directory, pattern="*"):
        self.index = 0
        self.pattern = pattern
        directory.replace("/", os.sep)
        if os.path.isdir(directory):
            self.stack = [directory]
            self.files = []
        else:
            from reportlab.lib.utils import isCompactDistro, __loader__, rl_isdir

            if not isCompactDistro() or not __loader__ or not rl_isdir(directory):
                raise ValueError('"%s" is not a directory' % directory)
            self.directory = directory[len(__loader__.archive) + len(os.sep) :]
            pfx = self.directory + os.sep
            n = len(pfx)
            self.files = map(
                lambda x, n=n: x[n:], filter(lambda x, pfx=pfx: x.startswith(pfx), __loader__._files.keys())
            )
            self.stack = []
def _processPackageDir(p, dn, P, allowCompiled=True):
    if _ofile: print('searching package', p, 'dn=', dn, file=_ofile)
    from reportlab.lib.utils import rl_glob, rl_isfile, rl_isdir, isCompactDistro
    if isCompactDistro():
        ext = '.pyc'
        init = '__init__' + ext
        FN = [normpath(x) for x in rl_glob(path_join(dn, '*'))]
        D = []
        dn = normpath(dn)
        for x in FN:
            x = path_dirname(x)
            if x not in D and rl_isdir(x) and path_dirname(
                    x) == dn and rl_isfile(path_join(x, init)):
                D.append(x)
        F = [
            x for x in FN if x.endswith(ext) and path_dirname(x) == dn
            and not path_basename(x).startswith('__init__.')
        ]
    else:
        ext = '.py'
        init = '__init__' + ext
        FN = [path_join(dn, x) for x in os.listdir(dn)]
        D = [x for x in FN if path_isdir(x) and isPyFile(path_join(x, init))]
        F = [
            x for x in FN if (x.endswith(ext) or (allowCompiled and (
                x.endswith(ext + 'c') or x.endswith(ext + 'o'))))
            and not path_basename(x).startswith('__init__.')
        ]
    for f in F:
        mn = path_splitext(path_basename(f))[0]
        if p: mn = p + '.' + mn
        if mn not in P:
            if _ofile: print('appending 1', mn, file=_ofile)
            P.append(mn)
    for f in D:
        mn = p + ('.' + path_basename(f))
        if mn not in P:
            if _ofile: print('appending 2', mn, file=_ofile)
            P.append(mn)
Exemple #15
0
 def addDirectory(self, dirName):
     #aesthetics - if there are 2 copies of a font, should the first or last
     #be picked up?  might need reversing
     if rl_isdir(dirName):
         self._dirs.add(dirName)
Exemple #16
0
 def addDirectory(self, dirName):
     #aesthetics - if there are 2 copies of a font, should the first or last
     #be picked up?  might need reversing
     if rl_isdir(dirName):
         self._dirs.add(dirName)
Exemple #17
0
def _startUp():
    '''This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default'''
    V='''T1SearchPath
CMapSearchPath
TTFSearchPath
allowTableBoundsErrors
shapeChecking
defaultEncoding 
defaultGraphicsFontName
pageCompression 
defaultPageSize 
defaultImageCaching 
ZLIB_WARNINGS 
warnOnMissingFontGlyphs 
verbose 
showBoundary 
emptyTableAction
invariant
eps_preview_transparent
eps_preview
eps_ttf_embed
eps_ttf_embed_uid
overlapAttachedSpace
longTableOptimize 
autoConvertEncoding  
_FUZZ
wrapA85
fsEncodings
odbc_driver
platypus_link_underline
canvas_basefontname
allowShortTableRows
imageReaderFlags
paraFontSizeHeightOffset
canvas_baseColor
ttfAsciiReadable'''.split()
    import os, sys
    global sys_version, _unset_
    sys_version = sys.version.split()[0]        #strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED=={}:
        _unset_ = getattr(sys,'_rl_config__unset_',None)
        if _unset_ is None:
            class _unset_: pass
            sys._rl_config__unset_ = _unset_ = _unset_()
        for k in V:
            _SAVED[k] = globals()[k]

    #places to search for Type 1 Font files
    import reportlab
    D = {'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
        'HOME': os.environ.get('HOME',os.getcwd()),
        'disk': os.getcwd().split(':')[0],
        'sys_version': sys_version,
        }

    for name in ('T1SearchPath','TTFSearchPath','CMapSearchPath'):
        P=[]
        for p in _SAVED[name]:
            d = (p % D).replace('/',os.sep)
            if rl_isdir(d): P.append(d)
        _setOpt(name,P)

    for k in V[3:]:
        v = _SAVED[k]
        if isinstance(v,(int,float)): conv = type(v)
        elif k=='defaultPageSize': conv = lambda v,M=pagesizes: getattr(M,v)
        else: conv = None
        _setOpt(k,v,conv)
Exemple #18
0
def _startUp():
    """This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default"""
    import os, sys

    global sys_version, _unset_
    sys_version = sys.version.split()[0]  # strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED == {}:
        _unset_ = getattr(sys, "_rl_config__unset_", None)
        if _unset_ is None:

            class _unset_:
                pass

            sys._rl_config__unset_ = _unset_ = _unset_()
        global __all__
        A = list(__all__)
        for k, v in _DEFAULTS.items():
            _SAVED[k] = globals()[k] = v
            if k not in __all__:
                A.append(k)
        __all__ = tuple(A)

    # places to search for Type 1 Font files
    import reportlab

    D = {
        "REPORTLAB_DIR": os.path.abspath(os.path.dirname(reportlab.__file__)),
        "CWD": os.getcwd(),
        "disk": os.getcwd().split(":")[0],
        "sys_version": sys_version,
        "XDG_DATA_HOME": os.environ.get("XDG_DATA_HOME", "~/.local/share"),
    }

    for k in _SAVED:
        if k.endswith("SearchPath"):
            P = []
            for p in _SAVED[k]:
                d = (p % D).replace("/", os.sep)
                if "~" in d:
                    try:
                        d = os.path.expanduser(d)  # appengine fails with KeyError/ImportError (dev/live)
                    except (KeyError, ImportError):
                        continue
                if rl_isdir(d):
                    P.append(d)
            _setOpt(k, os.pathsep.join(P), lambda x: x.split(os.pathsep))
            globals()[k] = list(filter(rl_isdir, globals()[k]))
        else:
            v = _SAVED[k]
            if isinstance(v, (int, float)):
                conv = type(v)
            elif k == "defaultPageSize":
                conv = lambda v, M=pagesizes: getattr(M, v)
            else:
                conv = None
            _setOpt(k, v, conv)
def _startUp():
    """This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default"""
    V = (
        "T1SearchPath",
        "CMapSearchPath",
        "TTFSearchPath",
        "shapeChecking",
        "defaultEncoding",
        "pageCompression",
        "defaultPageSize",
        "defaultImageCaching",
        "ZLIB_WARNINGS",
        "warnOnMissingFontGlyphs",
        "verbose",
        "emptyTableAction",
        "invariant",
        "eps_preview_transparent",
    )
    import os, sys, string

    global sys_version, _unset_
    sys_version = string.split(sys.version)[0]  # strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED == {}:
        _unset_ = getattr(sys, "_rl_config__unset_", None)
        if _unset_ is None:

            class _unset_:
                pass

            sys._rl_config__unset_ = _unset_ = _unset_()
        for k in V:
            _SAVED[k] = globals()[k]

    # places to search for Type 1 Font files
    import reportlab

    D = {
        "REPORTLAB_DIR": os.path.abspath(os.path.dirname(reportlab.__file__)),
        "HOME": os.environ.get("HOME", os.getcwd()),
        "disk": string.split(os.getcwd(), ":")[0],
        "sys_version": sys_version,
    }

    for name in ("T1SearchPath", "TTFSearchPath", "CMapSearchPath"):
        P = []
        for p in _SAVED[name]:
            d = string.replace(p % D, "/", os.sep)
            if rl_isdir(d):
                P.append(d)
        _setOpt(name, P)

    for k in V[3:]:
        v = _SAVED[k]
        if type(v) == type(1):
            conv = int
        elif k == "defaultPageSize":
            conv = lambda v, M=pagesizes: getattr(M, v)
        else:
            conv = None
        _setOpt(k, v, conv)
Exemple #20
0
def _startUp():
    '''This function allows easy resetting to the global defaults
    If the environment contains 'RL_xxx' then we use the value
    else we use the given default'''
    V = '''T1SearchPath
CMapSearchPath
TTFSearchPath
allowTableBoundsErrors
shapeChecking
defaultEncoding 
defaultGraphicsFontName
pageCompression 
defaultPageSize 
defaultImageCaching 
ZLIB_WARNINGS 
warnOnMissingFontGlyphs 
verbose 
showBoundary 
emptyTableAction
invariant
eps_preview_transparent
eps_preview
eps_ttf_embed
eps_ttf_embed_uid
overlapAttachedSpace
longTableOptimize 
autoConvertEncoding  
_FUZZ
wrapA85
fsEncodings
odbc_driver
platypus_link_underline
canvas_basefontname
allowShortTableRows
imageReaderFlags'''.split()
    import os, sys
    global sys_version, _unset_
    sys_version = sys.version.split()[0]  #strip off the other garbage
    from reportlab.lib import pagesizes
    from reportlab.lib.utils import rl_isdir

    if _SAVED == {}:
        _unset_ = getattr(sys, '_rl_config__unset_', None)
        if _unset_ is None:

            class _unset_:
                pass

            sys._rl_config__unset_ = _unset_ = _unset_()
        for k in V:
            _SAVED[k] = globals()[k]

    #places to search for Type 1 Font files
    import reportlab
    D = {
        'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
        'HOME': os.environ.get('HOME', os.getcwd()),
        'disk': os.getcwd().split(':')[0],
        'sys_version': sys_version,
    }

    for name in ('T1SearchPath', 'TTFSearchPath', 'CMapSearchPath'):
        P = []
        for p in _SAVED[name]:
            d = (p % D).replace('/', os.sep)
            if rl_isdir(d): P.append(d)
        _setOpt(name, P)

    for k in V[3:]:
        v = _SAVED[k]
        if isinstance(v, (int, float)): conv = type(v)
        elif k == 'defaultPageSize':
            conv = lambda v, M=pagesizes: getattr(M, v)
        else:
            conv = None
        _setOpt(k, v, conv)